Skip to content

Commit 18a4baf

Browse files
CoveMBericglauCopilot
authored
Plat 6359 add stylus ai assistant (#515)
Co-authored-by: Eric Lau <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 300b8b3 commit 18a4baf

File tree

8 files changed

+115
-4
lines changed

8 files changed

+115
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { AiFunctionPropertyDefinition } from '../types/function-definition.ts';
2+
import type { StylusCommonContractOptions } from '../types/languages.ts';
3+
4+
export const stylusCommonFunctionDescription = {
5+
access: {
6+
type: 'boolean',
7+
enum: [false],
8+
description: 'The type of access control to provision, currently not supported',
9+
// 'The type of access control to provision. Ownable is a simple mechanism with a single account authorized for all privileged actions. Roles is a flexible mechanism with a separate role for each privileged action. A role can have many authorized accounts.',
10+
},
11+
12+
info: {
13+
type: 'object',
14+
description: 'Metadata about the contract and author',
15+
properties: {
16+
license: {
17+
type: 'string',
18+
description: 'The license used by the contract, default is "MIT"',
19+
},
20+
},
21+
},
22+
} as const satisfies AiFunctionPropertyDefinition<StylusCommonContractOptions>['properties'];
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import type { AiFunctionDefinition } from '../types/function-definition.ts';
2+
import { addFunctionPropertiesFrom } from './shared.ts';
3+
import { stylusCommonFunctionDescription } from './stylus-shared.ts';
4+
5+
export const stylusERC20AIFunctionDefinition = {
6+
name: 'ERC20',
7+
description: 'Make a fungible token per the ERC-20 standard',
8+
parameters: {
9+
type: 'object',
10+
properties: {
11+
...addFunctionPropertiesFrom(stylusCommonFunctionDescription, ['name', 'burnable', 'access', 'info']),
12+
permit: {
13+
type: 'boolean',
14+
description:
15+
'Whether without paying gas, token holders will be able to allow third parties to transfer from their account.',
16+
},
17+
flashmint: {
18+
type: 'boolean',
19+
description:
20+
"Whether to include built-in flash loans to allow lending tokens without requiring collateral as long as they're returned in the same transaction.",
21+
},
22+
},
23+
required: ['name'],
24+
additionalProperties: false,
25+
},
26+
} as const satisfies AiFunctionDefinition<'stylus', 'ERC20'>;
27+
28+
export const stylusERC721AIFunctionDefinition = {
29+
name: 'ERC721',
30+
description: 'Make a non-fungible token per the ERC-721 standard',
31+
parameters: {
32+
type: 'object',
33+
properties: {
34+
...addFunctionPropertiesFrom(stylusCommonFunctionDescription, ['name', 'burnable', 'access', 'info']),
35+
enumerable: {
36+
type: 'boolean',
37+
description:
38+
'Whether to allow on-chain enumeration of all tokens or those owned by an account. Increases gas cost of transfers.',
39+
},
40+
},
41+
required: ['name'],
42+
additionalProperties: false,
43+
},
44+
} as const satisfies AiFunctionDefinition<'stylus', 'ERC721'>;
45+
46+
export const stylusERC1155AIFunctionDefinition = {
47+
name: 'ERC1155',
48+
description: 'Make a non-fungible token per the ERC-1155 standard',
49+
parameters: {
50+
type: 'object',
51+
properties: {
52+
...addFunctionPropertiesFrom(stylusCommonFunctionDescription, ['name', 'burnable', 'access', 'info']),
53+
supply: {
54+
type: 'boolean',
55+
description: 'Whether to keep track of total supply of tokens',
56+
},
57+
},
58+
required: ['name'],
59+
additionalProperties: false,
60+
},
61+
} as const satisfies AiFunctionDefinition<'stylus', 'ERC1155'>;

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export type { RoyaltyInfoOptions as CairoAlphaRoyaltyInfoOptions } from '../../.
1313
import type { KindedOptions as StellarKindedOptions } from '../../../../core/stellar/dist';
1414
import type { CommonContractOptions as StellarCommonContractOptionsBase } from '../../../../core/stellar/dist/common-options';
1515
export type StellarCommonContractOptions = Omit<StellarCommonContractOptionsBase, 'access'> & { access?: false };
16+
// Stylus
17+
import type { KindedOptions as StylusKindedOptions } from '../../../../core/stylus/dist';
18+
import type { CommonContractOptions as StylusCommonContractOptionsBase } from '../../../../core/stylus/dist/common-options';
19+
export type StylusCommonContractOptions = Omit<StylusCommonContractOptionsBase, 'access'> & { access?: false };
1620

1721
// Add supported language here
1822
export type LanguagesContractsOptions = {
@@ -25,12 +29,18 @@ export type LanguagesContractsOptions = {
2529
stellar: Omit<StellarKindedOptions, 'Fungible'> & {
2630
Fungible: StellarKindedOptions['Fungible'] & StellarCommonContractOptions;
2731
};
32+
stylus: Omit<StylusKindedOptions, 'ERC20' | 'ERC721' | 'ERC1155'> & {
33+
ERC20: StylusKindedOptions['ERC20'] & StylusCommonContractOptions;
34+
ERC721: StylusKindedOptions['ERC721'] & StylusCommonContractOptions;
35+
ERC1155: StylusKindedOptions['ERC1155'] & StylusCommonContractOptions;
36+
};
2837
};
2938

3039
export type AllLanguagesContractsOptions = LanguagesContractsOptions['solidity'] &
3140
LanguagesContractsOptions['cairo'] &
3241
LanguagesContractsOptions['cairoAlpha'] &
33-
LanguagesContractsOptions['stellar'];
42+
LanguagesContractsOptions['stellar'] &
43+
LanguagesContractsOptions['stylus'];
3444
//
3545

3646
export type SupportedLanguage = keyof LanguagesContractsOptions;

packages/ui/api/ai.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as solidityFunctions from './ai-assistant/function-definitions/solidity
33
import * as cairoFunctions from './ai-assistant/function-definitions/cairo.ts';
44
import * as cairoAlphaFunctions from './ai-assistant/function-definitions/cairo-alpha.ts';
55
import * as stellarFunctions from './ai-assistant/function-definitions/stellar.ts';
6+
import * as stylusFunctions from './ai-assistant/function-definitions/stylus.ts';
67
import { saveChatInRedisIfDoesNotExist } from './services/redis.ts';
78
import { getOpenAiInstance } from './services/open-ai.ts';
89
import { getEnvironmentVariableOr } from './utils/env.ts';
@@ -21,6 +22,7 @@ const getFunctionsContext = <TLanguage extends SupportedLanguage = SupportedLang
2122
cairo: cairoFunctions,
2223
cairoAlpha: cairoAlphaFunctions,
2324
stellar: stellarFunctions,
25+
stylus: stylusFunctions,
2426
};
2527

2628
return Object.values(functionPerLanguages[language] ?? {});

packages/ui/src/stylus/App.svelte

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
import { saveAs } from 'file-saver';
2828
import { injectHyperlinks } from './inject-hyperlinks';
2929
import type { InitialOptions } from '../common/initial-options';
30+
import { createWiz, mergeAiAssistanceOptions } from '../common/Wiz.svelte';
31+
import type { AiFunctionCall } from '../../api/ai-assistant/types/assistant';
3032
3133
const dispatch = createEventDispatcher();
3234
35+
const WizStylus = createWiz<'stylus'>();
36+
3337
let showCode = true;
3438
async function allowRendering() {
3539
showCode = false;
@@ -113,9 +117,21 @@
113117
await postConfig(opts, 'download-file', language);
114118
}
115119
};
120+
121+
const applyFunctionCall = ({ detail: aiFunctionCall }: CustomEvent<AiFunctionCall<'stylus'>>) => {
122+
tab = sanitizeKind(aiFunctionCall.name);
123+
allOpts = mergeAiAssistanceOptions(allOpts, aiFunctionCall);
124+
};
116125
</script>
117126

118127
<div class="container flex flex-col gap-4 p-4 rounded-3xl">
128+
<WizStylus
129+
language="stylus"
130+
bind:currentOpts={opts}
131+
bind:currentCode={code}
132+
on:function-call-response={applyFunctionCall}
133+
sampleMessages={['Make a token with flash loan capability', 'What is a flash loan?']}
134+
/>
119135
<div class="header flex flex-row justify-between">
120136
<div class="tab overflow-hidden">
121137
<OverflowMenu>

packages/ui/src/stylus/ERC1155Controls.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import InfoSection from './InfoSection.svelte';
99
import { error } from '../common/error-tooltip';
1010
11-
export const opts: Required<KindedOptions['ERC1155']> = {
11+
export let opts: Required<KindedOptions['ERC1155']> = {
1212
kind: 'ERC1155',
1313
...erc1155.defaults,
1414
info: { ...infoDefaults }, // create new object since Info is nested

packages/ui/src/stylus/ERC20Controls.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import InfoSection from './InfoSection.svelte';
99
import { error } from '../common/error-tooltip';
1010
11-
export const opts: Required<KindedOptions['ERC20']> = {
11+
export let opts: Required<KindedOptions['ERC20']> = {
1212
kind: 'ERC20',
1313
...erc20.defaults,
1414
info: { ...infoDefaults }, // create new object since Info is nested

packages/ui/src/stylus/ERC721Controls.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import InfoSection from './InfoSection.svelte';
99
import { error } from '../common/error-tooltip';
1010
11-
export const opts: Required<KindedOptions['ERC721']> = {
11+
export let opts: Required<KindedOptions['ERC721']> = {
1212
kind: 'ERC721',
1313
...erc721.defaults,
1414
info: { ...infoDefaults }, // create new object since Info is nested

0 commit comments

Comments
 (0)