Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/endpoints/functions-v2.tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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<Output>; add leading /** description */ field comments. Schemas are generated; nullable unions preserve null.' },
inputSchema: schema,
outputSchema: schema,
connections: {
Expand Down Expand Up @@ -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<Output> { return input; }',
},
},
],
Expand Down Expand Up @@ -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<Output> { return input; }',
},
},
],
Expand Down Expand Up @@ -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<Output> { return input; }',
},
data: { value: false },
},
Expand Down
6 changes: 4 additions & 2 deletions src/endpoints/functions-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>;
endpoints?: FunctionV2Endpoint[];
Expand Down
22 changes: 22 additions & 0 deletions test/functions-v2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output> { 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<string, { description: string }>;
};
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"' });
Expand Down