@niscorp/cortex 0.1.3 → 0.1.4
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/CHANGELOG.md +20 -0
- package/DESIGN.md +5 -1
- package/README.md +45 -8
- package/dist/index.cjs +11 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -16
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -207,8 +207,8 @@ var envelopeLooseWireSchema = (spec) => {
|
|
|
207
207
|
return z.object({
|
|
208
208
|
reasoning: z.string().nullish().describe(REASONING_DESCRIPTION),
|
|
209
209
|
response,
|
|
210
|
-
//
|
|
211
|
-
//
|
|
210
|
+
// Not z.unknown(): an empty {} schema tells the model no type, and it
|
|
211
|
+
// sends the payload as a string.
|
|
212
212
|
data: z.union([z.record(z.string(), z.unknown()), z.array(z.unknown())]).describe(LOOSE_DATA_DESCRIPTION)
|
|
213
213
|
});
|
|
214
214
|
}
|
|
@@ -219,12 +219,13 @@ var envelopeLooseWireSchema = (spec) => {
|
|
|
219
219
|
};
|
|
220
220
|
var envelopeAcceptSchema = (_spec) => z.union([z.record(z.string(), z.unknown()), z.array(z.unknown())]);
|
|
221
221
|
var KNOWN_KEYS = /* @__PURE__ */ new Set(["response", "data", "reasoning"]);
|
|
222
|
-
var
|
|
223
|
-
var
|
|
222
|
+
var takesAnyObject = (schema) => schema.safeParse({ "cortex:no-such-field": true }).success;
|
|
223
|
+
var asBarePayload = (record, spec) => {
|
|
224
224
|
if (!spec.schema || spec.responseMode === "required") return void 0;
|
|
225
225
|
const keys = Object.keys(record);
|
|
226
226
|
const looksWrapped = keys.length > 0 && keys.every((key) => KNOWN_KEYS.has(key));
|
|
227
227
|
if (looksWrapped) return void 0;
|
|
228
|
+
if (takesAnyObject(spec.schema)) return void 0;
|
|
228
229
|
const parsed = spec.schema.safeParse(record);
|
|
229
230
|
if (!parsed.success) return void 0;
|
|
230
231
|
return { data: parsed.data };
|
|
@@ -239,8 +240,8 @@ var validateEnvelope = (raw, spec) => {
|
|
|
239
240
|
if (!KNOWN_KEYS.has(key)) issues.push(`unknown key "${key}" \u2014 only response, data, reasoning are allowed`);
|
|
240
241
|
}
|
|
241
242
|
if (issues.length > 0) {
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
243
|
+
const bare = asBarePayload(record, spec);
|
|
244
|
+
if (bare !== void 0) return { ok: true, envelope: bare };
|
|
244
245
|
}
|
|
245
246
|
const response = record["response"] ?? void 0;
|
|
246
247
|
if (spec.responseMode === "required" && typeof response !== "string") {
|
|
@@ -253,7 +254,7 @@ var validateEnvelope = (raw, spec) => {
|
|
|
253
254
|
issues.push("reasoning: must be a string");
|
|
254
255
|
}
|
|
255
256
|
if (spec.schema) {
|
|
256
|
-
const data =
|
|
257
|
+
const data = decodeJsonish(record["data"]);
|
|
257
258
|
let parsed = spec.schema.safeParse(data);
|
|
258
259
|
if (!parsed.success) {
|
|
259
260
|
const repaired = spec.schema.safeParse(deepDecodeJsonish(data));
|
|
@@ -363,13 +364,9 @@ var stringify = (value) => {
|
|
|
363
364
|
}
|
|
364
365
|
};
|
|
365
366
|
var buildToolDescriptor = (tool) => ({
|
|
366
|
-
// The model sees the tool's NAME — the field designed for it (prompts
|
|
367
|
-
// say "call `query`"). The id stays the gate/policy/observation
|
|
368
|
-
// identity; the loop resolves calls by either.
|
|
369
367
|
name: tool.config.name,
|
|
370
368
|
description: tool.config.description,
|
|
371
|
-
//
|
|
372
|
-
// the caller's zod copy, not ours.
|
|
369
|
+
// Converted by the schema's own zod, not by cortex's: it may come from another copy of zod.
|
|
373
370
|
parameters: tool.config.input["~standard"].jsonSchema.output({ target: "draft-07" })
|
|
374
371
|
});
|
|
375
372
|
var runLoop = async (cfg) => {
|
|
@@ -581,7 +578,7 @@ var runLoop = async (cfg) => {
|
|
|
581
578
|
return verdict;
|
|
582
579
|
};
|
|
583
580
|
const streamEmittedOutput = cfg.resolved.transport !== "respond";
|
|
584
|
-
const
|
|
581
|
+
const oneStep = async (llm, request) => {
|
|
585
582
|
if (cfg.transport === "step") {
|
|
586
583
|
try {
|
|
587
584
|
return ok(await llm.step(request));
|
|
@@ -687,7 +684,7 @@ var runLoop = async (cfg) => {
|
|
|
687
684
|
...cfg.resolved.outputToolName !== void 0 && { outputTool: cfg.resolved.outputToolName }
|
|
688
685
|
}
|
|
689
686
|
};
|
|
690
|
-
const stepOutcome = await
|
|
687
|
+
const stepOutcome = await oneStep(llm, request);
|
|
691
688
|
if (!stepOutcome.ok) return fail(stepOutcome.error);
|
|
692
689
|
const result = stepOutcome.data;
|
|
693
690
|
s.usage = addUsage(s.usage, result.usage);
|
|
@@ -1097,8 +1094,6 @@ var previewAgent = async (definition, input, options) => {
|
|
|
1097
1094
|
...inputMessages(input)
|
|
1098
1095
|
];
|
|
1099
1096
|
const tools = [
|
|
1100
|
-
// The run's own builder — the preview shows the model-visible NAME,
|
|
1101
|
-
// not the id, or it would explain a request that never goes out.
|
|
1102
1097
|
...allTools.map(buildToolDescriptor),
|
|
1103
1098
|
...resolved.respondDescriptor ? [resolved.respondDescriptor] : []
|
|
1104
1099
|
];
|