Skip to content

Commit 300b8b3

Browse files
CoveMBericglauCopilot
authored
Plat 6358 add stellar ai assistant (#516)
Co-authored-by: Eric Lau <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 2944829 commit 300b8b3

File tree

6 files changed

+79
-2
lines changed

6 files changed

+79
-2
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 { StellarCommonContractOptions } from '../types/languages.ts';
3+
4+
export const stellarCommonFunctionDescription = {
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.',
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<StellarCommonContractOptions>['properties'];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { AiFunctionDefinition } from '../types/function-definition.ts';
2+
import { addFunctionPropertiesFrom } from './shared.ts';
3+
import { stellarCommonFunctionDescription } from './stellar-shared.ts';
4+
5+
export const stellarFungibleAIFunctionDefinition = {
6+
name: 'Fungible',
7+
description: 'Fungible Token Standard, compatible with SEP-41, similar to ERC-20',
8+
parameters: {
9+
type: 'object',
10+
properties: {
11+
...addFunctionPropertiesFrom(stellarCommonFunctionDescription, [
12+
'name',
13+
'symbol',
14+
'burnable',
15+
'pausable',
16+
'mintable',
17+
'access',
18+
'info',
19+
]),
20+
premint: {
21+
type: 'string',
22+
description: 'The number of tokens to premint for the deployer.',
23+
},
24+
},
25+
required: ['name', 'symbol'],
26+
additionalProperties: false,
27+
},
28+
} as const satisfies AiFunctionDefinition<'stellar', 'Fungible'>;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export type { RoyaltyInfoOptions as CairoRoyaltyInfoOptions } from '../../../../
99
import type { KindedOptions as CairoAlphaKindedOptions } from '../../../../core/cairo_alpha/dist';
1010
export type { CommonContractOptions as CairoAlphaCommonContractOptions } from '../../../../core/cairo_alpha/dist/common-options';
1111
export type { RoyaltyInfoOptions as CairoAlphaRoyaltyInfoOptions } from '../../../../core/cairo_alpha/dist/set-royalty-info';
12+
//Stellar
13+
import type { KindedOptions as StellarKindedOptions } from '../../../../core/stellar/dist';
14+
import type { CommonContractOptions as StellarCommonContractOptionsBase } from '../../../../core/stellar/dist/common-options';
15+
export type StellarCommonContractOptions = Omit<StellarCommonContractOptionsBase, 'access'> & { access?: false };
1216

1317
// Add supported language here
1418
export type LanguagesContractsOptions = {
@@ -18,11 +22,15 @@ export type LanguagesContractsOptions = {
1822
};
1923
cairo: CairoKindedOptions;
2024
cairoAlpha: CairoAlphaKindedOptions;
25+
stellar: Omit<StellarKindedOptions, 'Fungible'> & {
26+
Fungible: StellarKindedOptions['Fungible'] & StellarCommonContractOptions;
27+
};
2128
};
2229

2330
export type AllLanguagesContractsOptions = LanguagesContractsOptions['solidity'] &
2431
LanguagesContractsOptions['cairo'] &
25-
LanguagesContractsOptions['cairoAlpha'];
32+
LanguagesContractsOptions['cairoAlpha'] &
33+
LanguagesContractsOptions['stellar'];
2634
//
2735

2836
export type SupportedLanguage = keyof LanguagesContractsOptions;

packages/ui/api/ai.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { OpenAIStream } from 'ai';
22
import * as solidityFunctions from './ai-assistant/function-definitions/solidity.ts';
33
import * as cairoFunctions from './ai-assistant/function-definitions/cairo.ts';
44
import * as cairoAlphaFunctions from './ai-assistant/function-definitions/cairo-alpha.ts';
5+
import * as stellarFunctions from './ai-assistant/function-definitions/stellar.ts';
56
import { saveChatInRedisIfDoesNotExist } from './services/redis.ts';
67
import { getOpenAiInstance } from './services/open-ai.ts';
78
import { getEnvironmentVariableOr } from './utils/env.ts';
@@ -19,6 +20,7 @@ const getFunctionsContext = <TLanguage extends SupportedLanguage = SupportedLang
1920
solidity: solidityFunctions,
2021
cairo: cairoFunctions,
2122
cairoAlpha: cairoAlphaFunctions,
23+
stellar: stellarFunctions,
2224
};
2325

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

packages/ui/src/stellar/App.svelte

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import { saveAs } from 'file-saver';
2626
import { injectHyperlinks } from './inject-hyperlinks';
2727
import type { InitialOptions } from '../common/initial-options';
28+
import { createWiz, mergeAiAssistanceOptions } from '../common/Wiz.svelte';
29+
import type { AiFunctionCall } from '../../api/ai-assistant/types/assistant';
30+
31+
const WizStellar = createWiz<'stellar'>();
2832
2933
const dispatch = createEventDispatcher();
3034
@@ -105,9 +109,22 @@
105109
await postConfig(opts, 'download-file', language);
106110
}
107111
};
112+
113+
const applyFunctionCall = ({ detail: aiFunctionCall }: CustomEvent<AiFunctionCall<'stellar'>>) => {
114+
tab = sanitizeKind(aiFunctionCall.name);
115+
allOpts = mergeAiAssistanceOptions(allOpts, aiFunctionCall);
116+
};
108117
</script>
109118

110119
<div class="container flex flex-col gap-4 p-4 rounded-3xl">
120+
<WizStellar
121+
language="stellar"
122+
bind:currentOpts={opts}
123+
bind:currentCode={code}
124+
on:function-call-response={applyFunctionCall}
125+
sampleMessages={['Make a fungible token with supply of 10', 'What does mintable do?']}
126+
></WizStellar>
127+
111128
<div class="header flex flex-row justify-between">
112129
<div class="tab overflow-hidden">
113130
<OverflowMenu>

packages/ui/src/stellar/FungibleControls.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import InfoSection from './InfoSection.svelte';
88
import { error } from '../common/error-tooltip';
99
10-
export const opts: Required<KindedOptions['Fungible']> = {
10+
export let opts: Required<KindedOptions['Fungible']> = {
1111
kind: 'Fungible',
1212
...fungible.defaults,
1313
premint: '', // default to empty premint in UI instead of 0

0 commit comments

Comments
 (0)