From e7e000c0c808bb102c4f7ef4b8771c02663c35d9 Mon Sep 17 00:00:00 2001 From: Joe Vecernik Date: Thu, 26 Nov 2026 15:10:49 +0100 Subject: [PATCH] feat(AX-66): support source-defined Function contracts --- src/endpoints/functions-v2.tools.ts | 17 +++++++---------- src/endpoints/functions-v2.ts | 6 ++++-- test/functions-v2.spec.ts | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/endpoints/functions-v2.tools.ts b/src/endpoints/functions-v2.tools.ts index b1be271..6c57fe8 100644 --- a/src/endpoints/functions-v2.tools.ts +++ b/src/endpoints/functions-v2.tools.ts @@ -30,7 +30,7 @@ const schema: JSONSchema = { type: 'object', properties: {}, additionalProperties: true, - description: 'Bounded JSON Schema Draft 2020-12 contract. Use {} for a permissive contract.', + description: 'Optional compatibility assertion. Omit: the server generates this contract from main\'s types and leading /** description */ comments. If supplied, it must exactly match the generated schema.', }; const endpointIdentity = { appName: { type: 'string', minLength: 1, maxLength: 256 }, @@ -40,11 +40,11 @@ const endpointIdentity = { const content: JSONSchema = { type: 'object', additionalProperties: false, - required: ['source', 'inputSchema'], + required: ['source'], description: - 'TypeScript source and declared contracts, Connections and Endpoints. Source calls declared Endpoints by app/version/name and uses declared connection labels.', + 'TypeScript source with locally declared Input and Output types, Connections and Endpoints. Source calls declared Endpoints by app/version/name and uses declared connection labels.', properties: { - source: { type: 'string', description: 'Complete TypeScript Function source.' }, + source: { type: 'string', description: 'Complete TypeScript Function source. Type main(input: Input): Promise; add leading /** description */ field comments. Schemas are generated; nullable unions preserve null.' }, inputSchema: schema, outputSchema: schema, connections: { @@ -200,8 +200,7 @@ export const tools: MakeTool[] = [ teamId: 7, name: 'Echo', content: { - source: 'export default async function main(input: unknown) { return input; }', - inputSchema: {}, + source: 'interface Input { /** Message to echo. */ message: string } type Output = Input; export default async function main(input: Input): Promise { return input; }', }, }, ], @@ -358,8 +357,7 @@ export const tools: MakeTool[] = [ functionId: 42, expectedLatestVersion: 1, content: { - source: 'export default async function main(input: unknown) { return input; }', - inputSchema: {}, + source: 'interface Input { /** Message to echo. */ message: string } type Output = Input; export default async function main(input: Input): Promise { return input; }', }, }, ], @@ -450,8 +448,7 @@ export const tools: MakeTool[] = [ { teamId: 7, content: { - source: 'export default async function main(input: unknown) { return input; }', - inputSchema: {}, + source: 'interface Input { /** Message to echo. */ message: string } type Output = Input; export default async function main(input: Input): Promise { return input; }', }, data: { value: false }, }, diff --git a/src/endpoints/functions-v2.ts b/src/endpoints/functions-v2.ts index de05c3d..2aedd09 100644 --- a/src/endpoints/functions-v2.ts +++ b/src/endpoints/functions-v2.ts @@ -11,10 +11,12 @@ export type FunctionV2Endpoint = { endpointName: string; connectionKey?: string; }; -/** Source and contracts for an immutable Function version or an inline Run. */ +/** Source-defined contract for a new immutable version or inline Run. */ export type FunctionV2Content = { source: string; - inputSchema: FunctionV2Schema; + /** @deprecated Omit: derived from main's input type and documentation comments. If supplied, must match exactly. */ + inputSchema?: FunctionV2Schema; + /** @deprecated Omit: derived from main's return type and documentation comments. If supplied, must match exactly. */ outputSchema?: FunctionV2Schema; connections?: Record; endpoints?: FunctionV2Endpoint[]; diff --git a/test/functions-v2.spec.ts b/test/functions-v2.spec.ts index bceebc3..ab7593c 100644 --- a/test/functions-v2.spec.ts +++ b/test/functions-v2.spec.ts @@ -77,6 +77,28 @@ describe('Functions v2 HTTP contracts', () => { respond({ function: fn }); expect(await make.functionsV2.get(42)).toEqual({ function: fn }); }); + it('authors source without a second contract and advertises schemas as optional assertions', async () => { + const authored = { + source: 'interface Input { /** Optional note. */ note?: string | null } type Output = Input; export default async function main(input: Input): Promise { return input; }', + }; + respond({ function: fn }, 201); + await make.functionsV2.create(7, { name: 'Source contract', content: authored }); + expect(request().body.content).toEqual(authored); + for (const name of [ + 'functions_v2_create', + 'functions_v2_versions_publish', + 'functions_v2_runs_create_inline', + ]) { + const tool = MakeTools.find(tool => tool.name === name)!; + const contentSchema = tool.inputSchema.properties!.content as { + required: string[]; + properties: Record; + }; + expect(contentSchema.required).toEqual(['source']); + expect(contentSchema.properties.inputSchema?.description).toContain('Omit'); + expect(contentSchema.properties.source?.description).toContain('description'); + } + }); it('creates with team scope and initial content', async () => { respond({ function: fn }, 201, { ETag: '"new"' }); expect(await make.functionsV2.create(7, { name: 'Echo', content })).toEqual({ function: fn, etag: '"new"' });