Skip to content

Commit df78ef1

Browse files
JoshuaWhite1vividviolet
authored andcommitted
Add assets config key support for UI extension points
1 parent de64e8f commit df78ef1

4 files changed

Lines changed: 83 additions & 1 deletion

File tree

packages/app/src/cli/models/extensions/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const NewExtensionPointSchema = zod.object({
7575
chat: zod.string().optional(),
7676
})
7777
.optional(),
78+
assets: zod.string().optional(),
7879
})
7980

8081
export const NewExtensionPointsSchema = zod.array(NewExtensionPointSchema)

packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ describe('ui_extension', async () => {
151151
tools: undefined,
152152
instructions: undefined,
153153
intents: undefined,
154+
assets: undefined,
154155
module: './src/ExtensionPointA.js',
155156
metafields: [{namespace: 'test', key: 'test'}],
156157
default_placement_reference: undefined,
@@ -219,6 +220,7 @@ describe('ui_extension', async () => {
219220
tools: undefined,
220221
instructions: undefined,
221222
intents: undefined,
223+
assets: undefined,
222224
module: './src/ExtensionPointA.js',
223225
metafields: [],
224226
default_placement_reference: 'PLACEMENT_REFERENCE1',
@@ -283,6 +285,7 @@ describe('ui_extension', async () => {
283285
tools: undefined,
284286
instructions: undefined,
285287
intents: undefined,
288+
assets: undefined,
286289
module: './src/ExtensionPointA.js',
287290
metafields: [],
288291
urls: {},
@@ -347,6 +350,7 @@ describe('ui_extension', async () => {
347350
tools: undefined,
348351
instructions: undefined,
349352
intents: undefined,
353+
assets: undefined,
350354
module: './src/ExtensionPointA.js',
351355
metafields: [],
352356
default_placement_reference: undefined,
@@ -414,6 +418,7 @@ describe('ui_extension', async () => {
414418
tools: undefined,
415419
instructions: undefined,
416420
intents: undefined,
421+
assets: undefined,
417422
module: './src/ExtensionPointA.js',
418423
metafields: [],
419424
default_placement_reference: undefined,
@@ -483,6 +488,7 @@ describe('ui_extension', async () => {
483488
tools: undefined,
484489
instructions: undefined,
485490
intents: undefined,
491+
assets: undefined,
486492
module: './src/ExtensionPointA.js',
487493
metafields: [],
488494
default_placement_reference: undefined,
@@ -552,6 +558,7 @@ describe('ui_extension', async () => {
552558
tools: './tools.json',
553559
instructions: undefined,
554560
intents: undefined,
561+
assets: undefined,
555562
metafields: [],
556563
default_placement_reference: undefined,
557564
capabilities: undefined,
@@ -616,6 +623,72 @@ describe('ui_extension', async () => {
616623
tools: undefined,
617624
instructions: './instructions.md',
618625
intents: undefined,
626+
assets: undefined,
627+
metafields: [],
628+
default_placement_reference: undefined,
629+
capabilities: undefined,
630+
preloads: {},
631+
build_manifest: {
632+
assets: {
633+
main: {
634+
filepath: 'test-ui-extension.js',
635+
module: './src/ExtensionPointA.js',
636+
},
637+
},
638+
},
639+
urls: {},
640+
},
641+
])
642+
})
643+
644+
test('targeting object passes through assets when configured', async () => {
645+
const allSpecs = await loadLocalExtensionsSpecifications()
646+
const specification = allSpecs.find((spec) => spec.identifier === 'ui_extension')!
647+
const configuration = {
648+
targeting: [
649+
{
650+
target: 'EXTENSION::POINT::A',
651+
module: './src/ExtensionPointA.js',
652+
assets: './assets',
653+
},
654+
],
655+
api_version: '2023-01' as const,
656+
name: 'UI Extension',
657+
description: 'This is an ordinary test extension',
658+
type: 'ui_extension',
659+
handle: 'test-ui-extension',
660+
capabilities: {
661+
block_progress: false,
662+
network_access: false,
663+
api_access: false,
664+
collect_buyer_consent: {
665+
customer_privacy: true,
666+
sms_marketing: false,
667+
},
668+
iframe: {
669+
sources: [],
670+
},
671+
},
672+
settings: {},
673+
}
674+
675+
// When
676+
const parsed = specification.parseConfigurationObject(configuration)
677+
if (parsed.state !== 'ok') {
678+
throw new Error("Couldn't parse configuration")
679+
}
680+
681+
const got = parsed.data
682+
683+
// Then
684+
expect(got.extension_points).toStrictEqual([
685+
{
686+
target: 'EXTENSION::POINT::A',
687+
module: './src/ExtensionPointA.js',
688+
tools: undefined,
689+
instructions: undefined,
690+
intents: undefined,
691+
assets: './assets',
619692
metafields: [],
620693
default_placement_reference: undefined,
621694
capabilities: undefined,
@@ -779,6 +852,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
779852
tools: './tools.json',
780853
instructions: './instructions.md',
781854
intents: undefined,
855+
assets: undefined,
782856
metafields: [],
783857
default_placement_reference: undefined,
784858
capabilities: undefined,

packages/app/src/cli/models/extensions/specifications/ui_extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const UIExtensionSchema = BaseSchema.extend({
7474
tools: targeting.tools,
7575
instructions: targeting.instructions,
7676
intents: targeting.intents,
77+
assets: targeting.assets,
7778
}
7879
})
7980
return {...config, extension_points: extensionPoints}
@@ -119,6 +120,12 @@ const uiExtensionSpec = createExtensionSpecification({
119120
groupBy: 'target',
120121
key: 'extension_points[].intents[].schema',
121122
},
123+
{
124+
type: 'configKey',
125+
anchor: 'extension_points[]',
126+
groupBy: 'target',
127+
key: 'extension_points[].assets',
128+
},
122129
],
123130
},
124131
},

packages/app/src/cli/services/dev/extension/payload/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface Asset {
3939
lastUpdated: number
4040
}
4141

42-
export interface DevNewExtensionPointSchema extends Omit<NewExtensionPointSchemaType, 'intents'> {
42+
export interface DevNewExtensionPointSchema extends Omit<NewExtensionPointSchemaType, 'intents' | 'assets'> {
4343
assets: {
4444
[name: string]: Asset
4545
}

0 commit comments

Comments
 (0)