@runtypelabs/sdk 5.3.1 → 5.5.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/dist/index.cjs +523 -68
- package/dist/index.d.cts +810 -1
- package/dist/index.d.ts +810 -1
- package/dist/index.mjs +498 -68
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -97,14 +97,19 @@ __export(index_exports, {
|
|
|
97
97
|
buildLedgerOffloadReference: () => buildLedgerOffloadReference,
|
|
98
98
|
buildPolicyGuidance: () => buildPolicyGuidance,
|
|
99
99
|
buildSendViewOffloadMarker: () => buildSendViewOffloadMarker,
|
|
100
|
+
calledTool: () => calledTool,
|
|
100
101
|
compileWorkflowConfig: () => compileWorkflowConfig,
|
|
102
|
+
completed: () => completed,
|
|
101
103
|
computeAgentContentHash: () => computeAgentContentHash,
|
|
104
|
+
computeEvalContentHash: () => computeEvalContentHash,
|
|
102
105
|
computeFlowContentHash: () => computeFlowContentHash,
|
|
103
106
|
computeFpoContentHash: () => computeFpoContentHash,
|
|
104
107
|
computeProductContentHash: () => computeProductContentHash,
|
|
105
108
|
computeSkillContentHash: () => computeSkillContentHash,
|
|
106
109
|
computeSurfaceContentHash: () => computeSurfaceContentHash,
|
|
107
110
|
computeToolContentHash: () => computeToolContentHash,
|
|
111
|
+
contains: () => contains,
|
|
112
|
+
cost: () => cost,
|
|
108
113
|
createAgentEventTranslator: () => createAgentEventTranslator,
|
|
109
114
|
createClient: () => createClient,
|
|
110
115
|
createExternalTool: () => createExternalTool,
|
|
@@ -112,6 +117,7 @@ __export(index_exports, {
|
|
|
112
117
|
defaultWorkflow: () => defaultWorkflow,
|
|
113
118
|
defaultWorkflowConfig: () => defaultWorkflowConfig,
|
|
114
119
|
defineAgent: () => defineAgent,
|
|
120
|
+
defineEval: () => defineEval,
|
|
115
121
|
defineFlow: () => defineFlow,
|
|
116
122
|
defineFpo: () => defineFpo,
|
|
117
123
|
definePlaybook: () => definePlaybook,
|
|
@@ -121,6 +127,7 @@ __export(index_exports, {
|
|
|
121
127
|
defineTool: () => defineTool,
|
|
122
128
|
deployWorkflow: () => deployWorkflow,
|
|
123
129
|
ensureDefaultWorkflowHooks: () => ensureDefaultWorkflowHooks,
|
|
130
|
+
ensureEval: () => ensureEval,
|
|
124
131
|
ensureFpo: () => ensureFpo,
|
|
125
132
|
evaluateGeneratedRuntimeToolProposal: () => evaluateGeneratedRuntimeToolProposal,
|
|
126
133
|
extractDeclaredToolResultChars: () => extractDeclaredToolResultChars,
|
|
@@ -133,7 +140,15 @@ __export(index_exports, {
|
|
|
133
140
|
isPreservationSensitiveTask: () => isPreservationSensitiveTask,
|
|
134
141
|
isUnifiedEventType: () => isUnifiedEventType,
|
|
135
142
|
isWorkflowHookRef: () => isWorkflowHookRef,
|
|
143
|
+
jsonField: () => jsonField,
|
|
144
|
+
judge: () => judge,
|
|
145
|
+
judges: () => judges,
|
|
146
|
+
latency: () => latency,
|
|
147
|
+
length: () => length,
|
|
136
148
|
listWorkflowHooks: () => listWorkflowHooks,
|
|
149
|
+
matchesExpected: () => matchesExpected,
|
|
150
|
+
maxToolCalls: () => maxToolCalls,
|
|
151
|
+
noError: () => noError,
|
|
137
152
|
normalizeAgentDefinition: () => normalizeAgentDefinition,
|
|
138
153
|
normalizeCandidatePath: () => normalizeCandidatePath,
|
|
139
154
|
normalizeFpoDefinition: () => normalizeFpoDefinition,
|
|
@@ -141,20 +156,30 @@ __export(index_exports, {
|
|
|
141
156
|
normalizeSkillDefinition: () => normalizeSkillDefinition,
|
|
142
157
|
normalizeSurfaceDefinition: () => normalizeSurfaceDefinition,
|
|
143
158
|
normalizeToolDefinition: () => normalizeToolDefinition,
|
|
159
|
+
notCalledTool: () => notCalledTool,
|
|
160
|
+
notContains: () => notContains,
|
|
144
161
|
parseFinalBuffer: () => parseFinalBuffer,
|
|
145
162
|
parseLedgerArtifactRelativePath: () => parseLedgerArtifactRelativePath,
|
|
146
163
|
parseOffloadedOutputId: () => parseOffloadedOutputId,
|
|
147
164
|
parseSSEChunk: () => parseSSEChunk,
|
|
148
165
|
processStream: () => processStream,
|
|
166
|
+
pullEval: () => pullEval,
|
|
149
167
|
pullFpo: () => pullFpo,
|
|
168
|
+
ranStep: () => ranStep,
|
|
169
|
+
regex: () => regex,
|
|
150
170
|
registerWorkflowHook: () => registerWorkflowHook,
|
|
151
171
|
resolveStallStopAfter: () => resolveStallStopAfter,
|
|
152
172
|
resolveWorkflowHook: () => resolveWorkflowHook,
|
|
173
|
+
runEvalSuite: () => runEvalSuite,
|
|
153
174
|
sanitizeTaskSlug: () => sanitizeTaskSlug,
|
|
154
175
|
shouldInjectEmptySessionNudge: () => shouldInjectEmptySessionNudge,
|
|
155
176
|
shouldRequestModelEscalation: () => shouldRequestModelEscalation,
|
|
177
|
+
stepOrder: () => stepOrder,
|
|
156
178
|
streamEvents: () => streamEvents,
|
|
179
|
+
toolOrder: () => toolOrder,
|
|
157
180
|
unregisterWorkflowHook: () => unregisterWorkflowHook,
|
|
181
|
+
usedNoTools: () => usedNoTools,
|
|
182
|
+
validJson: () => validJson,
|
|
158
183
|
withUnifiedEvents: () => withUnifiedEvents
|
|
159
184
|
});
|
|
160
185
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -3437,6 +3462,368 @@ var BatchesNamespace = class {
|
|
|
3437
3462
|
}
|
|
3438
3463
|
};
|
|
3439
3464
|
|
|
3465
|
+
// src/evals-ensure.ts
|
|
3466
|
+
var CHECK_GRADER_KINDS = /* @__PURE__ */ new Set([
|
|
3467
|
+
"contains",
|
|
3468
|
+
"not_contains",
|
|
3469
|
+
"matches_expected",
|
|
3470
|
+
"regex",
|
|
3471
|
+
"valid_json",
|
|
3472
|
+
"json_field",
|
|
3473
|
+
"length",
|
|
3474
|
+
"latency",
|
|
3475
|
+
"no_error",
|
|
3476
|
+
// Trace checks.
|
|
3477
|
+
"called_tool",
|
|
3478
|
+
"not_called_tool",
|
|
3479
|
+
"used_no_tools",
|
|
3480
|
+
"max_tool_calls",
|
|
3481
|
+
"tool_order",
|
|
3482
|
+
"ran_step",
|
|
3483
|
+
"step_order",
|
|
3484
|
+
"completed",
|
|
3485
|
+
"cost"
|
|
3486
|
+
]);
|
|
3487
|
+
function contains(value, opts) {
|
|
3488
|
+
return { kind: "contains", value, ...opts?.caseSensitive ? { caseSensitive: true } : {} };
|
|
3489
|
+
}
|
|
3490
|
+
function notContains(value, opts) {
|
|
3491
|
+
return { kind: "not_contains", value, ...opts?.caseSensitive ? { caseSensitive: true } : {} };
|
|
3492
|
+
}
|
|
3493
|
+
function matchesExpected() {
|
|
3494
|
+
return { kind: "matches_expected" };
|
|
3495
|
+
}
|
|
3496
|
+
function regex(pattern, flags) {
|
|
3497
|
+
return { kind: "regex", pattern, ...flags ? { flags } : {} };
|
|
3498
|
+
}
|
|
3499
|
+
function validJson() {
|
|
3500
|
+
return { kind: "valid_json" };
|
|
3501
|
+
}
|
|
3502
|
+
function jsonField(path, opts) {
|
|
3503
|
+
return {
|
|
3504
|
+
kind: "json_field",
|
|
3505
|
+
path,
|
|
3506
|
+
...opts && "equals" in opts && opts.equals !== void 0 ? { equals: opts.equals } : {},
|
|
3507
|
+
...opts && typeof opts.exists === "boolean" ? { exists: opts.exists } : {}
|
|
3508
|
+
};
|
|
3509
|
+
}
|
|
3510
|
+
function length(opts) {
|
|
3511
|
+
if (!opts || opts.minChars === void 0 && opts.maxChars === void 0) {
|
|
3512
|
+
throw new Error("length() requires at least one of minChars or maxChars");
|
|
3513
|
+
}
|
|
3514
|
+
return {
|
|
3515
|
+
kind: "length",
|
|
3516
|
+
...opts.minChars !== void 0 ? { minChars: opts.minChars } : {},
|
|
3517
|
+
...opts.maxChars !== void 0 ? { maxChars: opts.maxChars } : {}
|
|
3518
|
+
};
|
|
3519
|
+
}
|
|
3520
|
+
function latency(maxMs) {
|
|
3521
|
+
if (!Number.isFinite(maxMs) || maxMs <= 0) {
|
|
3522
|
+
throw new Error("latency() requires a positive maxMs");
|
|
3523
|
+
}
|
|
3524
|
+
return { kind: "latency", maxMs };
|
|
3525
|
+
}
|
|
3526
|
+
function noError() {
|
|
3527
|
+
return { kind: "no_error" };
|
|
3528
|
+
}
|
|
3529
|
+
function calledTool(name, opts) {
|
|
3530
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
3531
|
+
throw new Error("calledTool() requires a non-empty tool name");
|
|
3532
|
+
}
|
|
3533
|
+
if (opts?.times !== void 0 && (!Number.isInteger(opts.times) || opts.times <= 0)) {
|
|
3534
|
+
throw new Error('calledTool() "times" must be a positive integer');
|
|
3535
|
+
}
|
|
3536
|
+
return {
|
|
3537
|
+
kind: "called_tool",
|
|
3538
|
+
name,
|
|
3539
|
+
...opts && "input" in opts && opts.input !== void 0 ? { input: opts.input } : {},
|
|
3540
|
+
...opts && "output" in opts && opts.output !== void 0 ? { output: opts.output } : {},
|
|
3541
|
+
...opts && typeof opts.isError === "boolean" ? { isError: opts.isError } : {},
|
|
3542
|
+
...opts?.times !== void 0 ? { times: opts.times } : {}
|
|
3543
|
+
};
|
|
3544
|
+
}
|
|
3545
|
+
function notCalledTool(name) {
|
|
3546
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
3547
|
+
throw new Error("notCalledTool() requires a non-empty tool name");
|
|
3548
|
+
}
|
|
3549
|
+
return { kind: "not_called_tool", name };
|
|
3550
|
+
}
|
|
3551
|
+
function usedNoTools() {
|
|
3552
|
+
return { kind: "used_no_tools" };
|
|
3553
|
+
}
|
|
3554
|
+
function maxToolCalls(max) {
|
|
3555
|
+
if (!Number.isInteger(max) || max < 0) {
|
|
3556
|
+
throw new Error("maxToolCalls() requires a non-negative integer");
|
|
3557
|
+
}
|
|
3558
|
+
return { kind: "max_tool_calls", max };
|
|
3559
|
+
}
|
|
3560
|
+
function toolOrder(tools) {
|
|
3561
|
+
if (!Array.isArray(tools) || tools.length === 0) {
|
|
3562
|
+
throw new Error("toolOrder() requires a non-empty array of tool names");
|
|
3563
|
+
}
|
|
3564
|
+
return { kind: "tool_order", tools };
|
|
3565
|
+
}
|
|
3566
|
+
function ranStep(name) {
|
|
3567
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
3568
|
+
throw new Error("ranStep() requires a non-empty step name");
|
|
3569
|
+
}
|
|
3570
|
+
return { kind: "ran_step", name };
|
|
3571
|
+
}
|
|
3572
|
+
function stepOrder(steps) {
|
|
3573
|
+
if (!Array.isArray(steps) || steps.length === 0) {
|
|
3574
|
+
throw new Error("stepOrder() requires a non-empty array of step names");
|
|
3575
|
+
}
|
|
3576
|
+
return { kind: "step_order", steps };
|
|
3577
|
+
}
|
|
3578
|
+
function completed() {
|
|
3579
|
+
return { kind: "completed" };
|
|
3580
|
+
}
|
|
3581
|
+
function cost(maxUsd) {
|
|
3582
|
+
if (!Number.isFinite(maxUsd) || maxUsd <= 0) {
|
|
3583
|
+
throw new Error("cost() requires a positive maxUsd");
|
|
3584
|
+
}
|
|
3585
|
+
return { kind: "cost", maxUsd };
|
|
3586
|
+
}
|
|
3587
|
+
function judge(criteria, opts) {
|
|
3588
|
+
if (typeof criteria !== "string" || criteria.trim().length === 0) {
|
|
3589
|
+
throw new Error("judge() requires non-empty criteria");
|
|
3590
|
+
}
|
|
3591
|
+
return {
|
|
3592
|
+
kind: "ai",
|
|
3593
|
+
criteria,
|
|
3594
|
+
...opts?.preset ? { preset: opts.preset } : {},
|
|
3595
|
+
...opts?.useExpected ? { useExpected: true } : {},
|
|
3596
|
+
...opts?.model ? { model: opts.model } : {},
|
|
3597
|
+
...opts?.threshold !== void 0 ? { threshold: opts.threshold } : {}
|
|
3598
|
+
};
|
|
3599
|
+
}
|
|
3600
|
+
var judges = {
|
|
3601
|
+
answersQuestion: () => judge(
|
|
3602
|
+
"The response directly addresses what the user asked, without dodging or answering a different question.",
|
|
3603
|
+
{ preset: "answersQuestion" }
|
|
3604
|
+
),
|
|
3605
|
+
matchesExpected: () => judge(
|
|
3606
|
+
"The response conveys the same facts and conclusion as the expected answer. Wording may differ.",
|
|
3607
|
+
{ preset: "matchesExpected", useExpected: true }
|
|
3608
|
+
),
|
|
3609
|
+
followsInstructions: () => judge(
|
|
3610
|
+
"The response obeys every instruction in the system prompt (format, tone, constraints, refusals).",
|
|
3611
|
+
{ preset: "followsInstructions" }
|
|
3612
|
+
),
|
|
3613
|
+
grounded: () => judge(
|
|
3614
|
+
"Every factual claim in the response is supported by the provided context or the expected answer. Flag anything invented.",
|
|
3615
|
+
{ preset: "grounded" }
|
|
3616
|
+
),
|
|
3617
|
+
rightTone: (voice = "{describe the voice you want}") => judge(`The response matches this voice: ${voice}.`, { preset: "rightTone" }),
|
|
3618
|
+
safeToSend: () => judge(
|
|
3619
|
+
"The response contains nothing embarrassing to show a customer: no leaked internals, no hostile tone, no policy violations.",
|
|
3620
|
+
{ preset: "safeToSend" }
|
|
3621
|
+
)
|
|
3622
|
+
};
|
|
3623
|
+
var DEFINE_EVAL_TOP_LEVEL_KEYS = /* @__PURE__ */ new Set([
|
|
3624
|
+
"name",
|
|
3625
|
+
"target",
|
|
3626
|
+
"graders",
|
|
3627
|
+
"cases",
|
|
3628
|
+
"virtual"
|
|
3629
|
+
]);
|
|
3630
|
+
var DEFINE_EVAL_CASE_KEYS = /* @__PURE__ */ new Set(["name", "input", "expected", "expect"]);
|
|
3631
|
+
function isPlainObject2(value) {
|
|
3632
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3633
|
+
}
|
|
3634
|
+
function normalizeTarget(target) {
|
|
3635
|
+
if (!isPlainObject2(target)) {
|
|
3636
|
+
throw new Error('defineEval requires a "target" object: { flow: name } or { agent: name }');
|
|
3637
|
+
}
|
|
3638
|
+
const hasFlow = typeof target.flow === "string" && target.flow.length > 0;
|
|
3639
|
+
const hasAgent = typeof target.agent === "string" && target.agent.length > 0;
|
|
3640
|
+
if (hasFlow === hasAgent) {
|
|
3641
|
+
throw new Error(
|
|
3642
|
+
'defineEval "target" must name exactly one of flow or agent: { flow: "name" } XOR { agent: "name" }'
|
|
3643
|
+
);
|
|
3644
|
+
}
|
|
3645
|
+
const extraKeys = Object.keys(target).filter((k) => k !== "flow" && k !== "agent");
|
|
3646
|
+
if (extraKeys.length > 0) {
|
|
3647
|
+
throw new Error(`defineEval "target" has unknown field(s): ${extraKeys.join(", ")}`);
|
|
3648
|
+
}
|
|
3649
|
+
return hasFlow ? { flow: target.flow } : { agent: target.agent };
|
|
3650
|
+
}
|
|
3651
|
+
function validateGrader(grader, where) {
|
|
3652
|
+
if (!isPlainObject2(grader) || typeof grader.kind !== "string") {
|
|
3653
|
+
throw new Error(`defineEval: ${where} must be a grader object with a string "kind"`);
|
|
3654
|
+
}
|
|
3655
|
+
if (grader.kind === "ai") {
|
|
3656
|
+
if (typeof grader.criteria !== "string" || grader.criteria.trim().length === 0) {
|
|
3657
|
+
throw new Error(`defineEval: ${where} is an AI grader and requires non-empty "criteria"`);
|
|
3658
|
+
}
|
|
3659
|
+
return grader;
|
|
3660
|
+
}
|
|
3661
|
+
if (!CHECK_GRADER_KINDS.has(grader.kind)) {
|
|
3662
|
+
throw new Error(
|
|
3663
|
+
`defineEval: ${where} has unknown grader kind "${grader.kind}". Known kinds: ${[...CHECK_GRADER_KINDS].join(", ")}, ai.`
|
|
3664
|
+
);
|
|
3665
|
+
}
|
|
3666
|
+
return grader;
|
|
3667
|
+
}
|
|
3668
|
+
function normalizeCaseInput(input, where) {
|
|
3669
|
+
if (input === void 0) return {};
|
|
3670
|
+
if (!isPlainObject2(input)) {
|
|
3671
|
+
throw new Error(`defineEval: ${where} "input" must be an object`);
|
|
3672
|
+
}
|
|
3673
|
+
const out = {};
|
|
3674
|
+
if (input.variables !== void 0) {
|
|
3675
|
+
if (!isPlainObject2(input.variables)) {
|
|
3676
|
+
throw new Error(`defineEval: ${where} "input.variables" must be an object`);
|
|
3677
|
+
}
|
|
3678
|
+
out.variables = input.variables;
|
|
3679
|
+
}
|
|
3680
|
+
if (input.messages !== void 0) {
|
|
3681
|
+
if (!Array.isArray(input.messages)) {
|
|
3682
|
+
throw new Error(`defineEval: ${where} "input.messages" must be an array`);
|
|
3683
|
+
}
|
|
3684
|
+
out.messages = input.messages.map((m, i) => {
|
|
3685
|
+
if (!isPlainObject2(m) || typeof m.role !== "string" || typeof m.content !== "string") {
|
|
3686
|
+
throw new Error(`defineEval: ${where} "input.messages[${i}]" must be { role, content }`);
|
|
3687
|
+
}
|
|
3688
|
+
return { role: m.role, content: m.content };
|
|
3689
|
+
});
|
|
3690
|
+
}
|
|
3691
|
+
return out;
|
|
3692
|
+
}
|
|
3693
|
+
function defineEval(input) {
|
|
3694
|
+
if (!input || typeof input !== "object") {
|
|
3695
|
+
throw new Error("defineEval requires a definition object");
|
|
3696
|
+
}
|
|
3697
|
+
const unknownKeys = Object.keys(input).filter((k) => !DEFINE_EVAL_TOP_LEVEL_KEYS.has(k));
|
|
3698
|
+
if (unknownKeys.length > 0) {
|
|
3699
|
+
throw new Error(
|
|
3700
|
+
`defineEval: unknown field(s): ${unknownKeys.join(", ")}. Allowed fields are target, graders, cases, virtual.`
|
|
3701
|
+
);
|
|
3702
|
+
}
|
|
3703
|
+
const target = normalizeTarget(input.target);
|
|
3704
|
+
if (input.name !== void 0 && (typeof input.name !== "string" || input.name.length === 0)) {
|
|
3705
|
+
throw new Error('defineEval "name" must be a non-empty string when provided');
|
|
3706
|
+
}
|
|
3707
|
+
const name = input.name ?? ("flow" in target ? `flow:${target.flow}` : `agent:${target.agent}`);
|
|
3708
|
+
const suiteGraders = (input.graders ?? []).map((g, i) => validateGrader(g, `graders[${i}]`));
|
|
3709
|
+
if (!Array.isArray(input.cases) || input.cases.length === 0) {
|
|
3710
|
+
throw new Error('defineEval requires a non-empty "cases" array');
|
|
3711
|
+
}
|
|
3712
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
3713
|
+
const cases = input.cases.map((c, index) => {
|
|
3714
|
+
if (!isPlainObject2(c)) {
|
|
3715
|
+
throw new Error(`defineEval: cases[${index}] must be an object`);
|
|
3716
|
+
}
|
|
3717
|
+
if (typeof c.name !== "string" || c.name.length === 0) {
|
|
3718
|
+
throw new Error(`defineEval: cases[${index}] requires a non-empty string "name"`);
|
|
3719
|
+
}
|
|
3720
|
+
if (seenNames.has(c.name)) {
|
|
3721
|
+
throw new Error(`defineEval: duplicate case name "${c.name}" (case names are the identity)`);
|
|
3722
|
+
}
|
|
3723
|
+
seenNames.add(c.name);
|
|
3724
|
+
const unknownCaseKeys = Object.keys(c).filter((k) => !DEFINE_EVAL_CASE_KEYS.has(k));
|
|
3725
|
+
if (unknownCaseKeys.length > 0) {
|
|
3726
|
+
throw new Error(
|
|
3727
|
+
`defineEval: cases[${index}] ("${c.name}") has unknown field(s): ${unknownCaseKeys.join(
|
|
3728
|
+
", "
|
|
3729
|
+
)}. Allowed case fields are name, input, expected, expect.`
|
|
3730
|
+
);
|
|
3731
|
+
}
|
|
3732
|
+
const caseGraders = (c.expect ?? []).map(
|
|
3733
|
+
(g, i) => validateGrader(g, `cases[${index}].expect[${i}]`)
|
|
3734
|
+
);
|
|
3735
|
+
const expect = [...suiteGraders, ...caseGraders];
|
|
3736
|
+
if (expect.length === 0) {
|
|
3737
|
+
throw new Error(
|
|
3738
|
+
`defineEval: cases[${index}] ("${c.name}") has no graders. Add suite-level "graders" or case-level "expect" so there is something to score.`
|
|
3739
|
+
);
|
|
3740
|
+
}
|
|
3741
|
+
if (c.expected !== void 0 && !isPlainObject2(c.expected)) {
|
|
3742
|
+
throw new Error(`defineEval: cases[${index}] ("${c.name}") "expected" must be an object`);
|
|
3743
|
+
}
|
|
3744
|
+
return {
|
|
3745
|
+
name: c.name,
|
|
3746
|
+
input: normalizeCaseInput(c.input, `cases[${index}] ("${c.name}")`),
|
|
3747
|
+
...c.expected !== void 0 ? { expected: c.expected } : {},
|
|
3748
|
+
expect
|
|
3749
|
+
};
|
|
3750
|
+
});
|
|
3751
|
+
return { name, target, cases, virtual: input.virtual === true };
|
|
3752
|
+
}
|
|
3753
|
+
function normalizeForHash(value) {
|
|
3754
|
+
if (Array.isArray(value)) return value.map(normalizeForHash);
|
|
3755
|
+
if (isPlainObject2(value)) {
|
|
3756
|
+
const out = {};
|
|
3757
|
+
for (const key of Object.keys(value).sort()) {
|
|
3758
|
+
const v = value[key];
|
|
3759
|
+
if (v === void 0) continue;
|
|
3760
|
+
out[key] = normalizeForHash(v);
|
|
3761
|
+
}
|
|
3762
|
+
return out;
|
|
3763
|
+
}
|
|
3764
|
+
return value;
|
|
3765
|
+
}
|
|
3766
|
+
async function computeEvalContentHash(definition) {
|
|
3767
|
+
const canonical = {
|
|
3768
|
+
target: normalizeForHash(definition.target),
|
|
3769
|
+
virtual: definition.virtual,
|
|
3770
|
+
cases: [...definition.cases].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0).map((c) => ({
|
|
3771
|
+
name: c.name,
|
|
3772
|
+
input: normalizeForHash(c.input),
|
|
3773
|
+
...c.expected !== void 0 ? { expected: normalizeForHash(c.expected) } : {},
|
|
3774
|
+
// Grader order preserved on purpose (it maps to the result index).
|
|
3775
|
+
expect: c.expect.map((g) => normalizeForHash(g))
|
|
3776
|
+
}))
|
|
3777
|
+
};
|
|
3778
|
+
const serialized = JSON.stringify(canonical);
|
|
3779
|
+
const encoded = new TextEncoder().encode(serialized);
|
|
3780
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", encoded);
|
|
3781
|
+
return Array.from(new Uint8Array(hashBuffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3782
|
+
}
|
|
3783
|
+
var serverHashMemo2 = /* @__PURE__ */ new WeakMap();
|
|
3784
|
+
function memoFor2(client) {
|
|
3785
|
+
let memo = serverHashMemo2.get(client);
|
|
3786
|
+
if (!memo) {
|
|
3787
|
+
memo = /* @__PURE__ */ new Map();
|
|
3788
|
+
serverHashMemo2.set(client, memo);
|
|
3789
|
+
}
|
|
3790
|
+
return memo;
|
|
3791
|
+
}
|
|
3792
|
+
async function ensureEval(client, definition) {
|
|
3793
|
+
if (definition.virtual) {
|
|
3794
|
+
throw new Error(
|
|
3795
|
+
"Cannot ensure a virtual eval: virtual evals are ephemeral (nothing is persisted to converge). Remove `virtual: true` to converge a durable suite, or run it directly."
|
|
3796
|
+
);
|
|
3797
|
+
}
|
|
3798
|
+
const memo = memoFor2(client);
|
|
3799
|
+
const localHash = await computeEvalContentHash(definition);
|
|
3800
|
+
const memoKey = `${definition.name} ${localHash}`;
|
|
3801
|
+
const contentHash = memo.get(memoKey) ?? localHash;
|
|
3802
|
+
const probe = await client.post(
|
|
3803
|
+
"/eval/ensure",
|
|
3804
|
+
{ name: definition.name, contentHash }
|
|
3805
|
+
);
|
|
3806
|
+
if (probe.result !== "definitionRequired") {
|
|
3807
|
+
memo.set(memoKey, probe.contentHash);
|
|
3808
|
+
return probe;
|
|
3809
|
+
}
|
|
3810
|
+
const converged = await client.post(
|
|
3811
|
+
"/eval/ensure",
|
|
3812
|
+
{ name: definition.name, definition }
|
|
3813
|
+
);
|
|
3814
|
+
if (converged.result === "definitionRequired") {
|
|
3815
|
+
throw new Error("Server reported definitionRequired for a full-definition request");
|
|
3816
|
+
}
|
|
3817
|
+
memo.set(memoKey, converged.contentHash);
|
|
3818
|
+
return converged;
|
|
3819
|
+
}
|
|
3820
|
+
async function pullEval(client, name) {
|
|
3821
|
+
return client.get("/eval/pull", { name });
|
|
3822
|
+
}
|
|
3823
|
+
async function runEvalSuite(client, input) {
|
|
3824
|
+
return client.post("/eval/run", input);
|
|
3825
|
+
}
|
|
3826
|
+
|
|
3440
3827
|
// src/evals-namespace.ts
|
|
3441
3828
|
var EvalRunner = class {
|
|
3442
3829
|
constructor(getClient, config) {
|
|
@@ -3581,6 +3968,49 @@ var EvalsNamespace = class {
|
|
|
3581
3968
|
run(config) {
|
|
3582
3969
|
return new EvalRunner(this.getClient, config);
|
|
3583
3970
|
}
|
|
3971
|
+
/**
|
|
3972
|
+
* Idempotently converge a `defineEval` suite definition onto the platform —
|
|
3973
|
+
* the deploy-time, non-executing converge for code-colocated evals. Hash-first:
|
|
3974
|
+
* the steady state is one tiny probe request. Upserts the eval suite + replaces
|
|
3975
|
+
* its cases; never runs the eval.
|
|
3976
|
+
*
|
|
3977
|
+
* @example
|
|
3978
|
+
* ```typescript
|
|
3979
|
+
* const suite = defineEval({
|
|
3980
|
+
* target: { flow: 'support-triage' },
|
|
3981
|
+
* graders: [noError()],
|
|
3982
|
+
* cases: [{ name: 'billing', input: { variables: { message: 'I was double charged' } }, expect: [contains('finance')] }],
|
|
3983
|
+
* })
|
|
3984
|
+
* const result = await Runtype.evals.ensure(suite)
|
|
3985
|
+
* ```
|
|
3986
|
+
*/
|
|
3987
|
+
async ensure(definition) {
|
|
3988
|
+
return ensureEval(this.getClient(), definition);
|
|
3989
|
+
}
|
|
3990
|
+
/**
|
|
3991
|
+
* Pull the canonical definition + provenance for an eval suite by name — the
|
|
3992
|
+
* absorb-drift direction of the ensure protocol.
|
|
3993
|
+
*/
|
|
3994
|
+
async pull(name) {
|
|
3995
|
+
return pullEval(this.getClient(), name);
|
|
3996
|
+
}
|
|
3997
|
+
/**
|
|
3998
|
+
* Run an eval suite synchronously and return the suite score + per-case grader
|
|
3999
|
+
* outcomes — the executing counterpart of `ensure`, powering the `runtype
|
|
4000
|
+
* eval` CI gate. Run a saved suite by id (`{ suiteId }`, the post-`ensure`
|
|
4001
|
+
* path) or an inline definition without persisting (`{ definition }`, the
|
|
4002
|
+
* virtual path).
|
|
4003
|
+
*
|
|
4004
|
+
* @example
|
|
4005
|
+
* ```typescript
|
|
4006
|
+
* const { suiteId } = await Runtype.evals.ensure(suite)
|
|
4007
|
+
* const result = await Runtype.evals.runSuite({ suiteId })
|
|
4008
|
+
* if (!result.passed) process.exit(1)
|
|
4009
|
+
* ```
|
|
4010
|
+
*/
|
|
4011
|
+
async runSuite(input) {
|
|
4012
|
+
return runEvalSuite(this.getClient(), input);
|
|
4013
|
+
}
|
|
3584
4014
|
/**
|
|
3585
4015
|
* Get evaluation status by ID
|
|
3586
4016
|
*
|
|
@@ -3699,14 +4129,14 @@ var PromptsNamespace = class {
|
|
|
3699
4129
|
};
|
|
3700
4130
|
|
|
3701
4131
|
// src/skills-ensure.ts
|
|
3702
|
-
function
|
|
4132
|
+
function isPlainObject3(value) {
|
|
3703
4133
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3704
4134
|
}
|
|
3705
4135
|
function normalizeValue(value) {
|
|
3706
4136
|
if (Array.isArray(value)) {
|
|
3707
4137
|
return value.map((item) => normalizeValue(item));
|
|
3708
4138
|
}
|
|
3709
|
-
if (
|
|
4139
|
+
if (isPlainObject3(value)) {
|
|
3710
4140
|
const normalized = {};
|
|
3711
4141
|
for (const key of Object.keys(value).sort()) {
|
|
3712
4142
|
const entry = value[key];
|
|
@@ -3718,15 +4148,15 @@ function normalizeValue(value) {
|
|
|
3718
4148
|
return value;
|
|
3719
4149
|
}
|
|
3720
4150
|
function normalizeSkillDefinition(definition) {
|
|
3721
|
-
const manifest =
|
|
3722
|
-
const rawFrontmatter =
|
|
4151
|
+
const manifest = isPlainObject3(definition.manifest) ? definition.manifest : {};
|
|
4152
|
+
const rawFrontmatter = isPlainObject3(manifest.frontmatter) ? manifest.frontmatter : {};
|
|
3723
4153
|
const frontmatterWithoutName = {};
|
|
3724
4154
|
for (const key of Object.keys(rawFrontmatter)) {
|
|
3725
4155
|
if (key === "name") continue;
|
|
3726
4156
|
frontmatterWithoutName[key] = rawFrontmatter[key];
|
|
3727
4157
|
}
|
|
3728
4158
|
const frontmatter = normalizeValue(frontmatterWithoutName);
|
|
3729
|
-
const runtype =
|
|
4159
|
+
const runtype = isPlainObject3(manifest.runtype) ? normalizeValue(manifest.runtype) : {};
|
|
3730
4160
|
const body = typeof manifest.body === "string" ? manifest.body : "";
|
|
3731
4161
|
return { frontmatter, runtype, body };
|
|
3732
4162
|
}
|
|
@@ -3744,7 +4174,7 @@ function defineSkill(input) {
|
|
|
3744
4174
|
if (typeof input.name !== "string" || input.name.length === 0) {
|
|
3745
4175
|
throw new Error('defineSkill requires a non-empty string "name"');
|
|
3746
4176
|
}
|
|
3747
|
-
if (!
|
|
4177
|
+
if (!isPlainObject3(input.manifest)) {
|
|
3748
4178
|
throw new Error('defineSkill requires a "manifest" object ({ frontmatter, runtype, body })');
|
|
3749
4179
|
}
|
|
3750
4180
|
const unknownKeys = Object.keys(input).filter((key) => !DEFINE_SKILL_TOP_LEVEL_KEYS.has(key));
|
|
@@ -3754,7 +4184,7 @@ function defineSkill(input) {
|
|
|
3754
4184
|
);
|
|
3755
4185
|
}
|
|
3756
4186
|
const frontmatter = input.manifest.frontmatter;
|
|
3757
|
-
if (!
|
|
4187
|
+
if (!isPlainObject3(frontmatter) || typeof frontmatter.name !== "string") {
|
|
3758
4188
|
throw new Error("defineSkill: manifest.frontmatter.name is required");
|
|
3759
4189
|
}
|
|
3760
4190
|
if (frontmatter.name !== input.name) {
|
|
@@ -3795,19 +4225,19 @@ function parseRequestError2(err) {
|
|
|
3795
4225
|
}
|
|
3796
4226
|
function toConflictError2(err) {
|
|
3797
4227
|
const { status, body } = parseRequestError2(err);
|
|
3798
|
-
if (status !== 409 || !
|
|
4228
|
+
if (status !== 409 || !isPlainObject3(body)) return null;
|
|
3799
4229
|
const code = body.code;
|
|
3800
4230
|
if (code !== "external_modification" && code !== "remote_changed") return null;
|
|
3801
4231
|
return new SkillEnsureConflictError(
|
|
3802
4232
|
body
|
|
3803
4233
|
);
|
|
3804
4234
|
}
|
|
3805
|
-
var
|
|
3806
|
-
function
|
|
3807
|
-
let memo =
|
|
4235
|
+
var serverHashMemo3 = /* @__PURE__ */ new WeakMap();
|
|
4236
|
+
function memoFor3(client) {
|
|
4237
|
+
let memo = serverHashMemo3.get(client);
|
|
3808
4238
|
if (!memo) {
|
|
3809
4239
|
memo = /* @__PURE__ */ new Map();
|
|
3810
|
-
|
|
4240
|
+
serverHashMemo3.set(client, memo);
|
|
3811
4241
|
}
|
|
3812
4242
|
return memo;
|
|
3813
4243
|
}
|
|
@@ -3848,7 +4278,7 @@ async function ensureSkill(client, definition, options = {}) {
|
|
|
3848
4278
|
}
|
|
3849
4279
|
return plan;
|
|
3850
4280
|
}
|
|
3851
|
-
const memo =
|
|
4281
|
+
const memo = memoFor3(client);
|
|
3852
4282
|
const localHash = await computeSkillContentHash(definition);
|
|
3853
4283
|
const memoKey = `${definition.name} ${localHash}`;
|
|
3854
4284
|
const contentHash = memo.get(memoKey) ?? localHash;
|
|
@@ -4143,14 +4573,14 @@ var AGENT_CONFIG_KEYS = [
|
|
|
4143
4573
|
"tenancyStrategy"
|
|
4144
4574
|
];
|
|
4145
4575
|
var AGENT_CONFIG_KEY_LIST = [...AGENT_CONFIG_KEYS].sort();
|
|
4146
|
-
function
|
|
4576
|
+
function isPlainObject4(value) {
|
|
4147
4577
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4148
4578
|
}
|
|
4149
4579
|
function normalizeValue2(value) {
|
|
4150
4580
|
if (Array.isArray(value)) {
|
|
4151
4581
|
return value.map((item) => normalizeValue2(item));
|
|
4152
4582
|
}
|
|
4153
|
-
if (
|
|
4583
|
+
if (isPlainObject4(value)) {
|
|
4154
4584
|
const normalized = {};
|
|
4155
4585
|
for (const key of Object.keys(value).sort()) {
|
|
4156
4586
|
const entry = value[key];
|
|
@@ -4163,7 +4593,7 @@ function normalizeValue2(value) {
|
|
|
4163
4593
|
}
|
|
4164
4594
|
function normalizeAgentDefinition(definition) {
|
|
4165
4595
|
const config = {};
|
|
4166
|
-
const rawConfig =
|
|
4596
|
+
const rawConfig = isPlainObject4(definition.config) ? definition.config : {};
|
|
4167
4597
|
for (const key of AGENT_CONFIG_KEY_LIST) {
|
|
4168
4598
|
const value = rawConfig[key];
|
|
4169
4599
|
if (value === void 0 || value === null) continue;
|
|
@@ -4185,7 +4615,7 @@ async function computeAgentContentHash(definition) {
|
|
|
4185
4615
|
var DEFINE_TOP_LEVEL_KEYS = /* @__PURE__ */ new Set(["name", "description", "icon", ...AGENT_CONFIG_KEYS]);
|
|
4186
4616
|
function collectNonPortableToolRefs(config) {
|
|
4187
4617
|
const tools = config.tools;
|
|
4188
|
-
if (!
|
|
4618
|
+
if (!isPlainObject4(tools)) return [];
|
|
4189
4619
|
const found = [];
|
|
4190
4620
|
const isAccountScoped = (ref) => typeof ref === "string" && ref.startsWith("tool_");
|
|
4191
4621
|
const scanArray = (value, path) => {
|
|
@@ -4195,7 +4625,7 @@ function collectNonPortableToolRefs(config) {
|
|
|
4195
4625
|
});
|
|
4196
4626
|
};
|
|
4197
4627
|
const scanKeys = (value, path) => {
|
|
4198
|
-
if (!
|
|
4628
|
+
if (!isPlainObject4(value)) return;
|
|
4199
4629
|
for (const key of Object.keys(value)) {
|
|
4200
4630
|
if (isAccountScoped(key)) found.push(`${path}.${key}`);
|
|
4201
4631
|
}
|
|
@@ -4203,16 +4633,16 @@ function collectNonPortableToolRefs(config) {
|
|
|
4203
4633
|
scanArray(tools.toolIds, "tools.toolIds");
|
|
4204
4634
|
scanKeys(tools.toolConfigs, "tools.toolConfigs");
|
|
4205
4635
|
scanKeys(tools.perToolLimits, "tools.perToolLimits");
|
|
4206
|
-
if (
|
|
4207
|
-
if (
|
|
4636
|
+
if (isPlainObject4(tools.approval)) scanArray(tools.approval.require, "tools.approval.require");
|
|
4637
|
+
if (isPlainObject4(tools.subagentConfig)) {
|
|
4208
4638
|
scanArray(tools.subagentConfig.toolPool, "tools.subagentConfig.toolPool");
|
|
4209
4639
|
}
|
|
4210
|
-
if (
|
|
4640
|
+
if (isPlainObject4(tools.codeModeConfig)) {
|
|
4211
4641
|
scanArray(tools.codeModeConfig.toolPool, "tools.codeModeConfig.toolPool");
|
|
4212
4642
|
}
|
|
4213
4643
|
if (Array.isArray(tools.runtimeTools)) {
|
|
4214
4644
|
tools.runtimeTools.forEach((runtimeTool, i) => {
|
|
4215
|
-
if (!
|
|
4645
|
+
if (!isPlainObject4(runtimeTool) || !isPlainObject4(runtimeTool.config)) return;
|
|
4216
4646
|
const base = `tools.runtimeTools[${i}].config`;
|
|
4217
4647
|
const rtConfig = runtimeTool.config;
|
|
4218
4648
|
if (runtimeTool.toolType === "subagent" && typeof rtConfig.agentId === "string" && rtConfig.agentId.startsWith("agent_")) {
|
|
@@ -4286,19 +4716,19 @@ function parseRequestError3(err) {
|
|
|
4286
4716
|
}
|
|
4287
4717
|
function toConflictError3(err) {
|
|
4288
4718
|
const { status, body } = parseRequestError3(err);
|
|
4289
|
-
if (status !== 409 || !
|
|
4719
|
+
if (status !== 409 || !isPlainObject4(body)) return null;
|
|
4290
4720
|
const code = body.code;
|
|
4291
4721
|
if (code !== "external_modification" && code !== "remote_changed") return null;
|
|
4292
4722
|
return new AgentEnsureConflictError(
|
|
4293
4723
|
body
|
|
4294
4724
|
);
|
|
4295
4725
|
}
|
|
4296
|
-
var
|
|
4297
|
-
function
|
|
4298
|
-
let memo =
|
|
4726
|
+
var serverHashMemo4 = /* @__PURE__ */ new WeakMap();
|
|
4727
|
+
function memoFor4(client) {
|
|
4728
|
+
let memo = serverHashMemo4.get(client);
|
|
4299
4729
|
if (!memo) {
|
|
4300
4730
|
memo = /* @__PURE__ */ new Map();
|
|
4301
|
-
|
|
4731
|
+
serverHashMemo4.set(client, memo);
|
|
4302
4732
|
}
|
|
4303
4733
|
return memo;
|
|
4304
4734
|
}
|
|
@@ -4335,7 +4765,7 @@ var AgentsNamespace = class {
|
|
|
4335
4765
|
}
|
|
4336
4766
|
return plan;
|
|
4337
4767
|
}
|
|
4338
|
-
const memo =
|
|
4768
|
+
const memo = memoFor4(client);
|
|
4339
4769
|
const localHash = await computeAgentContentHash({
|
|
4340
4770
|
...definition,
|
|
4341
4771
|
config: definition.config
|
|
@@ -4388,14 +4818,14 @@ var AgentsNamespace = class {
|
|
|
4388
4818
|
};
|
|
4389
4819
|
|
|
4390
4820
|
// src/tools-ensure.ts
|
|
4391
|
-
function
|
|
4821
|
+
function isPlainObject5(value) {
|
|
4392
4822
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4393
4823
|
}
|
|
4394
4824
|
function normalizeValue3(value) {
|
|
4395
4825
|
if (Array.isArray(value)) {
|
|
4396
4826
|
return value.map((item) => normalizeValue3(item));
|
|
4397
4827
|
}
|
|
4398
|
-
if (
|
|
4828
|
+
if (isPlainObject5(value)) {
|
|
4399
4829
|
const normalized = {};
|
|
4400
4830
|
for (const key of Object.keys(value).sort()) {
|
|
4401
4831
|
const entry = value[key];
|
|
@@ -4407,8 +4837,8 @@ function normalizeValue3(value) {
|
|
|
4407
4837
|
return value;
|
|
4408
4838
|
}
|
|
4409
4839
|
function normalizeToolDefinition(definition) {
|
|
4410
|
-
const parametersSchema =
|
|
4411
|
-
const config =
|
|
4840
|
+
const parametersSchema = isPlainObject5(definition.parametersSchema) ? normalizeValue3(definition.parametersSchema) : {};
|
|
4841
|
+
const config = isPlainObject5(definition.config) ? normalizeValue3(definition.config) : {};
|
|
4412
4842
|
return {
|
|
4413
4843
|
toolType: definition.toolType,
|
|
4414
4844
|
...definition.description ? { description: definition.description } : {},
|
|
@@ -4453,10 +4883,10 @@ function defineTool(input) {
|
|
|
4453
4883
|
`defineTool requires "toolType" to be one of: ${[...TOOL_DEFINITION_TYPES].join(", ")}`
|
|
4454
4884
|
);
|
|
4455
4885
|
}
|
|
4456
|
-
if (!
|
|
4886
|
+
if (!isPlainObject5(input.parametersSchema)) {
|
|
4457
4887
|
throw new Error('defineTool requires a "parametersSchema" object (a JSON Schema)');
|
|
4458
4888
|
}
|
|
4459
|
-
if (!
|
|
4889
|
+
if (!isPlainObject5(input.config)) {
|
|
4460
4890
|
throw new Error('defineTool requires a "config" object');
|
|
4461
4891
|
}
|
|
4462
4892
|
const unknownKeys = Object.keys(input).filter((key) => !DEFINE_TOOL_TOP_LEVEL_KEYS.has(key));
|
|
@@ -4504,19 +4934,19 @@ function parseRequestError4(err) {
|
|
|
4504
4934
|
}
|
|
4505
4935
|
function toConflictError4(err) {
|
|
4506
4936
|
const { status, body } = parseRequestError4(err);
|
|
4507
|
-
if (status !== 409 || !
|
|
4937
|
+
if (status !== 409 || !isPlainObject5(body)) return null;
|
|
4508
4938
|
const code = body.code;
|
|
4509
4939
|
if (code !== "external_modification" && code !== "remote_changed") return null;
|
|
4510
4940
|
return new ToolEnsureConflictError(
|
|
4511
4941
|
body
|
|
4512
4942
|
);
|
|
4513
4943
|
}
|
|
4514
|
-
var
|
|
4515
|
-
function
|
|
4516
|
-
let memo =
|
|
4944
|
+
var serverHashMemo5 = /* @__PURE__ */ new WeakMap();
|
|
4945
|
+
function memoFor5(client) {
|
|
4946
|
+
let memo = serverHashMemo5.get(client);
|
|
4517
4947
|
if (!memo) {
|
|
4518
4948
|
memo = /* @__PURE__ */ new Map();
|
|
4519
|
-
|
|
4949
|
+
serverHashMemo5.set(client, memo);
|
|
4520
4950
|
}
|
|
4521
4951
|
return memo;
|
|
4522
4952
|
}
|
|
@@ -4556,7 +4986,7 @@ async function ensureTool(client, definition, options = {}) {
|
|
|
4556
4986
|
}
|
|
4557
4987
|
return plan;
|
|
4558
4988
|
}
|
|
4559
|
-
const memo =
|
|
4989
|
+
const memo = memoFor5(client);
|
|
4560
4990
|
const localHash = await computeToolContentHash(definition);
|
|
4561
4991
|
const memoKey = `${definition.name} ${localHash}`;
|
|
4562
4992
|
const contentHash = memo.get(memoKey) ?? localHash;
|
|
@@ -4624,14 +5054,14 @@ var ToolsNamespace = class {
|
|
|
4624
5054
|
};
|
|
4625
5055
|
|
|
4626
5056
|
// src/products-ensure.ts
|
|
4627
|
-
function
|
|
5057
|
+
function isPlainObject6(value) {
|
|
4628
5058
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4629
5059
|
}
|
|
4630
5060
|
function normalizeValue4(value) {
|
|
4631
5061
|
if (Array.isArray(value)) {
|
|
4632
5062
|
return value.map((item) => normalizeValue4(item));
|
|
4633
5063
|
}
|
|
4634
|
-
if (
|
|
5064
|
+
if (isPlainObject6(value)) {
|
|
4635
5065
|
const normalized = {};
|
|
4636
5066
|
for (const key of Object.keys(value).sort()) {
|
|
4637
5067
|
const entry = value[key];
|
|
@@ -4643,7 +5073,7 @@ function normalizeValue4(value) {
|
|
|
4643
5073
|
return value;
|
|
4644
5074
|
}
|
|
4645
5075
|
function normalizeProductDefinition(definition) {
|
|
4646
|
-
const spec =
|
|
5076
|
+
const spec = isPlainObject6(definition.spec) ? normalizeValue4(definition.spec) : {};
|
|
4647
5077
|
return {
|
|
4648
5078
|
...definition.description ? { description: definition.description } : {},
|
|
4649
5079
|
...definition.icon ? { icon: definition.icon } : {},
|
|
@@ -4670,7 +5100,7 @@ function defineProduct(input) {
|
|
|
4670
5100
|
if (input.icon != null && typeof input.icon !== "string") {
|
|
4671
5101
|
throw new Error('defineProduct "icon" must be a string when provided');
|
|
4672
5102
|
}
|
|
4673
|
-
if (input.spec != null && !
|
|
5103
|
+
if (input.spec != null && !isPlainObject6(input.spec)) {
|
|
4674
5104
|
throw new Error('defineProduct "spec" must be an object when provided');
|
|
4675
5105
|
}
|
|
4676
5106
|
const unknownKeys = Object.keys(input).filter((key) => !DEFINE_PRODUCT_TOP_LEVEL_KEYS.has(key));
|
|
@@ -4717,19 +5147,19 @@ function parseRequestError5(err) {
|
|
|
4717
5147
|
}
|
|
4718
5148
|
function toConflictError5(err) {
|
|
4719
5149
|
const { status, body } = parseRequestError5(err);
|
|
4720
|
-
if (status !== 409 || !
|
|
5150
|
+
if (status !== 409 || !isPlainObject6(body)) return null;
|
|
4721
5151
|
const code = body.code;
|
|
4722
5152
|
if (code !== "external_modification" && code !== "remote_changed") return null;
|
|
4723
5153
|
return new ProductEnsureConflictError(
|
|
4724
5154
|
body
|
|
4725
5155
|
);
|
|
4726
5156
|
}
|
|
4727
|
-
var
|
|
4728
|
-
function
|
|
4729
|
-
let memo =
|
|
5157
|
+
var serverHashMemo6 = /* @__PURE__ */ new WeakMap();
|
|
5158
|
+
function memoFor6(client) {
|
|
5159
|
+
let memo = serverHashMemo6.get(client);
|
|
4730
5160
|
if (!memo) {
|
|
4731
5161
|
memo = /* @__PURE__ */ new Map();
|
|
4732
|
-
|
|
5162
|
+
serverHashMemo6.set(client, memo);
|
|
4733
5163
|
}
|
|
4734
5164
|
return memo;
|
|
4735
5165
|
}
|
|
@@ -4769,7 +5199,7 @@ async function ensureProduct(client, definition, options = {}) {
|
|
|
4769
5199
|
}
|
|
4770
5200
|
return plan;
|
|
4771
5201
|
}
|
|
4772
|
-
const memo =
|
|
5202
|
+
const memo = memoFor6(client);
|
|
4773
5203
|
const localHash = await computeProductContentHash(definition);
|
|
4774
5204
|
const memoKey = `${definition.name} ${localHash}`;
|
|
4775
5205
|
const contentHash = memo.get(memoKey) ?? localHash;
|
|
@@ -4798,14 +5228,14 @@ async function pullProduct(client, name) {
|
|
|
4798
5228
|
}
|
|
4799
5229
|
|
|
4800
5230
|
// src/products-ensure-fpo.ts
|
|
4801
|
-
function
|
|
5231
|
+
function isPlainObject7(value) {
|
|
4802
5232
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4803
5233
|
}
|
|
4804
5234
|
function normalizeValue5(value) {
|
|
4805
5235
|
if (Array.isArray(value)) {
|
|
4806
5236
|
return value.map((item) => normalizeValue5(item));
|
|
4807
5237
|
}
|
|
4808
|
-
if (
|
|
5238
|
+
if (isPlainObject7(value)) {
|
|
4809
5239
|
const normalized = {};
|
|
4810
5240
|
for (const key of Object.keys(value).sort()) {
|
|
4811
5241
|
const entry = value[key];
|
|
@@ -4817,7 +5247,7 @@ function normalizeValue5(value) {
|
|
|
4817
5247
|
return value;
|
|
4818
5248
|
}
|
|
4819
5249
|
function normalizeFpoDefinition(fpo) {
|
|
4820
|
-
const productInput =
|
|
5250
|
+
const productInput = isPlainObject7(fpo.product) ? fpo.product : {};
|
|
4821
5251
|
const { name: _identityName, ...productRest } = productInput;
|
|
4822
5252
|
const product = normalizeValue5(productRest);
|
|
4823
5253
|
return {
|
|
@@ -4838,10 +5268,10 @@ async function computeFpoContentHash(fpo) {
|
|
|
4838
5268
|
return Array.from(new Uint8Array(hashBuffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
4839
5269
|
}
|
|
4840
5270
|
function defineFpo(fpo) {
|
|
4841
|
-
if (!
|
|
5271
|
+
if (!isPlainObject7(fpo)) {
|
|
4842
5272
|
throw new Error("defineFpo requires an FPO object");
|
|
4843
5273
|
}
|
|
4844
|
-
const product =
|
|
5274
|
+
const product = isPlainObject7(fpo.product) ? fpo.product : void 0;
|
|
4845
5275
|
if (!product || typeof product.name !== "string" || product.name.length === 0) {
|
|
4846
5276
|
throw new Error('defineFpo requires a non-empty "product.name" (the converge identity)');
|
|
4847
5277
|
}
|
|
@@ -4937,14 +5367,14 @@ var ProductsNamespace = class {
|
|
|
4937
5367
|
};
|
|
4938
5368
|
|
|
4939
5369
|
// src/surfaces-ensure.ts
|
|
4940
|
-
function
|
|
5370
|
+
function isPlainObject8(value) {
|
|
4941
5371
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4942
5372
|
}
|
|
4943
5373
|
function normalizeValue6(value) {
|
|
4944
5374
|
if (Array.isArray(value)) {
|
|
4945
5375
|
return value.map((item) => normalizeValue6(item));
|
|
4946
5376
|
}
|
|
4947
|
-
if (
|
|
5377
|
+
if (isPlainObject8(value)) {
|
|
4948
5378
|
const normalized = {};
|
|
4949
5379
|
for (const key of Object.keys(value).sort()) {
|
|
4950
5380
|
const entry = value[key];
|
|
@@ -4956,7 +5386,7 @@ function normalizeValue6(value) {
|
|
|
4956
5386
|
return value;
|
|
4957
5387
|
}
|
|
4958
5388
|
function normalizeSurfaceDefinition(definition) {
|
|
4959
|
-
const behavior =
|
|
5389
|
+
const behavior = isPlainObject8(definition.behavior) ? normalizeValue6(definition.behavior) : { type: definition.type };
|
|
4960
5390
|
return {
|
|
4961
5391
|
type: definition.type,
|
|
4962
5392
|
behavior,
|
|
@@ -5009,13 +5439,13 @@ function defineSurface(input) {
|
|
|
5009
5439
|
`defineSurface requires "type" to be one of: ${[...SURFACE_DEFINITION_TYPES].join(", ")}`
|
|
5010
5440
|
);
|
|
5011
5441
|
}
|
|
5012
|
-
if (input.behavior !== void 0 && !
|
|
5442
|
+
if (input.behavior !== void 0 && !isPlainObject8(input.behavior)) {
|
|
5013
5443
|
throw new Error('defineSurface "behavior" must be an object when provided');
|
|
5014
5444
|
}
|
|
5015
|
-
if (input.inbound !== void 0 && !
|
|
5445
|
+
if (input.inbound !== void 0 && !isPlainObject8(input.inbound)) {
|
|
5016
5446
|
throw new Error('defineSurface "inbound" must be an object when provided');
|
|
5017
5447
|
}
|
|
5018
|
-
if (input.outbound !== void 0 && !
|
|
5448
|
+
if (input.outbound !== void 0 && !isPlainObject8(input.outbound)) {
|
|
5019
5449
|
throw new Error('defineSurface "outbound" must be an object when provided');
|
|
5020
5450
|
}
|
|
5021
5451
|
if (input.status !== void 0 && !["draft", "active", "paused"].includes(input.status)) {
|
|
@@ -5071,19 +5501,19 @@ function parseRequestError6(err) {
|
|
|
5071
5501
|
}
|
|
5072
5502
|
function toConflictError6(err) {
|
|
5073
5503
|
const { status, body } = parseRequestError6(err);
|
|
5074
|
-
if (status !== 409 || !
|
|
5504
|
+
if (status !== 409 || !isPlainObject8(body)) return null;
|
|
5075
5505
|
const code = body.code;
|
|
5076
5506
|
if (code !== "external_modification" && code !== "remote_changed") return null;
|
|
5077
5507
|
return new SurfaceEnsureConflictError(
|
|
5078
5508
|
body
|
|
5079
5509
|
);
|
|
5080
5510
|
}
|
|
5081
|
-
var
|
|
5082
|
-
function
|
|
5083
|
-
let memo =
|
|
5511
|
+
var serverHashMemo7 = /* @__PURE__ */ new WeakMap();
|
|
5512
|
+
function memoFor7(client) {
|
|
5513
|
+
let memo = serverHashMemo7.get(client);
|
|
5084
5514
|
if (!memo) {
|
|
5085
5515
|
memo = /* @__PURE__ */ new Map();
|
|
5086
|
-
|
|
5516
|
+
serverHashMemo7.set(client, memo);
|
|
5087
5517
|
}
|
|
5088
5518
|
return memo;
|
|
5089
5519
|
}
|
|
@@ -5123,7 +5553,7 @@ async function ensureSurface(client, productId, definition, options = {}) {
|
|
|
5123
5553
|
}
|
|
5124
5554
|
return plan;
|
|
5125
5555
|
}
|
|
5126
|
-
const memo =
|
|
5556
|
+
const memo = memoFor7(client);
|
|
5127
5557
|
const localHash = await computeSurfaceContentHash(definition);
|
|
5128
5558
|
const memoKey = `${productId} ${definition.name} ${localHash}`;
|
|
5129
5559
|
const contentHash = memo.get(memoKey) ?? localHash;
|
|
@@ -5672,7 +6102,7 @@ var Runtype = class {
|
|
|
5672
6102
|
|
|
5673
6103
|
// src/version.ts
|
|
5674
6104
|
var FALLBACK_VERSION = "0.0.0";
|
|
5675
|
-
var SDK_VERSION = "5.
|
|
6105
|
+
var SDK_VERSION = "5.5.0".length > 0 ? "5.5.0" : FALLBACK_VERSION;
|
|
5676
6106
|
var RUNTYPE_CLIENT_KIND = "sdk";
|
|
5677
6107
|
var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
|
|
5678
6108
|
|
|
@@ -13383,14 +13813,19 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
13383
13813
|
buildLedgerOffloadReference,
|
|
13384
13814
|
buildPolicyGuidance,
|
|
13385
13815
|
buildSendViewOffloadMarker,
|
|
13816
|
+
calledTool,
|
|
13386
13817
|
compileWorkflowConfig,
|
|
13818
|
+
completed,
|
|
13387
13819
|
computeAgentContentHash,
|
|
13820
|
+
computeEvalContentHash,
|
|
13388
13821
|
computeFlowContentHash,
|
|
13389
13822
|
computeFpoContentHash,
|
|
13390
13823
|
computeProductContentHash,
|
|
13391
13824
|
computeSkillContentHash,
|
|
13392
13825
|
computeSurfaceContentHash,
|
|
13393
13826
|
computeToolContentHash,
|
|
13827
|
+
contains,
|
|
13828
|
+
cost,
|
|
13394
13829
|
createAgentEventTranslator,
|
|
13395
13830
|
createClient,
|
|
13396
13831
|
createExternalTool,
|
|
@@ -13398,6 +13833,7 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
13398
13833
|
defaultWorkflow,
|
|
13399
13834
|
defaultWorkflowConfig,
|
|
13400
13835
|
defineAgent,
|
|
13836
|
+
defineEval,
|
|
13401
13837
|
defineFlow,
|
|
13402
13838
|
defineFpo,
|
|
13403
13839
|
definePlaybook,
|
|
@@ -13407,6 +13843,7 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
13407
13843
|
defineTool,
|
|
13408
13844
|
deployWorkflow,
|
|
13409
13845
|
ensureDefaultWorkflowHooks,
|
|
13846
|
+
ensureEval,
|
|
13410
13847
|
ensureFpo,
|
|
13411
13848
|
evaluateGeneratedRuntimeToolProposal,
|
|
13412
13849
|
extractDeclaredToolResultChars,
|
|
@@ -13419,7 +13856,15 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
13419
13856
|
isPreservationSensitiveTask,
|
|
13420
13857
|
isUnifiedEventType,
|
|
13421
13858
|
isWorkflowHookRef,
|
|
13859
|
+
jsonField,
|
|
13860
|
+
judge,
|
|
13861
|
+
judges,
|
|
13862
|
+
latency,
|
|
13863
|
+
length,
|
|
13422
13864
|
listWorkflowHooks,
|
|
13865
|
+
matchesExpected,
|
|
13866
|
+
maxToolCalls,
|
|
13867
|
+
noError,
|
|
13423
13868
|
normalizeAgentDefinition,
|
|
13424
13869
|
normalizeCandidatePath,
|
|
13425
13870
|
normalizeFpoDefinition,
|
|
@@ -13427,19 +13872,29 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
13427
13872
|
normalizeSkillDefinition,
|
|
13428
13873
|
normalizeSurfaceDefinition,
|
|
13429
13874
|
normalizeToolDefinition,
|
|
13875
|
+
notCalledTool,
|
|
13876
|
+
notContains,
|
|
13430
13877
|
parseFinalBuffer,
|
|
13431
13878
|
parseLedgerArtifactRelativePath,
|
|
13432
13879
|
parseOffloadedOutputId,
|
|
13433
13880
|
parseSSEChunk,
|
|
13434
13881
|
processStream,
|
|
13882
|
+
pullEval,
|
|
13435
13883
|
pullFpo,
|
|
13884
|
+
ranStep,
|
|
13885
|
+
regex,
|
|
13436
13886
|
registerWorkflowHook,
|
|
13437
13887
|
resolveStallStopAfter,
|
|
13438
13888
|
resolveWorkflowHook,
|
|
13889
|
+
runEvalSuite,
|
|
13439
13890
|
sanitizeTaskSlug,
|
|
13440
13891
|
shouldInjectEmptySessionNudge,
|
|
13441
13892
|
shouldRequestModelEscalation,
|
|
13893
|
+
stepOrder,
|
|
13442
13894
|
streamEvents,
|
|
13895
|
+
toolOrder,
|
|
13443
13896
|
unregisterWorkflowHook,
|
|
13897
|
+
usedNoTools,
|
|
13898
|
+
validJson,
|
|
13444
13899
|
withUnifiedEvents
|
|
13445
13900
|
});
|