@m6d/cortex 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/drizzle.d.ts +461 -5
- package/dist/drizzle.js +172 -44
- package/dist/{index-z0594rs3.js → index-jw8cnjqv.js} +159 -124
- package/dist/index.d.ts +1592 -240
- package/dist/index.js +352 -179
- package/package.json +2 -14
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BACKEND_ERROR_STATUS,
|
|
3
3
|
CortexError,
|
|
4
|
+
DATASET_REQUEST_MAX_BYTES,
|
|
4
5
|
backendErrorSchema,
|
|
5
6
|
boundDatasetResult,
|
|
6
7
|
checkDatasetQuery,
|
|
8
|
+
contentVersion,
|
|
7
9
|
datasetCatalogOf,
|
|
8
10
|
datasetDefinitionSchema,
|
|
9
11
|
datasetIdentifierSchema,
|
|
@@ -11,13 +13,14 @@ import {
|
|
|
11
13
|
envelopeOf,
|
|
12
14
|
errorEnvelope,
|
|
13
15
|
isRecord,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
malformedBody,
|
|
17
|
+
protocolBodyLimit,
|
|
18
|
+
readJsonPointer
|
|
19
|
+
} from "./index-jw8cnjqv.js";
|
|
16
20
|
|
|
17
|
-
// src/server.ts
|
|
21
|
+
// src/server/server.ts
|
|
18
22
|
import { createHash, timingSafeEqual } from "node:crypto";
|
|
19
23
|
import { Hono } from "hono";
|
|
20
|
-
import { bodyLimit } from "hono/body-limit";
|
|
21
24
|
import { z as z3 } from "zod";
|
|
22
25
|
|
|
23
26
|
// ../../node_modules/.bun/re2js@2.8.8/node_modules/re2js/build/index.js
|
|
@@ -6953,6 +6956,34 @@ var REQUEST_LOCATION_TOOL = "requestLocation";
|
|
|
6953
6956
|
|
|
6954
6957
|
// ../../internal/contracts/src/triggers/index.ts
|
|
6955
6958
|
import { z } from "zod";
|
|
6959
|
+
|
|
6960
|
+
// ../../internal/contracts/src/wire/index.ts
|
|
6961
|
+
var LOCALES = ["en", "ar"];
|
|
6962
|
+
var BASE_LOCALE = LOCALES[0];
|
|
6963
|
+
function byLocale(valueOf) {
|
|
6964
|
+
const entries = LOCALES.map((locale) => [locale, valueOf(locale)]);
|
|
6965
|
+
return Object.fromEntries(entries);
|
|
6966
|
+
}
|
|
6967
|
+
var TOOL_SURFACES = ["inline", "modal"];
|
|
6968
|
+
var MEDIA_FORMS = ["mermaid", "vega-lite", "map", "report"];
|
|
6969
|
+
var DEFAULT_MEDIA_FORMS = [
|
|
6970
|
+
"mermaid",
|
|
6971
|
+
"vega-lite",
|
|
6972
|
+
"map"
|
|
6973
|
+
];
|
|
6974
|
+
var ATTACHMENT_MAX_BYTES = 10 * 1024 * 1024;
|
|
6975
|
+
var APPROVAL_TITLE_FIELD = "approvalTitle";
|
|
6976
|
+
var TRIGGER_DROP_REASONS = ["busy", "approval_pending", "budget", "rate_limited"];
|
|
6977
|
+
var TRIGGER_REASONS = [
|
|
6978
|
+
...TRIGGER_DROP_REASONS,
|
|
6979
|
+
"invalid_payload",
|
|
6980
|
+
"missing_thread_key",
|
|
6981
|
+
"no_turn",
|
|
6982
|
+
"no_output",
|
|
6983
|
+
"invalid_output"
|
|
6984
|
+
];
|
|
6985
|
+
|
|
6986
|
+
// ../../internal/contracts/src/triggers/index.ts
|
|
6956
6987
|
var MESSAGE_TRIGGER_NAME = "message";
|
|
6957
6988
|
var TRIGGER_ANSWER_TOOL_NAME = "submitAnswer";
|
|
6958
6989
|
var TRIGGER_OUTCOMES = [
|
|
@@ -6963,7 +6994,12 @@ var TRIGGER_OUTCOMES = [
|
|
|
6963
6994
|
"rejected",
|
|
6964
6995
|
"dropped"
|
|
6965
6996
|
];
|
|
6966
|
-
|
|
6997
|
+
function agentRoute(agentSlug) {
|
|
6998
|
+
return `/agents/${encodeURIComponent(agentSlug)}`;
|
|
6999
|
+
}
|
|
7000
|
+
function triggerRoute(agentSlug, name) {
|
|
7001
|
+
return `${agentRoute(agentSlug)}/triggers/${encodeURIComponent(name)}`;
|
|
7002
|
+
}
|
|
6967
7003
|
var pendingApprovalSchema = z.object({
|
|
6968
7004
|
toolCallId: z.string(),
|
|
6969
7005
|
toolName: z.string(),
|
|
@@ -6995,7 +7031,7 @@ var triggerFiringResponseSchema = z.discriminatedUnion("outcome", [
|
|
|
6995
7031
|
outcome: z.literal("failed"),
|
|
6996
7032
|
threadId: z.uuid(),
|
|
6997
7033
|
runId: z.string(),
|
|
6998
|
-
reason: z.
|
|
7034
|
+
reason: z.enum(TRIGGER_REASONS).nullable()
|
|
6999
7035
|
}),
|
|
7000
7036
|
z.object({
|
|
7001
7037
|
firingId: z.uuid(),
|
|
@@ -7019,38 +7055,35 @@ var triggerFiringRecordSchema = z.object({
|
|
|
7019
7055
|
threadId: z.uuid().nullable(),
|
|
7020
7056
|
runId: z.string().nullable(),
|
|
7021
7057
|
outcome: z.enum(TRIGGER_OUTCOMES),
|
|
7022
|
-
reason: z.
|
|
7058
|
+
reason: z.enum(TRIGGER_REASONS).nullable(),
|
|
7023
7059
|
output: z.unknown(),
|
|
7024
7060
|
approvals: z.array(pendingApprovalSchema),
|
|
7025
7061
|
createdAt: z.iso.datetime(),
|
|
7026
7062
|
finishedAt: z.iso.datetime().nullable()
|
|
7027
7063
|
});
|
|
7028
7064
|
|
|
7029
|
-
// ../../internal/contracts/src/wire/index.ts
|
|
7030
|
-
var LOCALES = ["en", "ar"];
|
|
7031
|
-
var TOOL_SURFACES = ["inline", "modal"];
|
|
7032
|
-
var MEDIA_FORMS = ["mermaid", "vega-lite", "map", "report"];
|
|
7033
|
-
var DEFAULT_MEDIA_FORMS = [
|
|
7034
|
-
"mermaid",
|
|
7035
|
-
"vega-lite",
|
|
7036
|
-
"map"
|
|
7037
|
-
];
|
|
7038
|
-
var ATTACHMENT_MAX_BYTES = 10 * 1024 * 1024;
|
|
7039
|
-
var APPROVAL_TITLE_FIELD = "approvalTitle";
|
|
7040
|
-
|
|
7041
7065
|
// ../../internal/contracts/src/server/index.ts
|
|
7042
7066
|
var END_USER_TOKEN_HEADER = "X-End-User-Token";
|
|
7043
7067
|
var AGENT_SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
7044
7068
|
var agentSlugSchema = z2.string().regex(AGENT_SLUG_PATTERN);
|
|
7045
|
-
var
|
|
7069
|
+
var USER_ID_MAX_LENGTH = 255;
|
|
7070
|
+
var userIdSchema = z2.string().max(USER_ID_MAX_LENGTH);
|
|
7046
7071
|
var IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
7072
|
+
var IDENTIFIER_MAX_LENGTH = 64;
|
|
7073
|
+
var identifierSchema = z2.string().regex(IDENTIFIER_PATTERN).max(IDENTIFIER_MAX_LENGTH);
|
|
7047
7074
|
var localeSchema = z2.enum(LOCALES);
|
|
7075
|
+
var SERVER_MANIFEST_LIMITS = {
|
|
7076
|
+
variables: 100,
|
|
7077
|
+
tools: 500,
|
|
7078
|
+
description: 500,
|
|
7079
|
+
example: 200
|
|
7080
|
+
};
|
|
7048
7081
|
var variableValueSchema = z2.union([z2.string(), z2.number(), z2.boolean()]);
|
|
7049
7082
|
var variableValuesSchema = z2.record(z2.string(), variableValueSchema);
|
|
7050
7083
|
var variableDeclarationSchema = z2.object({
|
|
7051
|
-
name:
|
|
7052
|
-
description: z2.string().max(
|
|
7053
|
-
example: z2.string().max(
|
|
7084
|
+
name: identifierSchema,
|
|
7085
|
+
description: z2.string().max(SERVER_MANIFEST_LIMITS.description),
|
|
7086
|
+
example: z2.string().max(SERVER_MANIFEST_LIMITS.example),
|
|
7054
7087
|
type: z2.enum(["string", "number", "boolean"]),
|
|
7055
7088
|
computed: z2.boolean()
|
|
7056
7089
|
});
|
|
@@ -7085,28 +7118,25 @@ var BUILT_IN_TOOL_NAMES = [
|
|
|
7085
7118
|
"queryDataset",
|
|
7086
7119
|
"readAttachment",
|
|
7087
7120
|
"readReport",
|
|
7088
|
-
"
|
|
7089
|
-
"searchServices",
|
|
7121
|
+
"searchRegistries",
|
|
7090
7122
|
"searchThreadHistory",
|
|
7091
|
-
"searchTools",
|
|
7092
7123
|
REQUEST_LOCATION_TOOL,
|
|
7093
7124
|
TRIGGER_ANSWER_TOOL_NAME
|
|
7094
7125
|
];
|
|
7095
7126
|
function isBuiltInToolName(name) {
|
|
7096
7127
|
return BUILT_IN_TOOL_NAMES.some((builtIn) => builtIn === name);
|
|
7097
7128
|
}
|
|
7098
|
-
var
|
|
7099
|
-
var declaredToolNameSchema = z2.string().regex(IDENTIFIER_PATTERN).max(TOOL_NAME_MAX_LENGTH).refine((name) => !isBuiltInToolName(name), "the name of a built-in tool");
|
|
7129
|
+
var declaredToolNameSchema = identifierSchema.refine((name) => !isBuiltInToolName(name), "the name of a built-in tool");
|
|
7100
7130
|
var jsonSchemaSchema = z2.record(z2.string(), z2.unknown());
|
|
7101
7131
|
var serverVariableSchema = z2.object({
|
|
7102
|
-
name:
|
|
7103
|
-
description: z2.string().max(
|
|
7104
|
-
example: z2.string().max(
|
|
7132
|
+
name: identifierSchema.refine((name) => !BUILT_IN_VARIABLES.some((builtIn) => builtIn.name === name), "the name of a built-in variable"),
|
|
7133
|
+
description: z2.string().max(SERVER_MANIFEST_LIMITS.description),
|
|
7134
|
+
example: z2.string().max(SERVER_MANIFEST_LIMITS.example),
|
|
7105
7135
|
type: variableDeclarationSchema.shape.type
|
|
7106
7136
|
});
|
|
7107
7137
|
var serverToolSchema = z2.object({
|
|
7108
7138
|
name: declaredToolNameSchema,
|
|
7109
|
-
description: z2.string().trim().min(1).max(
|
|
7139
|
+
description: z2.string().trim().min(1).max(SERVER_MANIFEST_LIMITS.description),
|
|
7110
7140
|
inputSchema: jsonSchemaSchema.refine((schema) => schema.type === "object", "a tool's input is an object"),
|
|
7111
7141
|
outputSchema: jsonSchemaSchema.optional(),
|
|
7112
7142
|
readOnly: z2.boolean(),
|
|
@@ -7126,22 +7156,8 @@ var approvalRequestedEventSchema = z2.object({
|
|
|
7126
7156
|
approvals: z2.array(pendingApprovalSchema.partial({ input: true })),
|
|
7127
7157
|
occurredAt: z2.iso.datetime()
|
|
7128
7158
|
});
|
|
7129
|
-
function pointerKey(token) {
|
|
7130
|
-
try {
|
|
7131
|
-
return unescapePointerToken(decodeURIComponent(token));
|
|
7132
|
-
} catch {
|
|
7133
|
-
return;
|
|
7134
|
-
}
|
|
7135
|
-
}
|
|
7136
7159
|
function pointedAt(root, ref) {
|
|
7137
|
-
|
|
7138
|
-
return;
|
|
7139
|
-
let node = root;
|
|
7140
|
-
for (const token of ref.slice(1).split("/").slice(1)) {
|
|
7141
|
-
const key = pointerKey(token);
|
|
7142
|
-
node = key !== undefined && (isRecord(node) || Array.isArray(node)) ? new Map(Object.entries(node)).get(key) : undefined;
|
|
7143
|
-
}
|
|
7144
|
-
return node;
|
|
7160
|
+
return ref.startsWith("#") ? readJsonPointer(root, ref) : undefined;
|
|
7145
7161
|
}
|
|
7146
7162
|
function namesApprovalTitle(node) {
|
|
7147
7163
|
const required = node.required;
|
|
@@ -7176,22 +7192,18 @@ function closed(node) {
|
|
|
7176
7192
|
function blocksApprovalTitle(inputSchema) {
|
|
7177
7193
|
return sameObjectNodes(inputSchema).some((node) => namesApprovalTitle(node) || node !== inputSchema && closed(node));
|
|
7178
7194
|
}
|
|
7179
|
-
function refuseBlockedApprovalTitle(tool, context, path) {
|
|
7195
|
+
function refuseBlockedApprovalTitle(tool, context, path, message = `a tool that needs approval cannot take an input named ${APPROVAL_TITLE_FIELD}, nor one a closed sub-schema describes: Cortex adds the approval card's title to it`) {
|
|
7180
7196
|
if (!tool.requiresApproval || !blocksApprovalTitle(tool.inputSchema))
|
|
7181
7197
|
return;
|
|
7182
|
-
context.addIssue({
|
|
7183
|
-
code: "custom",
|
|
7184
|
-
path: [...path, "inputSchema"],
|
|
7185
|
-
message: `a tool that needs approval cannot take an input named ${APPROVAL_TITLE_FIELD}, nor one a closed sub-schema describes: Cortex adds the approval card's title to it`
|
|
7186
|
-
});
|
|
7198
|
+
context.addIssue({ code: "custom", path: [...path, "inputSchema"], message });
|
|
7187
7199
|
}
|
|
7188
7200
|
function uniqueNames(entries) {
|
|
7189
7201
|
return new Set(entries.map((entry) => entry.name)).size === entries.length;
|
|
7190
7202
|
}
|
|
7191
7203
|
var serverManifestSchema = z2.object({
|
|
7192
7204
|
version: z2.string().min(1).max(128),
|
|
7193
|
-
variables: z2.array(serverVariableSchema).max(
|
|
7194
|
-
tools: z2.array(serverToolSchema).max(
|
|
7205
|
+
variables: z2.array(serverVariableSchema).max(SERVER_MANIFEST_LIMITS.variables).refine(uniqueNames, "variable names repeat"),
|
|
7206
|
+
tools: z2.array(serverToolSchema).max(SERVER_MANIFEST_LIMITS.tools).refine(uniqueNames, "tool names repeat").superRefine((tools, context) => {
|
|
7195
7207
|
tools.forEach((tool, index) => refuseBlockedApprovalTitle(tool, context, [index]));
|
|
7196
7208
|
}),
|
|
7197
7209
|
verify: z2.boolean(),
|
|
@@ -7223,7 +7235,7 @@ var serverEventSchemas = {
|
|
|
7223
7235
|
approval_requested: approvalRequestedEventSchema
|
|
7224
7236
|
};
|
|
7225
7237
|
|
|
7226
|
-
// src/server.ts
|
|
7238
|
+
// src/server/server.ts
|
|
7227
7239
|
function digest(value) {
|
|
7228
7240
|
return createHash("sha256").update(value).digest();
|
|
7229
7241
|
}
|
|
@@ -7232,7 +7244,6 @@ async function bodyOf(request, schema) {
|
|
|
7232
7244
|
return;
|
|
7233
7245
|
})).data;
|
|
7234
7246
|
}
|
|
7235
|
-
var malformed = errorEnvelope("invalid_request", "Malformed request body");
|
|
7236
7247
|
function dropUncheckablePatterns({
|
|
7237
7248
|
zodSchema,
|
|
7238
7249
|
jsonSchema
|
|
@@ -7272,8 +7283,7 @@ function manifestOf(options) {
|
|
|
7272
7283
|
verify: options.verify !== undefined,
|
|
7273
7284
|
events: SERVER_EVENTS.filter((event) => options.events?.[event])
|
|
7274
7285
|
};
|
|
7275
|
-
|
|
7276
|
-
return { version, ...content };
|
|
7286
|
+
return { version: contentVersion(content), ...content };
|
|
7277
7287
|
}
|
|
7278
7288
|
function defineServer(options) {
|
|
7279
7289
|
if (!options.key)
|
|
@@ -7299,17 +7309,14 @@ function defineServer(options) {
|
|
|
7299
7309
|
}
|
|
7300
7310
|
await next();
|
|
7301
7311
|
});
|
|
7302
|
-
app.use(
|
|
7303
|
-
maxSize: SERVER_REQUEST_MAX_BYTES,
|
|
7304
|
-
onError: (c) => c.json(errorEnvelope("invalid_request", "Request body too large"), 413)
|
|
7305
|
-
}));
|
|
7312
|
+
app.use(protocolBodyLimit(SERVER_REQUEST_MAX_BYTES));
|
|
7306
7313
|
app.get("/", function(c) {
|
|
7307
7314
|
return c.json(manifest);
|
|
7308
7315
|
});
|
|
7309
7316
|
post("/variables", async function(c) {
|
|
7310
7317
|
const body = await bodyOf(c.req, variablesRequestSchema);
|
|
7311
7318
|
if (!body)
|
|
7312
|
-
return c.json(
|
|
7319
|
+
return c.json(malformedBody, 400);
|
|
7313
7320
|
const request = { ...body, token: c.req.header(END_USER_TOKEN_HEADER) };
|
|
7314
7321
|
const values = await Promise.all(Object.entries(options.variables ?? {}).map(async ([name, variable]) => [name, await variable.resolve(request)]));
|
|
7315
7322
|
return c.json({ values: Object.fromEntries(values) });
|
|
@@ -7321,7 +7328,7 @@ function defineServer(options) {
|
|
|
7321
7328
|
}
|
|
7322
7329
|
const body = await bodyOf(c.req, toolRequestSchema);
|
|
7323
7330
|
if (!body)
|
|
7324
|
-
return c.json(
|
|
7331
|
+
return c.json(malformedBody, 400);
|
|
7325
7332
|
const input = tool.input.safeParse(body.input);
|
|
7326
7333
|
if (!input.success) {
|
|
7327
7334
|
return c.json(errorEnvelope("invalid_request", z3.prettifyError(input.error)), 400);
|
|
@@ -7337,7 +7344,7 @@ function defineServer(options) {
|
|
|
7337
7344
|
post("/verify", async function(c) {
|
|
7338
7345
|
const body = await bodyOf(c.req, verifyRequestSchema);
|
|
7339
7346
|
if (!body)
|
|
7340
|
-
return c.json(
|
|
7347
|
+
return c.json(malformedBody, 400);
|
|
7341
7348
|
const verdict = await verify(body.token);
|
|
7342
7349
|
return c.json(verdict ? { sub: verdict.sub, claims: verdict.claims ?? {} } : { sub: null });
|
|
7343
7350
|
});
|
|
@@ -7349,22 +7356,16 @@ function defineServer(options) {
|
|
|
7349
7356
|
post(`/events/${event}`, async function(c) {
|
|
7350
7357
|
const body = await bodyOf(c.req, serverEventSchemas[event]);
|
|
7351
7358
|
if (!body)
|
|
7352
|
-
return c.json(
|
|
7359
|
+
return c.json(malformedBody, 400);
|
|
7353
7360
|
await handler(body);
|
|
7354
7361
|
return c.body(null, 204);
|
|
7355
7362
|
});
|
|
7356
7363
|
}
|
|
7357
7364
|
return app;
|
|
7358
7365
|
}
|
|
7359
|
-
// src/datasets/
|
|
7360
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
7366
|
+
// src/datasets/dataset-host.ts
|
|
7361
7367
|
import { Hono as Hono2 } from "hono";
|
|
7362
|
-
import { bodyLimit as bodyLimit2 } from "hono/body-limit";
|
|
7363
7368
|
var DEFAULT_TIMEOUT_MS = 30000;
|
|
7364
|
-
var QUERY_BODY_MAX_BYTES = 256 * 1024;
|
|
7365
|
-
function manifestVersion(definitions) {
|
|
7366
|
-
return createHash2("sha256").update(JSON.stringify(definitions)).digest("hex");
|
|
7367
|
-
}
|
|
7368
7369
|
function tokenFrom(headers, userToken) {
|
|
7369
7370
|
const raw = headers.get(userToken.header);
|
|
7370
7371
|
if (!raw)
|
|
@@ -7380,7 +7381,7 @@ function defineDatasetHost(options) {
|
|
|
7380
7381
|
const definitions = [...sources.values()].map((source) => source.definition).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
7381
7382
|
const catalog = datasetCatalogOf(definitions);
|
|
7382
7383
|
const manifest = {
|
|
7383
|
-
version:
|
|
7384
|
+
version: contentVersion(definitions),
|
|
7384
7385
|
datasets: definitions
|
|
7385
7386
|
};
|
|
7386
7387
|
const userToken = options.userToken ?? { header: END_USER_TOKEN_HEADER };
|
|
@@ -7389,11 +7390,7 @@ function defineDatasetHost(options) {
|
|
|
7389
7390
|
app.get("/", function(c) {
|
|
7390
7391
|
return c.json(manifest);
|
|
7391
7392
|
});
|
|
7392
|
-
|
|
7393
|
-
maxSize: QUERY_BODY_MAX_BYTES,
|
|
7394
|
-
onError: (c) => c.json(errorEnvelope("invalid_request", "Request body too large"), 413)
|
|
7395
|
-
});
|
|
7396
|
-
app.post("/:name", capBody, async function(c) {
|
|
7393
|
+
app.post("/:name", protocolBodyLimit(DATASET_REQUEST_MAX_BYTES), async function(c) {
|
|
7397
7394
|
const source = sources.get(c.req.param("name"));
|
|
7398
7395
|
if (!source) {
|
|
7399
7396
|
return c.json(errorEnvelope("invalid_request", `Unknown dataset "${c.req.param("name")}"`), 400);
|
|
@@ -7402,8 +7399,8 @@ function defineDatasetHost(options) {
|
|
|
7402
7399
|
return;
|
|
7403
7400
|
}));
|
|
7404
7401
|
if (!body.success)
|
|
7405
|
-
return c.json(
|
|
7406
|
-
const { query: raw } = body.data;
|
|
7402
|
+
return c.json(malformedBody, 400);
|
|
7403
|
+
const { query: raw, context } = body.data;
|
|
7407
7404
|
if (raw.from !== source.definition.name) {
|
|
7408
7405
|
return c.json(errorEnvelope("invalid_request", `Query is for "${raw.from}", not "${source.definition.name}"`), 400);
|
|
7409
7406
|
}
|
|
@@ -7415,7 +7412,7 @@ function defineDatasetHost(options) {
|
|
|
7415
7412
|
const resolveAndRun = async () => {
|
|
7416
7413
|
const user = await options.resolveUser({ token: tokenFrom(headers, userToken), headers }, signal);
|
|
7417
7414
|
signal.throwIfAborted();
|
|
7418
|
-
return source.run({ ...query, limit: query.limit + 1 }, user, signal);
|
|
7415
|
+
return source.run({ ...query, limit: query.limit + 1 }, user, signal, context);
|
|
7419
7416
|
};
|
|
7420
7417
|
try {
|
|
7421
7418
|
const rows = await Promise.race([
|
|
@@ -7432,7 +7429,7 @@ function defineDatasetHost(options) {
|
|
|
7432
7429
|
});
|
|
7433
7430
|
return app;
|
|
7434
7431
|
}
|
|
7435
|
-
// src/triggers/client.ts
|
|
7432
|
+
// src/triggers/trigger-client.ts
|
|
7436
7433
|
class TriggerClientError extends Error {
|
|
7437
7434
|
status;
|
|
7438
7435
|
body;
|
|
@@ -7447,7 +7444,7 @@ function isFiringRunning(firing) {
|
|
|
7447
7444
|
return firing.outcome === "started";
|
|
7448
7445
|
}
|
|
7449
7446
|
function createTriggerClient(config) {
|
|
7450
|
-
const
|
|
7447
|
+
const origin = config.url.replace(/\/+$/, "");
|
|
7451
7448
|
const fetchFn = config.fetch ?? globalThis.fetch;
|
|
7452
7449
|
function secretOf(trigger) {
|
|
7453
7450
|
const { secrets = {} } = config;
|
|
@@ -7458,7 +7455,7 @@ function createTriggerClient(config) {
|
|
|
7458
7455
|
return secret;
|
|
7459
7456
|
}
|
|
7460
7457
|
async function send(trigger, path, init, parse) {
|
|
7461
|
-
const response = await fetchFn(`${
|
|
7458
|
+
const response = await fetchFn(`${origin}${triggerRoute(config.agent, trigger)}${path}`, {
|
|
7462
7459
|
...init,
|
|
7463
7460
|
headers: { ...init.headers, Authorization: `Bearer ${secretOf(trigger)}` }
|
|
7464
7461
|
});
|
|
@@ -7531,7 +7528,10 @@ function canCarrySecret(url, allowed = egressAllowedHosts()) {
|
|
|
7531
7528
|
// ../../internal/contracts/src/manifest/index.ts
|
|
7532
7529
|
var TOOL_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
7533
7530
|
var RESPONSE_WRAPS = ["items", "value"];
|
|
7531
|
+
var QUERY_STYLES = ["form", "spaceDelimited", "pipeDelimited", "deepObject"];
|
|
7532
|
+
var PATH_STYLES = ["simple", "label", "matrix"];
|
|
7534
7533
|
var SOAP_VERSIONS = ["1.1", "1.2"];
|
|
7534
|
+
var jsonPointerSchema = z4.string().regex(/^\//).max(256);
|
|
7535
7535
|
var SETTING_BOUNDS = {
|
|
7536
7536
|
tool: {
|
|
7537
7537
|
timeoutMs: { min: 100, max: 120000, default: 30000 },
|
|
@@ -7562,8 +7562,12 @@ var SETTING_BOUNDS = {
|
|
|
7562
7562
|
function setting({ min, max, default: fallback }) {
|
|
7563
7563
|
return z4.number().int().min(min).max(max).default(fallback);
|
|
7564
7564
|
}
|
|
7565
|
+
function overridable(fields) {
|
|
7566
|
+
return z4.array(z4.enum(fields)).refine((listed) => new Set(listed).size === listed.length, "a field repeats").default([]);
|
|
7567
|
+
}
|
|
7565
7568
|
var SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
7566
|
-
var
|
|
7569
|
+
var SLUG_MAX_LENGTH = 64;
|
|
7570
|
+
var slugSchema = z4.string().regex(SLUG_PATTERN).max(SLUG_MAX_LENGTH);
|
|
7567
7571
|
var HOSTNAME_PATTERN = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/;
|
|
7568
7572
|
var FETCH_IMAGE_HOSTS_LIMIT = 20;
|
|
7569
7573
|
var SUGGESTION_LIMITS = { perLocale: 6, titleLength: 120, promptLength: 2000 };
|
|
@@ -7579,8 +7583,16 @@ var tlsUrlSchema = z4.url().refine((url) => canCarrySecret(url, []));
|
|
|
7579
7583
|
var embedOriginSchema = tlsUrlSchema.transform((value) => new URL(value).origin);
|
|
7580
7584
|
var soapActionSchema = z4.string().regex(/^[^"\\\u0000-\u001f\u007f]*$/);
|
|
7581
7585
|
var envelopeTemplateSchema = z4.string().refine((template) => template.trim().length > 0);
|
|
7586
|
+
var FORM_MEDIA_TYPES = [
|
|
7587
|
+
"application/x-www-form-urlencoded",
|
|
7588
|
+
"multipart/form-data"
|
|
7589
|
+
];
|
|
7582
7590
|
var toolConfigByType = {
|
|
7583
|
-
http: z4.object({
|
|
7591
|
+
http: z4.object({
|
|
7592
|
+
responseWrap: z4.enum(RESPONSE_WRAPS).optional(),
|
|
7593
|
+
requestMediaType: z4.enum(FORM_MEDIA_TYPES).optional(),
|
|
7594
|
+
resultPath: jsonPointerSchema.optional()
|
|
7595
|
+
}),
|
|
7584
7596
|
embedded: z4.object({ embedOrigin: embedOriginSchema, surface: z4.enum(TOOL_SURFACES) }),
|
|
7585
7597
|
soap: z4.object({
|
|
7586
7598
|
soapVersion: z4.enum(SOAP_VERSIONS),
|
|
@@ -7595,6 +7607,54 @@ var toolConfigByType = {
|
|
|
7595
7607
|
native: z4.object({}),
|
|
7596
7608
|
client: z4.object({})
|
|
7597
7609
|
};
|
|
7610
|
+
var TOOL_TYPE_NAMES = ["http", "embedded", "soap", "native", "client"];
|
|
7611
|
+
var TOOL_TYPES = {
|
|
7612
|
+
http: {
|
|
7613
|
+
kind: "server",
|
|
7614
|
+
calls: true,
|
|
7615
|
+
approval: true,
|
|
7616
|
+
sources: true,
|
|
7617
|
+
targets: true,
|
|
7618
|
+
creatable: true
|
|
7619
|
+
},
|
|
7620
|
+
embedded: {
|
|
7621
|
+
kind: "client",
|
|
7622
|
+
calls: true,
|
|
7623
|
+
approval: false,
|
|
7624
|
+
sources: true,
|
|
7625
|
+
targets: false,
|
|
7626
|
+
creatable: true,
|
|
7627
|
+
readOnly: false
|
|
7628
|
+
},
|
|
7629
|
+
soap: {
|
|
7630
|
+
kind: "server",
|
|
7631
|
+
calls: true,
|
|
7632
|
+
approval: true,
|
|
7633
|
+
sources: true,
|
|
7634
|
+
targets: true,
|
|
7635
|
+
creatable: true,
|
|
7636
|
+
method: "POST"
|
|
7637
|
+
},
|
|
7638
|
+
native: {
|
|
7639
|
+
kind: "server",
|
|
7640
|
+
calls: true,
|
|
7641
|
+
approval: true,
|
|
7642
|
+
sources: false,
|
|
7643
|
+
targets: false,
|
|
7644
|
+
creatable: false,
|
|
7645
|
+
method: "POST"
|
|
7646
|
+
},
|
|
7647
|
+
client: {
|
|
7648
|
+
kind: "client",
|
|
7649
|
+
calls: false,
|
|
7650
|
+
approval: false,
|
|
7651
|
+
sources: false,
|
|
7652
|
+
targets: false,
|
|
7653
|
+
creatable: true,
|
|
7654
|
+
readOnly: true
|
|
7655
|
+
}
|
|
7656
|
+
};
|
|
7657
|
+
var CREATABLE_TOOL_TYPES = TOOL_TYPE_NAMES.filter((type) => TOOL_TYPES[type].creatable);
|
|
7598
7658
|
var ENDPOINT_PARAM_PATTERN = /\{([^{}]+)\}/g;
|
|
7599
7659
|
function confinesEndpointParams(url) {
|
|
7600
7660
|
const origin = /^[^:/?#]*:[/\\]*[^/\\?#]*/.exec(url)?.[0] ?? "";
|
|
@@ -7603,8 +7663,9 @@ function confinesEndpointParams(url) {
|
|
|
7603
7663
|
return ![origin, fragment].some((part) => part.match(ENDPOINT_PARAM_PATTERN));
|
|
7604
7664
|
}
|
|
7605
7665
|
var upstreamUrlSchema = z4.url({ protocol: /^https?$/ });
|
|
7666
|
+
var CREDENTIAL_LIMITS = { headerLength: 120, prefixLength: 40, presentations: 8 };
|
|
7606
7667
|
var HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
7607
|
-
var headerNameSchema = z4.string().trim().min(1).max(
|
|
7668
|
+
var headerNameSchema = z4.string().trim().min(1).max(CREDENTIAL_LIMITS.headerLength).regex(HEADER_NAME_PATTERN);
|
|
7608
7669
|
var transportSetHeaders = ["accept", "content-type", "content-length", "host"];
|
|
7609
7670
|
var transportForbiddenHeaders = [
|
|
7610
7671
|
"connection",
|
|
@@ -7624,7 +7685,6 @@ var transportOwnedHeaders = new Set([
|
|
|
7624
7685
|
...transportSetHeaders,
|
|
7625
7686
|
...transportForbiddenHeaders
|
|
7626
7687
|
]);
|
|
7627
|
-
var CREDENTIAL_PRESENTATION_LIMIT = 8;
|
|
7628
7688
|
function repeatedHeaders(entries) {
|
|
7629
7689
|
const seen = new Set;
|
|
7630
7690
|
return entries.flatMap((entry, index) => {
|
|
@@ -7634,23 +7694,31 @@ function repeatedHeaders(entries) {
|
|
|
7634
7694
|
return repeated ? [index] : [];
|
|
7635
7695
|
});
|
|
7636
7696
|
}
|
|
7637
|
-
var
|
|
7697
|
+
var NAME_MAX_LENGTH = 120;
|
|
7698
|
+
var nameSchema = z4.string().trim().min(1).max(NAME_MAX_LENGTH);
|
|
7638
7699
|
var presentedHeaderSchema = headerNameSchema.refine((name) => !transportOwnedHeaders.has(name.toLowerCase()), "a header the transport sets");
|
|
7639
|
-
function presentationsSchema(
|
|
7640
|
-
return z4.array(
|
|
7700
|
+
function presentationsSchema(entry, repeated) {
|
|
7701
|
+
return z4.array(entry).max(CREDENTIAL_LIMITS.presentations).superRefine((entries, context) => {
|
|
7641
7702
|
for (const index of repeatedHeaders(entries)) {
|
|
7642
7703
|
context.addIssue({
|
|
7643
7704
|
code: "custom",
|
|
7644
7705
|
path: [index, "header"],
|
|
7645
|
-
message:
|
|
7706
|
+
message: repeated()
|
|
7646
7707
|
});
|
|
7647
7708
|
}
|
|
7648
|
-
})
|
|
7709
|
+
});
|
|
7649
7710
|
}
|
|
7650
|
-
|
|
7711
|
+
function declaredPresentationsSchema(header, credential) {
|
|
7712
|
+
return presentationsSchema(z4.strictObject({
|
|
7713
|
+
header,
|
|
7714
|
+
prefix: z4.string().max(CREDENTIAL_LIMITS.prefixLength).default(""),
|
|
7715
|
+
credential
|
|
7716
|
+
}), () => "a header presented twice").default([]);
|
|
7717
|
+
}
|
|
7718
|
+
var credentialsSchema = declaredPresentationsSchema(presentedHeaderSchema, nameSchema.nullable());
|
|
7651
7719
|
var fieldSourceSchema = z4.discriminatedUnion("kind", [
|
|
7652
7720
|
z4.object({ kind: z4.literal("variable"), name: z4.string().trim().min(1).max(64) }),
|
|
7653
|
-
z4.object({ kind: z4.literal("secret"), name:
|
|
7721
|
+
z4.object({ kind: z4.literal("secret"), name: nameSchema }),
|
|
7654
7722
|
z4.object({
|
|
7655
7723
|
kind: z4.literal("constant"),
|
|
7656
7724
|
value: z4.union([z4.string().max(4000), z4.number(), z4.boolean()])
|
|
@@ -7679,30 +7747,53 @@ function sourceFits(source, field) {
|
|
|
7679
7747
|
}
|
|
7680
7748
|
}
|
|
7681
7749
|
var fieldTargetSchema = z4.discriminatedUnion("kind", [
|
|
7682
|
-
z4.
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7750
|
+
z4.strictObject({
|
|
7751
|
+
kind: z4.literal("body"),
|
|
7752
|
+
contentType: z4.enum(["application/json", "text/plain"]).optional(),
|
|
7753
|
+
style: z4.enum(QUERY_STYLES).optional(),
|
|
7754
|
+
explode: z4.boolean().optional()
|
|
7755
|
+
}),
|
|
7756
|
+
z4.strictObject({
|
|
7757
|
+
kind: z4.literal("query"),
|
|
7758
|
+
name: z4.string().trim().min(1).max(120).optional(),
|
|
7759
|
+
style: z4.enum(QUERY_STYLES).optional(),
|
|
7760
|
+
explode: z4.boolean().optional()
|
|
7761
|
+
}),
|
|
7762
|
+
z4.strictObject({
|
|
7763
|
+
kind: z4.literal("path"),
|
|
7764
|
+
name: z4.string().trim().min(1).max(120).optional(),
|
|
7765
|
+
style: z4.enum(PATH_STYLES).optional(),
|
|
7766
|
+
explode: z4.boolean().optional()
|
|
7767
|
+
}),
|
|
7768
|
+
z4.strictObject({
|
|
7769
|
+
kind: z4.literal("header"),
|
|
7770
|
+
name: headerNameSchema.optional(),
|
|
7771
|
+
explode: z4.boolean().optional()
|
|
7772
|
+
}),
|
|
7773
|
+
z4.strictObject({ kind: z4.literal("cookie"), name: headerNameSchema.optional() })
|
|
7687
7774
|
]);
|
|
7688
7775
|
var SCALAR_TYPES = ["string", "number", "integer", "boolean"];
|
|
7689
7776
|
var schemaTypeSchema = z4.enum([...SCALAR_TYPES, "object", "array"]);
|
|
7690
|
-
var
|
|
7777
|
+
var FIELD_LIMITS = { nameLength: 120, descriptionLength: 500, enumValues: 50 };
|
|
7778
|
+
var propertyNameSchema = z4.string().min(1).max(FIELD_LIMITS.nameLength).refine((name) => name === name.trim(), "no surrounding spaces");
|
|
7779
|
+
var propertyOrderSchema = z4.array(z4.string()).refine((names) => new Set(names).size === names.length, "a name repeats").optional();
|
|
7691
7780
|
var itemsSchema = z4.strictObject({
|
|
7692
7781
|
type: z4.enum([...SCALAR_TYPES, "object"]),
|
|
7693
7782
|
get properties() {
|
|
7694
7783
|
return z4.record(propertyNameSchema, schemaPropertySchema).optional();
|
|
7695
7784
|
},
|
|
7696
|
-
required: z4.array(z4.string()).optional()
|
|
7785
|
+
required: z4.array(z4.string()).optional(),
|
|
7786
|
+
"x-order": propertyOrderSchema
|
|
7697
7787
|
});
|
|
7698
7788
|
var schemaPropertySchema = z4.strictObject({
|
|
7699
7789
|
type: z4.union([schemaTypeSchema, z4.tuple([schemaTypeSchema, z4.literal("null")])]),
|
|
7700
|
-
description: z4.string().trim().max(
|
|
7701
|
-
enum: z4.array(z4.union([z4.string().trim().min(1), z4.null()])).min(1).max(
|
|
7790
|
+
description: z4.string().trim().max(FIELD_LIMITS.descriptionLength).optional(),
|
|
7791
|
+
enum: z4.array(z4.union([z4.string().trim().min(1), z4.null()])).min(1).max(FIELD_LIMITS.enumValues + 1).optional(),
|
|
7702
7792
|
get properties() {
|
|
7703
7793
|
return z4.record(propertyNameSchema, schemaPropertySchema).optional();
|
|
7704
7794
|
},
|
|
7705
7795
|
required: z4.array(z4.string()).optional(),
|
|
7796
|
+
"x-order": propertyOrderSchema,
|
|
7706
7797
|
get items() {
|
|
7707
7798
|
return itemsSchema.optional();
|
|
7708
7799
|
},
|
|
@@ -7716,16 +7807,18 @@ function typeOf(node) {
|
|
|
7716
7807
|
function nodeIssues(node) {
|
|
7717
7808
|
const issues = new Array;
|
|
7718
7809
|
const object = typeOf(node) === "object";
|
|
7719
|
-
for (const keyword of ["properties", "required"]) {
|
|
7810
|
+
for (const keyword of ["properties", "required", "x-order"]) {
|
|
7720
7811
|
if (!object && node[keyword] !== undefined) {
|
|
7721
7812
|
issues.push({ at: [keyword], message: "only an object has it" });
|
|
7722
7813
|
}
|
|
7723
7814
|
}
|
|
7724
|
-
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
|
|
7728
|
-
|
|
7815
|
+
for (const keyword of ["required", "x-order"]) {
|
|
7816
|
+
node[keyword]?.forEach((name, index) => {
|
|
7817
|
+
if (!Object.hasOwn(node.properties ?? {}, name)) {
|
|
7818
|
+
issues.push({ at: [keyword, index], message: "names no property" });
|
|
7819
|
+
}
|
|
7820
|
+
});
|
|
7821
|
+
}
|
|
7729
7822
|
return issues;
|
|
7730
7823
|
}
|
|
7731
7824
|
function enumIssueOf(property, type) {
|
|
@@ -7734,14 +7827,15 @@ function enumIssueOf(property, type) {
|
|
|
7734
7827
|
if (type !== "string")
|
|
7735
7828
|
return "an enum lists a string's values";
|
|
7736
7829
|
const values = property.enum.filter((value) => value !== null);
|
|
7737
|
-
if (values.length === 0 || values.length >
|
|
7738
|
-
return
|
|
7830
|
+
if (values.length === 0 || values.length > FIELD_LIMITS.enumValues) {
|
|
7831
|
+
return `an enum lists 1 to ${FIELD_LIMITS.enumValues} values`;
|
|
7832
|
+
}
|
|
7739
7833
|
const nullable = Array.isArray(property.type);
|
|
7740
7834
|
if (nullable === property.enum.includes(null))
|
|
7741
7835
|
return;
|
|
7742
7836
|
return nullable ? "a nullable enum lists null" : "only a nullable enum lists null";
|
|
7743
7837
|
}
|
|
7744
|
-
function propertyIssues(property,
|
|
7838
|
+
function propertyIssues(property, bindings) {
|
|
7745
7839
|
const issues = new Array;
|
|
7746
7840
|
const type = typeOf(property);
|
|
7747
7841
|
const enumIssue = enumIssueOf(property, type);
|
|
@@ -7753,22 +7847,30 @@ function propertyIssues(property, bindable) {
|
|
|
7753
7847
|
message: type === "array" ? "an array declares its items" : "only an array has it"
|
|
7754
7848
|
});
|
|
7755
7849
|
}
|
|
7756
|
-
|
|
7850
|
+
return [...issues, ...bindingIssues(property, type, bindings)];
|
|
7851
|
+
}
|
|
7852
|
+
function bindingIssues(property, type, bindings) {
|
|
7853
|
+
const issues = new Array;
|
|
7854
|
+
const scalar = SCALAR_TYPES.some((scalar2) => scalar2 === type);
|
|
7855
|
+
const fields = { "x-source": "a top-level scalar field", "x-target": "a top-level field" };
|
|
7757
7856
|
for (const binding of ["x-source", "x-target"]) {
|
|
7758
|
-
if (property[binding]
|
|
7759
|
-
|
|
7760
|
-
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
|
|
7857
|
+
if (property[binding] === undefined)
|
|
7858
|
+
continue;
|
|
7859
|
+
const reaches = bindings !== undefined && (binding === "x-target" || scalar);
|
|
7860
|
+
if (reaches && bindings.includes(binding))
|
|
7861
|
+
continue;
|
|
7862
|
+
issues.push({
|
|
7863
|
+
at: [binding],
|
|
7864
|
+
message: reaches ? "this type of tool takes none" : `only ${fields[binding]} of a tool's input has it`
|
|
7865
|
+
});
|
|
7764
7866
|
}
|
|
7765
7867
|
const source = property["x-source"];
|
|
7766
|
-
if (
|
|
7868
|
+
if (scalar && bindings?.includes("x-source") && source && !sourceFits(source, { type, enum: property.enum })) {
|
|
7767
7869
|
issues.push({ at: ["x-source"], message: "the source does not fit the field's type" });
|
|
7768
7870
|
}
|
|
7769
7871
|
return issues;
|
|
7770
7872
|
}
|
|
7771
|
-
function heldByRows(node, context, path,
|
|
7873
|
+
function heldByRows(node, context, path, bindings) {
|
|
7772
7874
|
const report = (under, issues) => {
|
|
7773
7875
|
for (const { at, message } of issues) {
|
|
7774
7876
|
context.addIssue({ code: "custom", path: [...under, ...at], message });
|
|
@@ -7777,20 +7879,21 @@ function heldByRows(node, context, path, bindable) {
|
|
|
7777
7879
|
report(path, nodeIssues(node));
|
|
7778
7880
|
for (const [name, property] of Object.entries(node.properties ?? {})) {
|
|
7779
7881
|
const at = [...path, "properties", name];
|
|
7780
|
-
report(at, propertyIssues(property,
|
|
7781
|
-
heldByRows(property, context, at,
|
|
7882
|
+
report(at, propertyIssues(property, bindings));
|
|
7883
|
+
heldByRows(property, context, at, undefined);
|
|
7782
7884
|
if (property.items)
|
|
7783
|
-
heldByRows(property.items, context, [...at, "items"],
|
|
7885
|
+
heldByRows(property.items, context, [...at, "items"], undefined);
|
|
7784
7886
|
}
|
|
7785
7887
|
}
|
|
7786
|
-
function
|
|
7888
|
+
function objectJsonSchemaOf(bindings) {
|
|
7787
7889
|
return z4.strictObject({
|
|
7788
7890
|
type: z4.literal("object"),
|
|
7789
7891
|
properties: z4.record(propertyNameSchema, schemaPropertySchema).optional(),
|
|
7790
|
-
required: z4.array(z4.string()).optional()
|
|
7791
|
-
|
|
7892
|
+
required: z4.array(z4.string()).optional(),
|
|
7893
|
+
"x-order": propertyOrderSchema
|
|
7894
|
+
}).superRefine((schema, context) => heldByRows(schema, context, [], bindings));
|
|
7792
7895
|
}
|
|
7793
|
-
var objectSchema =
|
|
7896
|
+
var objectSchema = objectJsonSchemaOf();
|
|
7794
7897
|
var EMPTY_OBJECT = { type: "object" };
|
|
7795
7898
|
var audienceSchema = z4.union([
|
|
7796
7899
|
z4.literal("all"),
|
|
@@ -7799,17 +7902,26 @@ var audienceSchema = z4.union([
|
|
|
7799
7902
|
agents: z4.array(agentSlugSchema).min(1).refine((slugs) => new Set(slugs).size === slugs.length, "an agent repeats")
|
|
7800
7903
|
})
|
|
7801
7904
|
]);
|
|
7905
|
+
var MODEL_PROVIDER_LIMITS = { urlLength: 2048, modelLength: 200, models: 100 };
|
|
7802
7906
|
var modelSchema = z4.strictObject({
|
|
7803
7907
|
provider: nameSchema,
|
|
7804
|
-
model: z4.string().trim().min(1).max(
|
|
7908
|
+
model: z4.string().trim().min(1).max(MODEL_PROVIDER_LIMITS.modelLength),
|
|
7805
7909
|
effort: z4.string().trim().min(1).max(64).optional()
|
|
7806
7910
|
});
|
|
7807
|
-
var
|
|
7808
|
-
var
|
|
7911
|
+
var SERVICE_LIMITS = { nameLength: 120, descriptionLength: 4000 };
|
|
7912
|
+
var localizedLineSchema = z4.record(localeSchema, z4.string().trim().min(1).max(SERVICE_LIMITS.nameLength));
|
|
7913
|
+
var localizedTextSchema = z4.record(localeSchema, z4.string().trim().min(1).max(SERVICE_LIMITS.descriptionLength));
|
|
7809
7914
|
var { tool: toolBounds } = SETTING_BOUNDS;
|
|
7915
|
+
function toolInputSchemaOf(type) {
|
|
7916
|
+
const { sources, targets } = TOOL_TYPES[type];
|
|
7917
|
+
return objectJsonSchemaOf([
|
|
7918
|
+
...sources ? ["x-source"] : [],
|
|
7919
|
+
...targets ? ["x-target"] : []
|
|
7920
|
+
]).default(EMPTY_OBJECT);
|
|
7921
|
+
}
|
|
7810
7922
|
var toolBaseSchema = z4.strictObject({
|
|
7811
7923
|
...serverToolSchema.pick({ name: true, description: true }).shape,
|
|
7812
|
-
inputSchema:
|
|
7924
|
+
inputSchema: toolInputSchemaOf("client"),
|
|
7813
7925
|
outputSchema: objectSchema.default(EMPTY_OBJECT),
|
|
7814
7926
|
timeoutMs: setting(toolBounds.timeoutMs),
|
|
7815
7927
|
maxResponseBytes: setting(toolBounds.maxResponseBytes),
|
|
@@ -7818,10 +7930,18 @@ var toolBaseSchema = z4.strictObject({
|
|
|
7818
7930
|
projectOutput: z4.boolean().default(false),
|
|
7819
7931
|
pinned: z4.boolean().default(false),
|
|
7820
7932
|
tags: toolTagsSchema.default([]),
|
|
7821
|
-
audience: audienceSchema
|
|
7933
|
+
audience: audienceSchema,
|
|
7934
|
+
overridable: overridable([
|
|
7935
|
+
"description",
|
|
7936
|
+
"timeoutMs",
|
|
7937
|
+
"maxResponseBytes",
|
|
7938
|
+
"rateLimitRequests",
|
|
7939
|
+
"rateLimitWindowSeconds",
|
|
7940
|
+
"pinned",
|
|
7941
|
+
"tags"
|
|
7942
|
+
])
|
|
7822
7943
|
});
|
|
7823
7944
|
var calledToolSchema = toolBaseSchema.extend({
|
|
7824
|
-
inputSchema: objectSchemaOf(true).default(EMPTY_OBJECT),
|
|
7825
7945
|
url: upstreamUrlSchema.refine(confinesEndpointParams, "a {parameter} outside the path or query"),
|
|
7826
7946
|
credentials: credentialsSchema,
|
|
7827
7947
|
requiresApproval: z4.boolean().default(false)
|
|
@@ -7829,30 +7949,31 @@ var calledToolSchema = toolBaseSchema.extend({
|
|
|
7829
7949
|
var manifestToolSchema = z4.discriminatedUnion("type", [
|
|
7830
7950
|
calledToolSchema.extend({
|
|
7831
7951
|
type: z4.literal("http"),
|
|
7952
|
+
inputSchema: toolInputSchemaOf("http"),
|
|
7832
7953
|
method: z4.enum(TOOL_METHODS),
|
|
7833
7954
|
readOnly: z4.boolean(),
|
|
7834
7955
|
...toolConfigByType.http.shape
|
|
7835
7956
|
}),
|
|
7836
|
-
calledToolSchema.extend({
|
|
7957
|
+
calledToolSchema.omit({ requiresApproval: true }).extend({
|
|
7837
7958
|
type: z4.literal("embedded"),
|
|
7959
|
+
inputSchema: toolInputSchemaOf("embedded"),
|
|
7838
7960
|
method: z4.enum(TOOL_METHODS),
|
|
7839
7961
|
...toolConfigByType.embedded.shape
|
|
7840
7962
|
}),
|
|
7841
7963
|
calledToolSchema.extend({
|
|
7842
7964
|
type: z4.literal("soap"),
|
|
7965
|
+
inputSchema: toolInputSchemaOf("soap"),
|
|
7843
7966
|
readOnly: z4.boolean(),
|
|
7844
7967
|
...toolConfigByType.soap.shape
|
|
7845
7968
|
}),
|
|
7846
7969
|
toolBaseSchema.extend({ type: z4.literal("client") })
|
|
7847
|
-
]).superRefine((tool, context) =>
|
|
7848
|
-
if (tool.type !== "client")
|
|
7849
|
-
refuseBlockedApprovalTitle(tool, context, []);
|
|
7850
|
-
});
|
|
7970
|
+
]).superRefine((tool, context) => refuseBlockedApprovalTitle(tool, context, []));
|
|
7851
7971
|
var toolNamesSchema = z4.array(serverToolSchema.shape.name).max(500).default([]);
|
|
7852
7972
|
var manifestOpenApiSchema = z4.strictObject({
|
|
7853
7973
|
name: nameSchema,
|
|
7854
7974
|
url: upstreamUrlSchema,
|
|
7855
7975
|
credentials: credentialsSchema,
|
|
7976
|
+
resultPath: jsonPointerSchema.optional(),
|
|
7856
7977
|
pinned: toolNamesSchema,
|
|
7857
7978
|
approval: z4.strictObject({ never: toolNamesSchema, always: toolNamesSchema }).prefault({}).refine(({ never, always }) => !never.some((name) => always.includes(name)), "a tool both never and always needs approval"),
|
|
7858
7979
|
audience: audienceSchema
|
|
@@ -7861,34 +7982,46 @@ var manifestServiceSchema = z4.strictObject({
|
|
|
7861
7982
|
key: slugSchema,
|
|
7862
7983
|
name: localizedLineSchema,
|
|
7863
7984
|
description: localizedTextSchema,
|
|
7864
|
-
audience: audienceSchema
|
|
7985
|
+
audience: audienceSchema,
|
|
7986
|
+
overridable: overridable(["description"])
|
|
7865
7987
|
});
|
|
7988
|
+
var SKILL_LIMITS = { descriptionLength: 500 };
|
|
7866
7989
|
var manifestSkillSchema = z4.strictObject({
|
|
7867
7990
|
name: slugSchema,
|
|
7868
|
-
description: z4.string().trim().min(1).max(
|
|
7991
|
+
description: z4.string().trim().min(1).max(SKILL_LIMITS.descriptionLength),
|
|
7869
7992
|
body: z4.string().trim().min(1),
|
|
7870
7993
|
service: slugSchema.optional(),
|
|
7871
|
-
audience: audienceSchema
|
|
7994
|
+
audience: audienceSchema,
|
|
7995
|
+
overridable: overridable(["description", "body"])
|
|
7872
7996
|
});
|
|
7873
7997
|
var triggerThreadPolicySchema = z4.discriminatedUnion("policy", [
|
|
7874
7998
|
z4.object({ policy: z4.literal("single") }),
|
|
7875
7999
|
z4.object({ policy: z4.literal("per-firing") }),
|
|
7876
8000
|
z4.object({ policy: z4.literal("ephemeral") }),
|
|
7877
|
-
z4.object({ policy: z4.literal("keyed"), key:
|
|
8001
|
+
z4.object({ policy: z4.literal("keyed"), key: jsonPointerSchema })
|
|
7878
8002
|
]);
|
|
8003
|
+
var TRIGGER_LIMITS = { descriptionLength: 500, instructionsLength: 20000 };
|
|
7879
8004
|
var manifestTriggerSchema = z4.strictObject({
|
|
7880
8005
|
name: slugSchema.refine((name) => name !== MESSAGE_TRIGGER_NAME, "the built-in trigger's name"),
|
|
7881
|
-
description: z4.string().trim().min(1).max(
|
|
8006
|
+
description: z4.string().trim().min(1).max(TRIGGER_LIMITS.descriptionLength),
|
|
7882
8007
|
inputSchema: objectSchema.default(EMPTY_OBJECT),
|
|
7883
8008
|
outputSchema: objectSchema.refine((schema) => Object.keys(schema.properties ?? {}).length > 0, "declares a property; leave it out for a free-text answer").optional(),
|
|
7884
|
-
instructions: z4.string().trim().min(1).max(
|
|
8009
|
+
instructions: z4.string().trim().min(1).max(TRIGGER_LIMITS.instructionsLength),
|
|
7885
8010
|
threadPolicy: triggerThreadPolicySchema.default({ policy: "single" }),
|
|
7886
8011
|
budgetPerDay: z4.number().int().positive().optional(),
|
|
7887
8012
|
disableAfterFailures: setting(SETTING_BOUNDS.trigger.disableAfterFailures),
|
|
7888
8013
|
credential: nameSchema.optional(),
|
|
7889
8014
|
fireCredential: nameSchema.optional(),
|
|
7890
8015
|
model: modelSchema.optional(),
|
|
7891
|
-
audience: audienceSchema
|
|
8016
|
+
audience: audienceSchema,
|
|
8017
|
+
overridable: overridable([
|
|
8018
|
+
"description",
|
|
8019
|
+
"instructions",
|
|
8020
|
+
"threadPolicy",
|
|
8021
|
+
"budgetPerDay",
|
|
8022
|
+
"disableAfterFailures",
|
|
8023
|
+
"model"
|
|
8024
|
+
])
|
|
7892
8025
|
});
|
|
7893
8026
|
function unexposedPins(host) {
|
|
7894
8027
|
const exposed = new Set(host.expose);
|
|
@@ -7901,7 +8034,8 @@ var manifestDatasetHostSchema = z4.strictObject({
|
|
|
7901
8034
|
timeoutMs: setting(SETTING_BOUNDS.datasetHost.timeoutMs),
|
|
7902
8035
|
expose: z4.array(datasetIdentifierSchema).min(1).max(500),
|
|
7903
8036
|
pinned: z4.array(datasetIdentifierSchema).max(50).default([]),
|
|
7904
|
-
audience: audienceSchema
|
|
8037
|
+
audience: audienceSchema,
|
|
8038
|
+
overridable: overridable(["timeoutMs"])
|
|
7905
8039
|
}).superRefine((host, context) => {
|
|
7906
8040
|
const unexposed = unexposedPins(host);
|
|
7907
8041
|
if (unexposed.length > 0) {
|
|
@@ -7914,27 +8048,32 @@ var manifestDatasetHostSchema = z4.strictObject({
|
|
|
7914
8048
|
});
|
|
7915
8049
|
var mcpToolNamesSchema = z4.array(z4.string().trim().min(1).max(128).regex(/^[^,]*$/, "a tool name holds no comma")).max(200);
|
|
7916
8050
|
var manifestMcpServerSchema = z4.strictObject({
|
|
7917
|
-
name:
|
|
8051
|
+
name: identifierSchema,
|
|
7918
8052
|
url: upstreamUrlSchema,
|
|
7919
|
-
credentials:
|
|
8053
|
+
credentials: declaredPresentationsSchema(presentedHeaderSchema.refine((name) => !mcpTransportHeaders.has(name.toLowerCase()), "a header the MCP transport sets"), nameSchema.nullable()),
|
|
7920
8054
|
include: mcpToolNamesSchema.default([]),
|
|
7921
8055
|
exclude: mcpToolNamesSchema.default([]),
|
|
7922
|
-
audience: audienceSchema
|
|
8056
|
+
audience: audienceSchema,
|
|
8057
|
+
overridable: overridable(["include", "exclude"])
|
|
7923
8058
|
});
|
|
7924
8059
|
var manifestWebhookSchema = z4.strictObject({
|
|
7925
8060
|
name: slugSchema,
|
|
7926
8061
|
description: z4.string().trim().max(500).default(""),
|
|
7927
8062
|
event: z4.enum(SERVER_EVENTS),
|
|
7928
8063
|
url: upstreamUrlSchema,
|
|
7929
|
-
credentials:
|
|
8064
|
+
credentials: declaredPresentationsSchema(presentedHeaderSchema.refine((name) => name.toLowerCase() !== EVENT_HEADER.toLowerCase(), "the header that names the event"), nameSchema),
|
|
7930
8065
|
timeoutMs: setting(SETTING_BOUNDS.webhook.timeoutMs),
|
|
7931
|
-
audience: audienceSchema
|
|
8066
|
+
audience: audienceSchema,
|
|
8067
|
+
overridable: overridable(["description", "timeoutMs"])
|
|
7932
8068
|
});
|
|
8069
|
+
var COLLECTION_LIMITS = { nameLength: 80, descriptionLength: 2000 };
|
|
7933
8070
|
var manifestCollectionSchema = z4.strictObject({
|
|
7934
|
-
name: z4.string().trim().min(1).max(
|
|
7935
|
-
description: z4.string().trim().max(
|
|
8071
|
+
name: z4.string().trim().min(1).max(COLLECTION_LIMITS.nameLength),
|
|
8072
|
+
description: z4.string().trim().max(COLLECTION_LIMITS.descriptionLength).default(""),
|
|
7936
8073
|
service: slugSchema.optional(),
|
|
7937
|
-
|
|
8074
|
+
citable: z4.boolean().default(true),
|
|
8075
|
+
audience: audienceSchema,
|
|
8076
|
+
overridable: overridable(["description"])
|
|
7938
8077
|
});
|
|
7939
8078
|
var AUTH_JWT_SECRET_ALGORITHMS = ["HS256", "HS384", "HS512"];
|
|
7940
8079
|
var issuerSchema = z4.string().trim().min(1).max(2048);
|
|
@@ -7966,7 +8105,7 @@ var agentSettingsSchema = z4.strictObject({
|
|
|
7966
8105
|
locationPicker: z4.boolean().default(false),
|
|
7967
8106
|
media: z4.array(z4.enum(MEDIA_FORMS)).default([...DEFAULT_MEDIA_FORMS]),
|
|
7968
8107
|
messageTrigger: z4.boolean().default(true),
|
|
7969
|
-
defaultLocale: localeSchema.default(
|
|
8108
|
+
defaultLocale: localeSchema.default(BASE_LOCALE),
|
|
7970
8109
|
rateLimitRequests: setting(agentBounds.rateLimitRequests),
|
|
7971
8110
|
rateLimitWindowSeconds: setting(agentBounds.rateLimitWindowSeconds),
|
|
7972
8111
|
dailyExecutionQuota: setting(agentBounds.dailyExecutionQuota),
|
|
@@ -7982,9 +8121,10 @@ var agentSettingsSchema = z4.strictObject({
|
|
|
7982
8121
|
maxResponseBytes: setting(agentLimits.maxResponseBytes)
|
|
7983
8122
|
}).prefault({})
|
|
7984
8123
|
});
|
|
8124
|
+
var AGENT_LIMITS = { nameLength: 120 };
|
|
7985
8125
|
var manifestAgentSchema = z4.strictObject({
|
|
7986
8126
|
slug: agentSlugSchema,
|
|
7987
|
-
name: z4.string().trim().min(1).max(
|
|
8127
|
+
name: z4.string().trim().min(1).max(AGENT_LIMITS.nameLength),
|
|
7988
8128
|
server: nameSchema,
|
|
7989
8129
|
prompt: z4.string().trim().min(1),
|
|
7990
8130
|
auth: agentAuthSchema,
|
|
@@ -7994,35 +8134,68 @@ var manifestAgentSchema = z4.strictObject({
|
|
|
7994
8134
|
summarization: modelSchema.omit({ effort: true }).optional()
|
|
7995
8135
|
}).default({}),
|
|
7996
8136
|
settings: agentSettingsSchema.prefault({}),
|
|
7997
|
-
suggestions: suggestionsSchema.default(
|
|
7998
|
-
greeting: greetingSchema.default(
|
|
8137
|
+
suggestions: suggestionsSchema.default(() => byLocale(() => [])),
|
|
8138
|
+
greeting: greetingSchema.default(() => byLocale(() => "")),
|
|
8139
|
+
overridable: overridable(["name", "prompt", "models", "settings", "suggestions", "greeting"])
|
|
7999
8140
|
});
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8141
|
+
var MANIFEST_KINDS = [
|
|
8142
|
+
"agents",
|
|
8143
|
+
"services",
|
|
8144
|
+
"tools",
|
|
8145
|
+
"skills",
|
|
8146
|
+
"triggers",
|
|
8147
|
+
"datasetHosts",
|
|
8148
|
+
"mcpServers",
|
|
8149
|
+
"webhooks",
|
|
8150
|
+
"collections"
|
|
8151
|
+
];
|
|
8152
|
+
var MANIFEST_NAME_FIELDS = {
|
|
8153
|
+
agents: "slug",
|
|
8154
|
+
tools: "name",
|
|
8155
|
+
services: "key",
|
|
8156
|
+
skills: "name",
|
|
8157
|
+
triggers: "name",
|
|
8158
|
+
datasetHosts: "name",
|
|
8159
|
+
mcpServers: "name",
|
|
8160
|
+
webhooks: "name",
|
|
8161
|
+
collections: "name"
|
|
8162
|
+
};
|
|
8163
|
+
function listOf(field, entry) {
|
|
8164
|
+
return z4.array(entry).refine((entries) => new Set(entries.map((value) => value[field])).size === entries.length, "a name repeats").default([]);
|
|
8005
8165
|
}
|
|
8006
|
-
var byName = (entry) => entry.name;
|
|
8007
8166
|
var manifestSchema = z4.strictObject({
|
|
8008
8167
|
id: slugSchema,
|
|
8009
|
-
agents: listOf(
|
|
8010
|
-
tools: listOf(
|
|
8011
|
-
openapi: listOf(
|
|
8012
|
-
services: listOf(
|
|
8013
|
-
skills: listOf(
|
|
8014
|
-
triggers: listOf(
|
|
8015
|
-
datasetHosts: listOf(
|
|
8016
|
-
mcpServers: listOf(
|
|
8017
|
-
webhooks: listOf(
|
|
8018
|
-
collections: listOf(
|
|
8168
|
+
agents: listOf(MANIFEST_NAME_FIELDS.agents, manifestAgentSchema),
|
|
8169
|
+
tools: listOf(MANIFEST_NAME_FIELDS.tools, manifestToolSchema),
|
|
8170
|
+
openapi: listOf("name", manifestOpenApiSchema),
|
|
8171
|
+
services: listOf(MANIFEST_NAME_FIELDS.services, manifestServiceSchema),
|
|
8172
|
+
skills: listOf(MANIFEST_NAME_FIELDS.skills, manifestSkillSchema),
|
|
8173
|
+
triggers: listOf(MANIFEST_NAME_FIELDS.triggers, manifestTriggerSchema),
|
|
8174
|
+
datasetHosts: listOf(MANIFEST_NAME_FIELDS.datasetHosts, manifestDatasetHostSchema),
|
|
8175
|
+
mcpServers: listOf(MANIFEST_NAME_FIELDS.mcpServers, manifestMcpServerSchema),
|
|
8176
|
+
webhooks: listOf(MANIFEST_NAME_FIELDS.webhooks, manifestWebhookSchema),
|
|
8177
|
+
collections: listOf(MANIFEST_NAME_FIELDS.collections, manifestCollectionSchema)
|
|
8019
8178
|
});
|
|
8020
|
-
var
|
|
8179
|
+
var manifestKindSchema = z4.enum(MANIFEST_KINDS);
|
|
8180
|
+
var namesByKindSchema = z4.record(manifestKindSchema, z4.array(z4.string()));
|
|
8021
8181
|
var manifestChangesSchema = z4.object({
|
|
8022
8182
|
create: namesByKindSchema,
|
|
8023
8183
|
update: namesByKindSchema,
|
|
8024
8184
|
delete: namesByKindSchema
|
|
8025
8185
|
});
|
|
8186
|
+
var manifestConflictSchema = z4.strictObject({
|
|
8187
|
+
kind: manifestKindSchema,
|
|
8188
|
+
name: z4.string(),
|
|
8189
|
+
field: z4.string()
|
|
8190
|
+
});
|
|
8191
|
+
var conflictSideSchema = z4.enum(["live", "manifest"]);
|
|
8192
|
+
var manifestApplyInputSchema = manifestSchema.extend({
|
|
8193
|
+
prefer: conflictSideSchema.optional(),
|
|
8194
|
+
resolutions: z4.array(manifestConflictSchema.extend({ keep: conflictSideSchema })).default([])
|
|
8195
|
+
});
|
|
8196
|
+
var manifestPreviewSchema = manifestChangesSchema.extend({
|
|
8197
|
+
conflicts: z4.array(manifestConflictSchema)
|
|
8198
|
+
});
|
|
8026
8199
|
var appliedManifestSchema = manifestChangesSchema.extend({
|
|
8027
8200
|
triggerSecrets: z4.record(z4.string(), z4.string())
|
|
8028
8201
|
});
|