Skip to content

Commit aa08900

Browse files
CoveMBericglauCopilot
authored
Deno ci check (#511)
Co-authored-by: Eric Lau <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a866d3e commit aa08900

File tree

18 files changed

+407
-165
lines changed

18 files changed

+407
-165
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ jobs:
2121
- name: Run linter
2222
run: yarn lint
2323

24+
deno-check:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Set up Deno 1.46.3 (matching Netlify edge function environment)
29+
uses: denoland/setup-deno@v2
30+
with:
31+
deno-version: '1.46.3'
32+
- uses: actions/setup-node@v4
33+
with:
34+
node-version: 18.x
35+
cache: 'yarn'
36+
- name: Install dependencies and build wizard packages
37+
run: yarn install --frozen-lockfile
38+
- name: Deno check API
39+
run: yarn type:check:api
40+
2441
build:
2542
strategy:
2643
matrix:

.vscode/example.settings.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
33
"editor.formatOnSave": true,
4-
"deno.enablePaths": [
5-
"packages/ui/api",
6-
"packages/ui/scripts/development-server.ts"
7-
],
84
"deno.enable": true,
9-
"deno.path": "/opt/homebrew/bin/deno" // Update this to your Deno path
5+
"deno.enablePaths": [
6+
"packages/ui/scripts/deno/"
7+
]
108
}

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ Contributions to OpenZeppelin Contracts Wizard are welcome. Please review the in
1414
The following prerequisites are required to build the project locally:
1515
- [Node.js](https://nodejs.org/)
1616
- [Yarn](https://yarnpkg.com/getting-started/install)
17-
18-
If you want to run the local API server for the AI Assistant, you also need to install [Deno](https://github.com/denoland/deno?tab=readme-ov-file#installation).
17+
- [Deno](https://github.com/denoland/deno?tab=readme-ov-file#installation) to run a local API server for the AI Assistant
18+
- Note that using the shell installation method is recommended (the `upgrade` command, which allows you to install a specific Deno version, is not always available when installing Deno with other installers).
19+
- To install the version of Deno that matches the Netlify deploy environment, run `deno upgrade --version 1.46.3`.
20+
- When adding dependencies for the Deno app add the dependency as a dev dependency using yarn, map the dependency to the Deno equivalent url in import_map.json and import it like a typescript dependency in the app.
1921

2022
### Installing dependencies
2123
From the root directory:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
"lint": "eslint",
77
"format:write": "prettier --write \"**/*\"",
88
"format:check": "prettier --check \"**/*\"",
9+
"type:check:api": "yarn --cwd ./packages/ui type:check:api",
910
"dev:ui": "yarn --cwd ./packages/ui dev",
1011
"dev:api": "yarn --cwd ./packages/ui dev:api",
11-
"dev": "concurrently --kill-others-on-fail --names \"ui,api\" --prefix-colors \"magenta.bold,green.bold\" \"yarn dev:ui\" \"yarn dev:api\"",
12+
"dev": "concurrently --kill-others-on-fail --names \"UI,API\" --prefix-colors \"magenta.bold,green.bold\" \"yarn dev:ui\" \"yarn dev:api\"",
1213
"run:core": "node ./scripts/run-command.mjs"
1314
},
1415
"workspaces": {

packages/ui/api/ai-assistant/function-definitions/solidity.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AiFunctionDefinition } from '../types/function-definition.ts';
22
import { addFunctionPropertiesFrom } from './shared.ts';
33
import { commonFunctionDescription } from './solidity-shared.ts';
44

5-
export const erc20Function = {
5+
export const solidityERC20AIFunctionDefinition = {
66
name: 'ERC20',
77
description: 'Make a fungible token per the ERC-20 standard',
88
parameters: {
@@ -63,7 +63,7 @@ export const erc20Function = {
6363
},
6464
} as const satisfies AiFunctionDefinition<'solidity', 'ERC20'>;
6565

66-
export const erc721Function = {
66+
export const solidityERC721AIFunctionDefinition = {
6767
name: 'ERC721',
6868
description: 'Make a non-fungible token per the ERC-721 standard',
6969
parameters: {
@@ -107,7 +107,7 @@ export const erc721Function = {
107107
},
108108
} as const satisfies AiFunctionDefinition<'solidity', 'ERC721'>;
109109

110-
export const erc1155Function = {
110+
export const solidityERC1155AIFunctionDefinition = {
111111
name: 'ERC1155',
112112
description: 'Make a non-fungible token per the ERC-1155 standard',
113113
parameters: {
@@ -141,14 +141,14 @@ export const erc1155Function = {
141141
},
142142
} as const satisfies AiFunctionDefinition<'solidity', 'ERC1155'>;
143143

144-
export const stablecoinFunction = {
144+
export const solidityStablecoinAIFunctionDefinition = {
145145
name: 'Stablecoin',
146146
description:
147147
'Make a stablecoin token that uses the ERC-20 standard. Emphasize that this is experimental, and some features are not audited and subject to change.',
148148
parameters: {
149149
type: 'object',
150150
properties: {
151-
...erc20Function.parameters.properties,
151+
...solidityERC20AIFunctionDefinition.parameters.properties,
152152
custodian: {
153153
type: 'boolean',
154154
description:
@@ -173,14 +173,14 @@ export const stablecoinFunction = {
173173
},
174174
} as const satisfies AiFunctionDefinition<'solidity', 'Stablecoin'>;
175175

176-
export const realWorldAssetFunction = {
176+
export const solidityRealWorldAssetAIFunctionDefinition = {
177177
name: 'RealWorldAsset',
178178
description:
179179
'Make a real-world asset token that uses the ERC-20 standard. Emphasize that this is experimental, and some features are not audited and subject to change.',
180-
parameters: stablecoinFunction.parameters,
180+
parameters: solidityStablecoinAIFunctionDefinition.parameters,
181181
} as const satisfies AiFunctionDefinition<'solidity', 'RealWorldAsset'>;
182182

183-
export const governorFunction = {
183+
export const solidityGovernorAIFunctionDefinition = {
184184
name: 'Governor',
185185
description: 'Make a contract to implement governance, such as for a DAO',
186186
parameters: {
@@ -253,7 +253,7 @@ export const governorFunction = {
253253
},
254254
} as const satisfies AiFunctionDefinition<'solidity', 'Governor'>;
255255

256-
export const customFunction = {
256+
export const solidityCustomAIFunctionDefinition = {
257257
name: 'Custom',
258258
description: 'Make a custom smart contract',
259259
parameters: {

packages/ui/api/ai-assistant/types/function-definition.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import type {
55
IsPrimitiveUnion,
66
Permutation,
77
} from './helpers.ts';
8-
import type { AllLanguagesContractsOptions, LanguageContractsOptions, SupportedLanguage } from './languages.ts';
8+
import type {
9+
AllLanguagesContractsOptions,
10+
LanguageContractsNames,
11+
LanguageContractsOptions,
12+
SupportedLanguage,
13+
} from './languages.ts';
914

1015
type AiFunctionType<TType> = {
1116
type?: StringifyPrimaryType<TType>;
@@ -67,3 +72,9 @@ export type SimpleAiFunctionDefinition = {
6772
additionalProperties: false;
6873
};
6974
};
75+
76+
export type AllContractsAIFunctionDefinitions = {
77+
[L in SupportedLanguage]: {
78+
[K in LanguageContractsNames<L> as `${L}${K}AIFunctionDefinition`]: { name: K } & SimpleAiFunctionDefinition;
79+
};
80+
};

packages/ui/api/ai-assistant/types/languages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { KindedOptions as SolidityKindedOptions } from '@openzeppelin/wizard';
2-
export type { CommonOptions as SolidityCommonOptions } from '@openzeppelin/wizard/src/common-options.ts';
1+
import type { KindedOptions as SolidityKindedOptions } from '../../../../core/solidity/dist';
2+
export type { CommonOptions as SolidityCommonOptions } from '../../../../core/solidity/dist/common-options';
33

44
// Add supported language here
55
export type LanguagesContractsOptions = {
@@ -18,7 +18,7 @@ export type LanguageContractsOptions<TLanguage extends SupportedLanguage> = Lang
1818

1919
export type AllLanguageContractsNames = AllLanguagesContractsOptions[keyof AllLanguagesContractsOptions]['kind'];
2020

21-
type ExtractKind<T> = T extends { kind: infer K } ? K : never;
21+
type ExtractKind<T> = T extends { kind: infer K } ? (K extends string ? K : never) : never;
2222

2323
export type LanguageContractsNames<TLanguage extends SupportedLanguage> = ExtractKind<
2424
LanguageContractsOptions<TLanguage>[keyof LanguageContractsOptions<TLanguage>]

packages/ui/api/ai.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import { OpenAIStream } from 'https://esm.sh/[email protected]';
1+
import { OpenAIStream } from 'ai';
22
import * as solidityFunctions from './ai-assistant/function-definitions/solidity.ts';
33
import { saveChatInRedisIfDoesNotExist } from './services/redis.ts';
44
import { getOpenAiInstance } from './services/open-ai.ts';
55
import { getEnvironmentVariableOr } from './utils/env.ts';
66
import type { AiChatBodyRequest, Chat } from './ai-assistant/types/assistant.ts';
77
import type { SupportedLanguage } from './ai-assistant/types/languages.ts';
8-
import type { SimpleAiFunctionDefinition } from './ai-assistant/types/function-definition.ts';
8+
import type {
9+
AllContractsAIFunctionDefinitions,
10+
SimpleAiFunctionDefinition,
11+
} from './ai-assistant/types/function-definition.ts';
912

10-
const getFunctionsContext = <TLanguage extends SupportedLanguage = SupportedLanguage>(language: TLanguage) => {
11-
const functionPerLanguages: Record<SupportedLanguage, Record<string, SimpleAiFunctionDefinition>> = {
13+
const getFunctionsContext = <TLanguage extends SupportedLanguage = SupportedLanguage>(
14+
language: TLanguage,
15+
): SimpleAiFunctionDefinition[] => {
16+
const functionPerLanguages: AllContractsAIFunctionDefinitions = {
1217
solidity: solidityFunctions,
1318
};
1419

packages/ui/api/services/dev-mocks/redis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// deno-lint-ignore-file require-await
2-
import type { Redis } from 'https://esm.sh/@upstash/redis@1.25.1';
2+
import type { Redis } from '@upstash/redis';
33

44
export default class RedisMock implements Pick<Redis, 'exists' | 'hset'> {
55
private store: Record<

packages/ui/api/services/open-ai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import OpenAI from 'https://esm.sh/openai@4.11.0';
1+
import OpenAI from 'openai';
22
import { getEnvironmentVariablesOrFail } from '../utils/env.ts';
33

44
export const getOpenAiInstance = () => {

0 commit comments

Comments
 (0)