From 134f5deb3c5351ee0c7ce5bd86d0ba0c4432848a Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 4 Jan 2025 16:34:33 +1030 Subject: [PATCH] chore: Bump node SDK ts-rest contract (#468) --- sdk-node/src/contract.ts | 474 +++++++++++++++++++-------------------- 1 file changed, 237 insertions(+), 237 deletions(-) diff --git a/sdk-node/src/contract.ts b/sdk-node/src/contract.ts index 95f875c2..d7e7d387 100644 --- a/sdk-node/src/contract.ts +++ b/sdk-node/src/contract.ts @@ -48,7 +48,7 @@ export const VersionedTextsSchema = z.object({ z.object({ version: z.string(), content: z.string(), - }), + }) ), }); @@ -68,16 +68,37 @@ export const integrationSchema = z.object({ }) .optional() .nullable(), + tavily: z + .object({ + apiKey: z.string(), + }) + .optional() + .nullable(), + valtown: z + .object({ + endpoint: z.string().url(), + token: z.string(), + }) + .optional() + .nullable(), + slack: z + .object({ + nangoConnectionId: z.string(), + botUserId: z.string(), + teamId: z.string(), + }) + .optional() + .nullable(), }); -export const genericMessageDataSchema = z +const genericMessageDataSchema = z .object({ message: z.string(), details: z.object({}).passthrough().optional(), }) .strict(); -export const resultDataSchema = z +const resultDataSchema = z .object({ id: z.string(), result: z.object({}).passthrough(), @@ -87,17 +108,13 @@ export const resultDataSchema = z export const learningSchema = z.object({ summary: z .string() - .describe( - "The new information that was learned. Be generic, do not refer to the entities.", - ), + .describe("The new information that was learned. Be generic, do not refer to the entities."), entities: z .array( z.object({ - name: z - .string() - .describe("The name of the entity this learning relates to."), + name: z.string().describe("The name of the entity this learning relates to."), type: z.enum(["tool"]), - }), + }) ) .describe("The entities this learning relates to."), relevance: z.object({ @@ -107,7 +124,7 @@ export const learningSchema = z.object({ }), }); -export const agentDataSchema = z +const agentDataSchema = z .object({ done: z.boolean().optional(), result: anyObject.optional(), @@ -121,18 +138,70 @@ export const agentDataSchema = z toolName: z.string(), reasoning: z.string().optional(), input: z.object({}).passthrough(), - }), + }) ) .optional(), }) .strict(); -export const messageDataSchema = z.union([ - resultDataSchema, - agentDataSchema, - genericMessageDataSchema, +const peripheralMessageDataSchema = z.object({ + id: z.string(), + createdAt: z.date().optional(), + pending: z.boolean().optional(), + displayableContext: z.record(z.string()).optional().nullable(), +}); + +export const unifiedMessageDataSchema = z.discriminatedUnion("type", [ + z + .object({ + type: z.literal("agent"), + data: agentDataSchema, + }) + .merge(peripheralMessageDataSchema), + z + .object({ + type: z.literal("invocation-result"), + data: resultDataSchema, + }) + .merge(peripheralMessageDataSchema), + z + .object({ + type: z.literal("human"), + data: genericMessageDataSchema, + }) + .merge(peripheralMessageDataSchema), + z + .object({ + type: z.literal("template"), + data: genericMessageDataSchema, + }) + .merge(peripheralMessageDataSchema), + z + .object({ + type: z.literal("supervisor"), + data: genericMessageDataSchema, + }) + .merge(peripheralMessageDataSchema), + z + .object({ + type: z.literal("agent-invalid"), + data: genericMessageDataSchema, + }) + .merge(peripheralMessageDataSchema), ]); +export type UnifiedMessage = z.infer; + +export type MessageTypes = + | "agent" + | "human" + | "template" + | "invocation-result" + | "supervisor" + | "agent-invalid"; + +export type UnifiedMessageOfType = Extract; + export const FunctionConfigSchema = z.object({ cache: z .object({ @@ -162,7 +231,7 @@ export const definition = { description: z.string().optional(), schema: z.string().optional(), config: FunctionConfigSchema.optional(), - }), + }) ) .optional(), }), @@ -226,13 +295,11 @@ export const definition = { message: z.string(), }), }, - body: blobSchema - .omit({ id: true, createdAt: true, jobId: true, workflowId: true }) - .and( - z.object({ - data: z.string(), - }), - ), + body: blobSchema.omit({ id: true, createdAt: true, jobId: true, workflowId: true }).and( + z.object({ + data: z.string(), + }) + ), }, getContract: { method: "GET", @@ -256,7 +323,7 @@ export const definition = { name: z.string(), createdAt: z.date(), description: z.string().nullable(), - }), + }) ), 401: z.undefined(), }, @@ -271,9 +338,7 @@ export const definition = { 204: z.undefined(), }, body: z.object({ - description: z - .string() - .describe("Human readable description of the cluster"), + description: z.string().describe("Human readable description of the cluster"), }), }, upsertIntegrations: { @@ -332,16 +397,17 @@ export const definition = { name: z.string().optional(), description: z.string().optional(), additionalContext: VersionedTextsSchema.optional().describe( - "Additional cluster context which is included in all runs", + "Additional cluster context which is included in all runs" ), debug: z .boolean() .optional() .describe( - "Enable additional logging (Including prompts and results) for use by Inferable support", + "Enable additional logging (Including prompts and results) for use by Inferable support" ), - enableRunConfigs: z.boolean().optional(), + enableCustomAuth: z.boolean().optional(), enableKnowledgebase: z.boolean().optional(), + handleCustomAuthFunction: z.string().optional(), }), }, getCluster: { @@ -358,7 +424,8 @@ export const definition = { additionalContext: VersionedTextsSchema.nullable(), createdAt: z.date(), debug: z.boolean(), - enableRunConfigs: z.boolean(), + enableCustomAuth: z.boolean(), + handleCustomAuthFunction: z.string(), enableKnowledgebase: z.boolean(), lastPingAt: z.date().nullable(), }), @@ -389,7 +456,7 @@ export const definition = { workflowId: z.string().nullable(), meta: z.any().nullable(), id: z.string(), - }), + }) ), 401: z.undefined(), 404: z.undefined(), @@ -418,13 +485,13 @@ export const definition = { totalInputTokens: z.number(), totalOutputTokens: z.number(), totalModelInvocations: z.number(), - }), + }) ), agentRuns: z.array( z.object({ date: z.string(), totalAgentRuns: z.number(), - }), + }) ), }), }, @@ -462,14 +529,21 @@ export const definition = { authorization: z.string(), }), body: z.object({ - initialPrompt: z + runId: z .string() .optional() - .describe("An initial 'human' message to trigger the run"), - systemPrompt: z + .describe( + "The run ID. If not provided, a new run will be created. If provided, the run will be created with the given" + ) + .refine( + val => !val || /^[0-9A-Z]{26}$/.test(val), + "Run ID must be a valid ULID (26 uppercase alphanumeric characters)" + ), + initialPrompt: z .string() .optional() - .describe("A system prompt for the run."), + .describe("An initial 'human' message to trigger the run"), + systemPrompt: z.string().optional().describe("A system prompt for the run."), name: z .string() .optional() @@ -481,24 +555,20 @@ export const definition = { resultSchema: anyObject .optional() .describe( - "A JSON schema definition which the result object should conform to. By default the result will be a JSON object which does not conform to any schema", + "A JSON schema definition which the result object should conform to. By default the result will be a JSON object which does not conform to any schema" ), attachedFunctions: z .array(functionReference) .optional() .describe( - "An array of functions to make available to the run. By default all functions in the cluster will be available", + "An array of functions to make available to the run. By default all functions in the cluster will be available" ), onStatusChange: z .object({ - function: functionReference.describe( - "A function to call when the run status changes", - ), + function: functionReference.describe("A function to call when the run status changes"), }) .optional() - .describe( - "Mechanism for receiving notifications when the run status changes", - ), + .describe("Mechanism for receiving notifications when the run status changes"), metadata: z .record(z.string()) .optional() @@ -509,71 +579,39 @@ export const definition = { mocks: z .record( z.object({ - output: z - .object({}) - .passthrough() - .describe("The mock output of the function"), - }), + output: z.object({}).passthrough().describe("The mock output of the function"), + }) ) .optional() .describe( - "Function mocks to be used in the run. (Keys should be function in the format _)", + "Function mocks to be used in the run. (Keys should be function in the format _)" ), }) .optional() - .describe( - "When provided, the run will be marked as as a test / evaluation", - ), - configId: z - .string() - .optional() - .describe("The run configuration ID to use"), + .describe("When provided, the run will be marked as as a test / evaluation"), + configId: z.string().optional().describe("DEPRECATED"), + agentId: z.string().optional().describe("The agent ID to use"), input: z .object({}) .passthrough() .describe( - "Structured input arguments to merge with the initial prompt. The schema must match the run configuration input schema if defined", + "Structured input arguments to merge with the initial prompt. The schema must match the agent input schema if defined" ) .optional(), - config: z - .object({ - id: z.string().describe("DEPRECATED"), - input: z - .object({}) - .passthrough() - .describe( - "DEPRECATED", - ) - .optional(), - }) - .describe("DEPRECATED") - .optional(), context: anyObject .optional() .describe("Additional context to propogate to all calls in the run"), - template: z - .object({ - id: z.string().describe("DEPRECATED"), - input: z.object({}).passthrough().optional().describe("DEPRECATED"), - }) - .optional() - .describe("DEPRECATED"), - reasoningTraces: z - .boolean() - .default(true) - .optional() - .describe("Enable reasoning traces"), + reasoningTraces: z.boolean().default(true).optional().describe("Enable reasoning traces"), callSummarization: z .boolean() - .default(true) + .default(false) .optional() .describe("Enable summarization of oversized call results"), interactive: z .boolean() .default(true) - .describe( - "Allow the run to be continued with follow-up messages / message edits", - ), + .describe("Allow the run to be continued with follow-up messages / message edits"), + enableResultGrounding: z.boolean().default(false).describe("Enable result grounding"), }), responses: { 201: z.object({ @@ -634,24 +672,18 @@ export const definition = { headers: z.object({ authorization: z.string(), }), + query: z.object({ + waitTime: z.coerce + .number() + .min(0) + .max(20) + .default(0) + .describe("Time in seconds to keep the request open waiting for a response"), + after: z.string().default("0"), + limit: z.coerce.number().min(10).max(50).default(50), + }), responses: { - 200: z.array( - z.object({ - id: z.string(), - data: messageDataSchema, - type: z.enum([ - "human", - "template", - "invocation-result", - "agent", - "agent-invalid", - "supervisor", - ]), - createdAt: z.date(), - pending: z.boolean().default(false), - displayableContext: z.record(z.string()).nullable(), - }), - ), + 200: z.array(unifiedMessageDataSchema), 401: z.undefined(), }, }, @@ -665,14 +697,11 @@ export const definition = { userId: z.string().optional(), test: z.coerce .string() - .transform((value) => value === "true") + .transform(value => value === "true") .optional(), limit: z.coerce.number().min(10).max(50).default(50), - metadata: z - .string() - .optional() - .describe("Filter runs by a metadata value (value:key)"), - configId: z.string().optional(), + metadata: z.string().optional().describe("Filter runs by a metadata value (value:key)"), + agentId: z.string().optional(), }), responses: { 200: z.array( @@ -681,14 +710,12 @@ export const definition = { name: z.string(), userId: z.string().nullable(), createdAt: z.date(), - status: z - .enum(["pending", "running", "paused", "done", "failed"]) - .nullable(), + status: z.enum(["pending", "running", "paused", "done", "failed"]).nullable(), test: z.boolean(), - configId: z.string().nullable(), - configVersion: z.number().nullable(), + agentId: z.string().nullable(), + agentVersion: z.number().nullable(), feedbackScore: z.number().nullable(), - }), + }) ), 401: z.undefined(), }, @@ -703,13 +730,13 @@ export const definition = { 200: z.object({ id: z.string(), userId: z.string().nullable(), - status: z - .enum(["pending", "running", "paused", "done", "failed"]) - .nullable(), + status: z.enum(["pending", "running", "paused", "done", "failed"]).nullable(), failureReason: z.string().nullable(), test: z.boolean(), feedbackComment: z.string().nullable(), feedbackScore: z.number().nullable(), + context: z.any().nullable(), + authContext: z.any().nullable(), result: anyObject.nullable(), metadata: z.record(z.string()).nullable(), attachedFunctions: z.array(z.string()).nullable(), @@ -725,12 +752,7 @@ export const definition = { }), body: z.object({ comment: z.string().describe("Feedback comment").nullable(), - score: z - .number() - .describe("Score between 0 and 1") - .min(0) - .max(1) - .nullable(), + score: z.number().describe("Score between 0 and 1").min(0).max(1).nullable(), }), responses: { 204: z.undefined(), @@ -756,7 +778,6 @@ export const definition = { body: z.object({ message: z.string() }), responses: { 200: z.object({ - data: genericMessageDataSchema, id: z.string(), }), 404: z.object({ message: z.string() }), @@ -835,7 +856,7 @@ export const definition = { targetFn: z.string(), service: z.string(), executingMachineId: z.string().nullable(), - }), + }) ), }, }, @@ -871,7 +892,7 @@ export const definition = { createdAt: z.date(), createdBy: z.string(), revokedAt: z.date().nullable(), - }), + }) ), }, }, @@ -895,13 +916,16 @@ export const definition = { headers: z.object({ authorization: z.string(), }), + query: z.object({ + limit: z.coerce.number().min(10).max(50).default(50), + }), responses: { 200: z.array( z.object({ id: z.string(), lastPingAt: z.date(), ip: z.string(), - }), + }) ), }, pathParams: z.object({ @@ -927,10 +951,11 @@ export const definition = { description: z.string().optional(), schema: z.string().optional(), config: FunctionConfigSchema.optional(), - }), + }) ) .optional(), - }), + timestamp: z.date(), + }) ), }, pathParams: z.object({ @@ -944,7 +969,6 @@ export const definition = { query: z.object({ messagesAfter: z.string().default("0"), activityAfter: z.string().default("0"), - jobsAfter: z.string().default("0"), }), pathParams: z.object({ clusterId: z.string(), @@ -953,24 +977,7 @@ export const definition = { responses: { 404: z.undefined(), 200: z.object({ - messages: z.array( - z.object({ - id: z.string(), - data: messageDataSchema, - type: z.enum([ - // TODO: Remove 'template' type - "template", - "invocation-result", - "human", - "agent", - "agent-invalid", - "supervisor", - ]), - createdAt: z.date(), - pending: z.boolean().default(false), - displayableContext: z.record(z.string()).nullable(), - }), - ), + messages: z.array(unifiedMessageDataSchema), activity: z.array( z.object({ id: z.string(), @@ -980,7 +987,7 @@ export const definition = { createdAt: z.date(), jobId: z.string().nullable(), targetFn: z.string().nullable(), - }), + }) ), jobs: z.array( z.object({ @@ -992,16 +999,16 @@ export const definition = { createdAt: z.date(), approved: z.boolean().nullable(), approvalRequested: z.boolean().nullable(), - }), + }) ), run: z.object({ id: z.string(), userId: z.string().nullable(), - status: z - .enum(["pending", "running", "paused", "done", "failed"]) - .nullable(), + status: z.enum(["pending", "running", "paused", "done", "failed"]).nullable(), failureReason: z.string().nullable(), test: z.boolean(), + context: z.any().nullable(), + authContext: z.any().nullable(), feedbackComment: z.string().nullable(), feedbackScore: z.number().nullable(), attachedFunctions: z.array(z.string()).nullable(), @@ -1079,9 +1086,9 @@ export const definition = { 401: z.undefined(), }, }, - getRunConfig: { + getAgent: { method: "GET", - path: "/clusters/:clusterId/run-configs/:configId", + path: "/clusters/:clusterId/agents/:agentId", headers: z.object({ authorization: z.string() }), responses: { 200: z.object({ @@ -1093,7 +1100,6 @@ export const definition = { attachedFunctions: z.array(z.string()), resultSchema: anyObject.nullable(), inputSchema: anyObject.nullable(), - public: z.boolean(), createdAt: z.date(), updatedAt: z.date(), versions: z.array( @@ -1105,8 +1111,7 @@ export const definition = { attachedFunctions: z.array(z.string()), resultSchema: anyObject.nullable(), inputSchema: anyObject.nullable(), - public: z.boolean(), - }), + }) ), }), 401: z.undefined(), @@ -1114,27 +1119,23 @@ export const definition = { }, pathParams: z.object({ clusterId: z.string(), - configId: z.string(), + agentId: z.string(), }), query: z.object({ withPreviousVersions: z.enum(["true", "false"]).default("false"), }), }, - createRunConfig: { + createAgent: { method: "POST", - path: "/clusters/:clusterId/run-configs", + path: "/clusters/:clusterId/agents", headers: z.object({ authorization: z.string() }), body: z.object({ name: z.string(), initialPrompt: z.string().optional(), - systemPrompt: z - .string() - .optional() - .describe("The initial system prompt for the run."), + systemPrompt: z.string().optional().describe("The initial system prompt for the run."), attachedFunctions: z.array(z.string()).optional(), resultSchema: anyObject.optional(), inputSchema: z.object({}).passthrough().optional().nullable(), - public: z.boolean(), }), responses: { 201: z.object({ id: z.string() }), @@ -1144,25 +1145,21 @@ export const definition = { clusterId: z.string(), }), }, - upsertRunConfig: { + upsertAgent: { method: "PUT", - path: "/clusters/:clusterId/run-configs/:configId", + path: "/clusters/:clusterId/agents/:agentId", headers: z.object({ authorization: z.string() }), pathParams: z.object({ clusterId: z.string(), - configId: z.string().regex(userDefinedIdRegex), + agentId: z.string().regex(userDefinedIdRegex), }), body: z.object({ name: z.string().optional(), initialPrompt: z.string().optional(), - systemPrompt: z - .string() - .optional() - .describe("The initial system prompt for the run."), + systemPrompt: z.string().optional().describe("The initial system prompt for the run."), attachedFunctions: z.array(z.string()).optional(), resultSchema: z.object({}).passthrough().optional().nullable(), inputSchema: z.object({}).passthrough().optional().nullable(), - public: z.boolean(), }), responses: { 200: z.object({ @@ -1180,9 +1177,9 @@ export const definition = { 404: z.object({ message: z.string() }), }, }, - deleteRunConfig: { + deleteAgent: { method: "DELETE", - path: "/clusters/:clusterId/run-configs/:configId", + path: "/clusters/:clusterId/agent/:agentId", headers: z.object({ authorization: z.string() }), responses: { 204: z.undefined(), @@ -1192,12 +1189,12 @@ export const definition = { body: z.undefined(), pathParams: z.object({ clusterId: z.string(), - configId: z.string(), + agentId: z.string(), }), }, - listRunConfigs: { + listAgents: { method: "GET", - path: "/clusters/:clusterId/run-configs", + path: "/clusters/:clusterId/agents", headers: z.object({ authorization: z.string() }), responses: { 200: z.array( @@ -1211,34 +1208,7 @@ export const definition = { resultSchema: z.unknown().nullable(), createdAt: z.date(), updatedAt: z.date(), - }), - ), - 401: z.undefined(), - }, - pathParams: z.object({ - clusterId: z.string(), - }), - }, - searchRunConfigs: { - method: "GET", - path: "/clusters/:clusterId/run-configs/search", - headers: z.object({ authorization: z.string() }), - query: z.object({ - search: z.string(), - }), - responses: { - 200: z.array( - z.object({ - id: z.string(), - clusterId: z.string(), - name: z.string(), - initialPrompt: z.string(), - attachedFunctions: z.array(z.string()), - resultSchema: z.unknown().nullable(), - createdAt: z.date(), - updatedAt: z.date(), - similarity: z.number(), - }), + }) ), 401: z.undefined(), }, @@ -1246,9 +1216,9 @@ export const definition = { clusterId: z.string(), }), }, - getRunConfigMetrics: { + getAgentMetrics: { method: "GET", - path: "/clusters/:clusterId/run-configs/:configId/metrics", + path: "/clusters/:clusterId/agents/:agentId/metrics", headers: z.object({ authorization: z.string() }), responses: { 200: z.array( @@ -1258,12 +1228,12 @@ export const definition = { jobFailureCount: z.number(), timeToCompletion: z.number(), jobCount: z.number(), - }), + }) ), }, pathParams: z.object({ clusterId: z.string(), - configId: z.string(), + agentId: z.string(), }), }, createClusterKnowledgeArtifact: { @@ -1275,11 +1245,9 @@ export const definition = { z.object({ id: z.string(), data: z.string(), - tags: z - .array(z.string()) - .transform((tags) => tags.map((tag) => tag.toLowerCase().trim())), + tags: z.array(z.string()).transform(tags => tags.map(tag => tag.toLowerCase().trim())), title: z.string(), - }), + }) ), }), responses: { @@ -1307,7 +1275,7 @@ export const definition = { tags: z.array(z.string()), title: z.string(), similarity: z.number(), - }), + }) ), 401: z.undefined(), }, @@ -1321,9 +1289,7 @@ export const definition = { headers: z.object({ authorization: z.string() }), body: z.object({ data: z.string(), - tags: z - .array(z.string()) - .transform((tags) => tags.map((tag) => tag.toLowerCase().trim())), + tags: z.array(z.string()).transform(tags => tags.map(tag => tag.toLowerCase().trim())), title: z.string(), }), responses: { @@ -1358,7 +1324,7 @@ export const definition = { data: z.string(), tags: z.array(z.string()), title: z.string(), - }), + }) ), 401: z.undefined(), }, @@ -1387,9 +1353,7 @@ export const definition = { .min(0) .max(20) .default(0) - .describe( - "Time in seconds to keep the request open waiting for a response", - ), + .describe("Time in seconds to keep the request open waiting for a response"), }), headers: z.object({ authorization: z.string(), @@ -1437,14 +1401,9 @@ export const definition = { path: "/clusters/:clusterId/calls", query: z.object({ service: z.string(), - status: z - .enum(["pending", "running", "paused", "done", "failed"]) - .default("pending"), + status: z.enum(["pending", "running", "paused", "done", "failed"]).default("pending"), limit: z.coerce.number().min(1).max(20).default(10), - acknowledge: z.coerce - .boolean() - .default(false) - .describe("Should calls be marked as running"), + acknowledge: z.coerce.boolean().default(false).describe("Should calls be marked as running"), }), pathParams: z.object({ clusterId: z.string(), @@ -1466,7 +1425,7 @@ export const definition = { authContext: z.any().nullable(), runContext: z.any().nullable(), approved: z.boolean(), - }), + }) ), }, }, @@ -1498,7 +1457,7 @@ export const definition = { resultSchema: anyObject .optional() .describe( - "A JSON schema definition which the result object should conform to. By default the result will be a JSON object which does not conform to any schema", + "A JSON schema definition which the result object should conform to. By default the result will be a JSON object which does not conform to any schema" ), modelId: z.enum(["claude-3-5-sonnet", "claude-3-haiku"]), temperature: z @@ -1515,6 +1474,47 @@ export const definition = { clusterId: z.string(), }), }, + getServerStats: { + method: "GET", + path: "/stats", + responses: { + 200: z.object({ + functionCalls: z.object({ + count: z.number(), + }), + tokenUsage: z.object({ + input: z.number(), + output: z.number(), + }), + refreshedAt: z.number(), + }), + }, + }, + createNangoSession: { + method: "POST", + path: "/clusters/:clusterId/nango/sessions", + pathParams: z.object({ + clusterId: z.string(), + }), + headers: z.object({ authorization: z.string() }), + body: z.object({ + integration: z.string(), + }), + responses: { + 200: z.object({ + token: z.string(), + }), + }, + }, + createNangoEvent: { + method: "POST", + path: "/nango/events", + headers: z.object({ "x-nango-signature": z.string() }), + body: z.object({}).passthrough(), + responses: { + 200: z.undefined(), + }, + }, } as const; export const contract = c.router(definition);