@exulu/backend 5.9.0 → 5.10.1
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/{chunk-LDA6HYEP.js → chunk-TFWF6WKM.js} +707 -179
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-PEZCQBM5.js → convert-exulu-tools-to-ai-sdk-tools-LL7R3VTK.js} +1 -1
- package/dist/index.cjs +1017 -410
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +63 -10
- package/ee/agentic-retrieval/pipeline/index.test.ts +47 -0
- package/ee/agentic-retrieval/pipeline/index.ts +28 -0
- package/ee/agentic-retrieval/pipeline/multi-query.test.ts +56 -0
- package/ee/agentic-retrieval/pipeline/multi-query.ts +14 -0
- package/ee/agentic-retrieval/pipeline/search.test.ts +21 -0
- package/ee/agentic-retrieval/pipeline/search.ts +8 -0
- package/package.json +1 -1
|
@@ -659,7 +659,7 @@ var ExuluTool = class _ExuluTool {
|
|
|
659
659
|
if (!agent) {
|
|
660
660
|
throw new Error("Agent not found.");
|
|
661
661
|
}
|
|
662
|
-
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-
|
|
662
|
+
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-LL7R3VTK.js");
|
|
663
663
|
const tools = await convertExuluToolsToAiSdkTools2(
|
|
664
664
|
[this],
|
|
665
665
|
[],
|
|
@@ -845,8 +845,36 @@ var createSessionItemsRetrievalTool = async ({
|
|
|
845
845
|
return sessionItemsRetrievalTool;
|
|
846
846
|
};
|
|
847
847
|
|
|
848
|
+
// src/exulu/approval-revalidation.ts
|
|
849
|
+
function answeredApprovalToolCallIds(messages) {
|
|
850
|
+
const toolCallByApproval = /* @__PURE__ */ new Map();
|
|
851
|
+
for (const message of messages ?? []) {
|
|
852
|
+
if (message.role !== "assistant" || typeof message.content === "string") continue;
|
|
853
|
+
for (const part of message.content) {
|
|
854
|
+
if (part?.type === "tool-approval-request" && typeof part.approvalId === "string" && typeof part.toolCallId === "string") {
|
|
855
|
+
toolCallByApproval.set(part.approvalId, part.toolCallId);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
const answered = /* @__PURE__ */ new Set();
|
|
860
|
+
for (const message of messages ?? []) {
|
|
861
|
+
if (message.role !== "tool" || typeof message.content === "string") continue;
|
|
862
|
+
for (const part of message.content) {
|
|
863
|
+
if (part?.type !== "tool-approval-response" || typeof part.approvalId !== "string") continue;
|
|
864
|
+
const toolCallId = toolCallByApproval.get(part.approvalId);
|
|
865
|
+
if (toolCallId) answered.add(toolCallId);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return answered;
|
|
869
|
+
}
|
|
870
|
+
function needsApprovalForCall(args) {
|
|
871
|
+
if (!args.requiresApproval) return false;
|
|
872
|
+
if (answeredApprovalToolCallIds(args.messages).has(args.toolCallId)) return true;
|
|
873
|
+
return !args.approvedForSession;
|
|
874
|
+
}
|
|
875
|
+
|
|
848
876
|
// ee/agentic-retrieval/pipeline/index.ts
|
|
849
|
-
import { z as
|
|
877
|
+
import { z as z8 } from "zod";
|
|
850
878
|
|
|
851
879
|
// src/exulu/resolve-reranker.ts
|
|
852
880
|
var ResolveRerankerError = class extends Error {
|
|
@@ -2320,6 +2348,324 @@ ${glossary.map((g) => `${g.term} : ${g.meaning}`).join("\n")}` : "";
|
|
|
2320
2348
|
}
|
|
2321
2349
|
}
|
|
2322
2350
|
|
|
2351
|
+
// src/exulu/json-field-schema.ts
|
|
2352
|
+
import { z as z7 } from "zod";
|
|
2353
|
+
function unwrap(schema) {
|
|
2354
|
+
let current = schema;
|
|
2355
|
+
for (; ; ) {
|
|
2356
|
+
const def = current.def;
|
|
2357
|
+
if (def.type === "optional" || def.type === "nullable" || def.type === "default") {
|
|
2358
|
+
current = def.innerType;
|
|
2359
|
+
continue;
|
|
2360
|
+
}
|
|
2361
|
+
return current;
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
function isPlainObject(value) {
|
|
2365
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2366
|
+
}
|
|
2367
|
+
function hasOwn(target, key) {
|
|
2368
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
2369
|
+
}
|
|
2370
|
+
function schemaPaths(schema) {
|
|
2371
|
+
const base = unwrap(schema);
|
|
2372
|
+
const def = base.def;
|
|
2373
|
+
if (def.type === "union") {
|
|
2374
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2375
|
+
for (const option of def.options) {
|
|
2376
|
+
for (const path3 of schemaPaths(option)) seen.add(path3);
|
|
2377
|
+
}
|
|
2378
|
+
return [...seen];
|
|
2379
|
+
}
|
|
2380
|
+
if (def.type === "record") {
|
|
2381
|
+
const subPaths = schemaPaths(def.valueType);
|
|
2382
|
+
return subPaths.length > 0 ? subPaths.map((path3) => `<key>.${path3}`) : ["<key>"];
|
|
2383
|
+
}
|
|
2384
|
+
if (def.type !== "object") {
|
|
2385
|
+
return [];
|
|
2386
|
+
}
|
|
2387
|
+
const shape = def.shape;
|
|
2388
|
+
const paths = [];
|
|
2389
|
+
for (const key of Object.keys(shape)) {
|
|
2390
|
+
const child = shape[key];
|
|
2391
|
+
if (!child) continue;
|
|
2392
|
+
const childDef = unwrap(child).def;
|
|
2393
|
+
if (childDef.type === "object") {
|
|
2394
|
+
for (const subKey of Object.keys(childDef.shape)) {
|
|
2395
|
+
paths.push(`${key}.${subKey}`);
|
|
2396
|
+
}
|
|
2397
|
+
} else {
|
|
2398
|
+
paths.push(key);
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
return paths;
|
|
2402
|
+
}
|
|
2403
|
+
function unknownChildPaths(child, value, key) {
|
|
2404
|
+
const childDef = unwrap(child).def;
|
|
2405
|
+
if (childDef.type === "object") {
|
|
2406
|
+
if (!isPlainObject(value)) {
|
|
2407
|
+
return [key];
|
|
2408
|
+
}
|
|
2409
|
+
const childShape = childDef.shape;
|
|
2410
|
+
const unknown = [];
|
|
2411
|
+
for (const subKey of Object.keys(value)) {
|
|
2412
|
+
if (!hasOwn(childShape, subKey)) unknown.push(`${key}.${subKey}`);
|
|
2413
|
+
}
|
|
2414
|
+
return unknown;
|
|
2415
|
+
}
|
|
2416
|
+
if (childDef.type === "record" && !isPlainObject(value)) {
|
|
2417
|
+
return [key];
|
|
2418
|
+
}
|
|
2419
|
+
return [];
|
|
2420
|
+
}
|
|
2421
|
+
function unknownPaths(schema, value) {
|
|
2422
|
+
if (!isPlainObject(value)) return [];
|
|
2423
|
+
const base = unwrap(schema);
|
|
2424
|
+
const def = base.def;
|
|
2425
|
+
if (def.type === "record") {
|
|
2426
|
+
const valueType = def.valueType;
|
|
2427
|
+
const unknown2 = [];
|
|
2428
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
2429
|
+
unknown2.push(...unknownChildPaths(valueType, inner, key));
|
|
2430
|
+
}
|
|
2431
|
+
return unknown2;
|
|
2432
|
+
}
|
|
2433
|
+
if (def.type !== "object") {
|
|
2434
|
+
return [];
|
|
2435
|
+
}
|
|
2436
|
+
const shape = def.shape;
|
|
2437
|
+
const unknown = [];
|
|
2438
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
2439
|
+
const child = hasOwn(shape, key) ? shape[key] : void 0;
|
|
2440
|
+
if (!child) {
|
|
2441
|
+
unknown.push(key);
|
|
2442
|
+
continue;
|
|
2443
|
+
}
|
|
2444
|
+
unknown.push(...unknownChildPaths(child, inner, key));
|
|
2445
|
+
}
|
|
2446
|
+
return unknown;
|
|
2447
|
+
}
|
|
2448
|
+
function valueAtPath(value, path3) {
|
|
2449
|
+
let current = value;
|
|
2450
|
+
for (const segment of path3) {
|
|
2451
|
+
if (current === null || typeof current !== "object") return void 0;
|
|
2452
|
+
current = current[segment];
|
|
2453
|
+
}
|
|
2454
|
+
return current;
|
|
2455
|
+
}
|
|
2456
|
+
function leafViolations(schema, value) {
|
|
2457
|
+
if (!isPlainObject(value)) return [];
|
|
2458
|
+
const base = unwrap(schema);
|
|
2459
|
+
const def = base.def;
|
|
2460
|
+
let subSchemaFor;
|
|
2461
|
+
if (def.type === "record") {
|
|
2462
|
+
const valueType = def.valueType;
|
|
2463
|
+
subSchemaFor = () => valueType;
|
|
2464
|
+
} else if (def.type === "object") {
|
|
2465
|
+
const shape = def.shape;
|
|
2466
|
+
subSchemaFor = (key) => hasOwn(shape, key) ? shape[key] : void 0;
|
|
2467
|
+
} else {
|
|
2468
|
+
return [];
|
|
2469
|
+
}
|
|
2470
|
+
const violations = [];
|
|
2471
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
2472
|
+
const subSchema = subSchemaFor(key);
|
|
2473
|
+
if (!subSchema) continue;
|
|
2474
|
+
const result = subSchema.safeParse(inner);
|
|
2475
|
+
if (result.success) continue;
|
|
2476
|
+
for (const issue of result.error.issues) {
|
|
2477
|
+
const issuePath = issue.path.map(String);
|
|
2478
|
+
const expectedSet = describeExpectedValues(issue);
|
|
2479
|
+
violations.push({
|
|
2480
|
+
path: [key, ...issuePath].join("."),
|
|
2481
|
+
expected: expectedSet ? `expected one of ${expectedSet}` : issue.message,
|
|
2482
|
+
received: issue.path.length > 0 ? valueAtPath(inner, issue.path) : inner
|
|
2483
|
+
});
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
return violations;
|
|
2487
|
+
}
|
|
2488
|
+
function describeExpectedValues(issue) {
|
|
2489
|
+
const anyIssue = issue;
|
|
2490
|
+
if (anyIssue.code === "invalid_value" && Array.isArray(anyIssue.values) && anyIssue.values.length > 0) {
|
|
2491
|
+
return anyIssue.values.map((value) => JSON.stringify(value)).join(" | ");
|
|
2492
|
+
}
|
|
2493
|
+
if (anyIssue.code === "invalid_union" && Array.isArray(anyIssue.errors)) {
|
|
2494
|
+
const parts = [];
|
|
2495
|
+
for (const branchIssues of anyIssue.errors) {
|
|
2496
|
+
const branchArray = branchIssues;
|
|
2497
|
+
const first = branchArray[0];
|
|
2498
|
+
if (!first || !Array.isArray(first.values) || first.values.length === 0) return void 0;
|
|
2499
|
+
parts.push(...first.values.map((value) => JSON.stringify(value)));
|
|
2500
|
+
}
|
|
2501
|
+
return parts.length > 0 ? parts.join(" | ") : void 0;
|
|
2502
|
+
}
|
|
2503
|
+
return void 0;
|
|
2504
|
+
}
|
|
2505
|
+
function missingRequiredKeys(schema, value) {
|
|
2506
|
+
if (!isPlainObject(value)) return [];
|
|
2507
|
+
const def = unwrap(schema).def;
|
|
2508
|
+
if (def.type !== "object") return [];
|
|
2509
|
+
const shape = def.shape;
|
|
2510
|
+
const missing = [];
|
|
2511
|
+
for (const key of Object.keys(shape)) {
|
|
2512
|
+
const child = shape[key];
|
|
2513
|
+
if (!child) continue;
|
|
2514
|
+
if (hasOwn(value, key)) continue;
|
|
2515
|
+
if (!child.safeParse(void 0).success) missing.push(key);
|
|
2516
|
+
}
|
|
2517
|
+
return missing;
|
|
2518
|
+
}
|
|
2519
|
+
function requiresPlainObject(schema) {
|
|
2520
|
+
const def = unwrap(schema).def;
|
|
2521
|
+
return def.type === "object" || def.type === "record";
|
|
2522
|
+
}
|
|
2523
|
+
function preserveDescription(original, rebuilt) {
|
|
2524
|
+
return original.description ? rebuilt.describe(original.description) : rebuilt;
|
|
2525
|
+
}
|
|
2526
|
+
function loosenForTransport(schema) {
|
|
2527
|
+
const def = schema.def;
|
|
2528
|
+
switch (def.type) {
|
|
2529
|
+
case "optional":
|
|
2530
|
+
return preserveDescription(schema, z7.optional(loosenForTransport(def.innerType)));
|
|
2531
|
+
case "nullable":
|
|
2532
|
+
return preserveDescription(schema, z7.nullable(loosenForTransport(def.innerType)));
|
|
2533
|
+
case "default":
|
|
2534
|
+
return preserveDescription(
|
|
2535
|
+
schema,
|
|
2536
|
+
loosenForTransport(def.innerType).default(
|
|
2537
|
+
def.defaultValue
|
|
2538
|
+
)
|
|
2539
|
+
);
|
|
2540
|
+
case "array":
|
|
2541
|
+
return preserveDescription(schema, z7.array(loosenForTransport(def.element)));
|
|
2542
|
+
case "record": {
|
|
2543
|
+
const loosenedValue = loosenForTransport(def.valueType);
|
|
2544
|
+
return preserveDescription(
|
|
2545
|
+
schema,
|
|
2546
|
+
schema.clone({ ...def, valueType: loosenedValue })
|
|
2547
|
+
);
|
|
2548
|
+
}
|
|
2549
|
+
case "union":
|
|
2550
|
+
return preserveDescription(
|
|
2551
|
+
schema,
|
|
2552
|
+
z7.union(def.options.map((option) => loosenForTransport(option)))
|
|
2553
|
+
);
|
|
2554
|
+
case "object": {
|
|
2555
|
+
const shape = def.shape;
|
|
2556
|
+
const loosenedShape = {};
|
|
2557
|
+
for (const key of Object.keys(shape)) {
|
|
2558
|
+
const child = shape[key];
|
|
2559
|
+
if (!child) continue;
|
|
2560
|
+
loosenedShape[key] = loosenForTransport(child);
|
|
2561
|
+
}
|
|
2562
|
+
return preserveDescription(
|
|
2563
|
+
schema,
|
|
2564
|
+
z7.object(loosenedShape).passthrough()
|
|
2565
|
+
);
|
|
2566
|
+
}
|
|
2567
|
+
default:
|
|
2568
|
+
return schema;
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
function mergeJson(stored, patch) {
|
|
2572
|
+
const merged = isPlainObject(stored) ? { ...stored } : {};
|
|
2573
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
2574
|
+
if (value === null) {
|
|
2575
|
+
delete merged[key];
|
|
2576
|
+
} else {
|
|
2577
|
+
Object.defineProperty(merged, key, { value, writable: true, enumerable: true, configurable: true });
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
return merged;
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
// src/graphql/utilities/convert-graphql-filter-operator-to-pg-query.ts
|
|
2584
|
+
var UnknownFilterPathError = class extends Error {
|
|
2585
|
+
field;
|
|
2586
|
+
offendingPaths;
|
|
2587
|
+
validPaths;
|
|
2588
|
+
constructor(field, offendingPaths, validPaths) {
|
|
2589
|
+
const plural = offendingPaths.length > 1;
|
|
2590
|
+
const badList = offendingPaths.map((path3) => `"${path3}"`).join(", ");
|
|
2591
|
+
const validList = validPaths.length > 0 ? validPaths.join(", ") : "(the schema declares no paths)";
|
|
2592
|
+
super(
|
|
2593
|
+
`Filter on field "${field}" rejected: ${plural ? "paths" : "path"} ${badList} ${plural ? "do" : "does"} not match the shape declared for "${field}". A filter on a path the schema does not define would silently match zero rows instead of erroring, which looks identical to "there are none" \u2014 so it is refused instead. Valid paths for "${field}": ${validList}.`
|
|
2594
|
+
);
|
|
2595
|
+
this.name = "UnknownFilterPathError";
|
|
2596
|
+
this.field = field;
|
|
2597
|
+
this.offendingPaths = offendingPaths;
|
|
2598
|
+
this.validPaths = validPaths;
|
|
2599
|
+
}
|
|
2600
|
+
};
|
|
2601
|
+
var convertGraphqlOperatorToPostgresQuery = (query, fieldName, operators, table, field_prefix) => {
|
|
2602
|
+
const field = table?.fields.find((f) => f.name === fieldName);
|
|
2603
|
+
const isJsonField = field?.type === "json";
|
|
2604
|
+
const prefix = field_prefix ? field_prefix + "." : "";
|
|
2605
|
+
fieldName = prefix + fieldName;
|
|
2606
|
+
console.log("[EXULU] operators", operators);
|
|
2607
|
+
if (isJsonField && field?.schema) {
|
|
2608
|
+
const filterValues = [];
|
|
2609
|
+
if (operators.eq !== void 0) filterValues.push(operators.eq);
|
|
2610
|
+
if (operators.ne !== void 0) filterValues.push(operators.ne);
|
|
2611
|
+
if (Array.isArray(operators.in)) filterValues.push(...operators.in);
|
|
2612
|
+
if (operators.contains !== void 0) filterValues.push(operators.contains);
|
|
2613
|
+
const badPaths = /* @__PURE__ */ new Set();
|
|
2614
|
+
for (const value of filterValues) {
|
|
2615
|
+
for (const path3 of unknownPaths(field.schema, value)) badPaths.add(path3);
|
|
2616
|
+
}
|
|
2617
|
+
if (badPaths.size > 0) {
|
|
2618
|
+
throw new UnknownFilterPathError(field.name, [...badPaths], schemaPaths(field.schema));
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
if (operators.eq !== void 0) {
|
|
2622
|
+
if (isJsonField) {
|
|
2623
|
+
query = query.whereRaw(`?? = ?::jsonb`, [fieldName, JSON.stringify(operators.eq)]);
|
|
2624
|
+
} else {
|
|
2625
|
+
query = query.where(fieldName, operators.eq);
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
if (operators.ne !== void 0) {
|
|
2629
|
+
if (isJsonField) {
|
|
2630
|
+
query = query.whereRaw(`?? IS DISTINCT FROM ?::jsonb`, [
|
|
2631
|
+
fieldName,
|
|
2632
|
+
JSON.stringify(operators.ne)
|
|
2633
|
+
]);
|
|
2634
|
+
} else {
|
|
2635
|
+
query = query.whereRaw(`?? IS DISTINCT FROM ?`, [fieldName, operators.ne]);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
if (operators.in !== void 0) {
|
|
2639
|
+
if (isJsonField) {
|
|
2640
|
+
const conditions = operators.in.map(() => `?? = ?::jsonb`).join(" OR ");
|
|
2641
|
+
const bindings = operators.in.flatMap((val) => [fieldName, JSON.stringify(val)]);
|
|
2642
|
+
query = query.whereRaw(`(${conditions})`, bindings);
|
|
2643
|
+
} else {
|
|
2644
|
+
query = query.whereIn(fieldName, operators.in);
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
if (operators.contains !== void 0) {
|
|
2648
|
+
if (isJsonField) {
|
|
2649
|
+
query = query.whereRaw(`?? @> ?::jsonb`, [fieldName, JSON.stringify(operators.contains)]);
|
|
2650
|
+
} else {
|
|
2651
|
+
query = query.where(fieldName, "ilike", `%${operators.contains}%`);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
if (operators.lte !== void 0) {
|
|
2655
|
+
console.log("[EXULU] operators.lte", operators.lte);
|
|
2656
|
+
console.log("[EXULU] fieldName", fieldName);
|
|
2657
|
+
if (operators.lte === 0 || operators.lte === "0") {
|
|
2658
|
+
query = query.whereNull(fieldName).orWhere(fieldName, "=", 0);
|
|
2659
|
+
} else {
|
|
2660
|
+
query = query.where(fieldName, "<=", operators.lte);
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
if (operators.gte !== void 0) {
|
|
2664
|
+
query = query.where(fieldName, ">=", operators.gte);
|
|
2665
|
+
}
|
|
2666
|
+
return query;
|
|
2667
|
+
};
|
|
2668
|
+
|
|
2323
2669
|
// ee/agentic-retrieval/pipeline/multi-query.ts
|
|
2324
2670
|
async function singleSearch({
|
|
2325
2671
|
query,
|
|
@@ -2350,6 +2696,7 @@ async function singleSearch({
|
|
|
2350
2696
|
});
|
|
2351
2697
|
return results.chunks || [];
|
|
2352
2698
|
} catch (e) {
|
|
2699
|
+
if (e instanceof UnknownFilterPathError) throw e;
|
|
2353
2700
|
console.warn("[EXULU] singleSearch failed for query:", query, e);
|
|
2354
2701
|
return [];
|
|
2355
2702
|
}
|
|
@@ -2589,6 +2936,7 @@ async function searchContexts(opts) {
|
|
|
2589
2936
|
}
|
|
2590
2937
|
return [];
|
|
2591
2938
|
} catch (err3) {
|
|
2939
|
+
if (err3 instanceof UnknownFilterPathError) throw err3;
|
|
2592
2940
|
if (isEmbedderNotConfigured(err3)) {
|
|
2593
2941
|
console.warn(
|
|
2594
2942
|
`[EXULU pipeline] context "${ctxId}" is not searchable: ${err3.message}`
|
|
@@ -3098,11 +3446,11 @@ function createAgenticRetrievalTool(opts) {
|
|
|
3098
3446
|
default: '{"enabled":false,"model":"","fidelity":"fast","thresholds":{"warn":0.1,"alert":0.3}}'
|
|
3099
3447
|
}
|
|
3100
3448
|
],
|
|
3101
|
-
inputSchema:
|
|
3102
|
-
userQuery:
|
|
3103
|
-
relevantKeywords:
|
|
3104
|
-
importantKeyword:
|
|
3105
|
-
confirmedContextIds:
|
|
3449
|
+
inputSchema: z8.object({
|
|
3450
|
+
userQuery: z8.string().describe("The original unaltered question from the user"),
|
|
3451
|
+
relevantKeywords: z8.array(z8.string()).describe("Keywords extracted from the user's question relevant to the search"),
|
|
3452
|
+
importantKeyword: z8.string().describe("The single most important keyword from the user's question"),
|
|
3453
|
+
confirmedContextIds: z8.array(z8.string()).optional().describe(
|
|
3106
3454
|
"Knowledge base IDs explicitly confirmed by the user to be used in the retrieval. When present, only searches these contexts."
|
|
3107
3455
|
)
|
|
3108
3456
|
}),
|
|
@@ -3520,6 +3868,18 @@ Verified answer:
|
|
|
3520
3868
|
yield { result: serializeOutput(result, hideSources) };
|
|
3521
3869
|
return { result: serializeOutput(result, hideSources) };
|
|
3522
3870
|
} catch (err3) {
|
|
3871
|
+
if (err3 instanceof UnknownFilterPathError) {
|
|
3872
|
+
console.warn("[EXULU pipeline] retrieval refused an unknown json filter path:", err3.message);
|
|
3873
|
+
result.steps.push({
|
|
3874
|
+
stepNumber: 1,
|
|
3875
|
+
text: err3.message,
|
|
3876
|
+
toolCalls: [],
|
|
3877
|
+
chunks: [],
|
|
3878
|
+
tokens: 0
|
|
3879
|
+
});
|
|
3880
|
+
yield { result: serializeOutput(result, hideSources) };
|
|
3881
|
+
return;
|
|
3882
|
+
}
|
|
3523
3883
|
console.warn("[EXULU pipeline] retrieval pipeline failed:", err3);
|
|
3524
3884
|
result.steps.push({
|
|
3525
3885
|
stepNumber: 1,
|
|
@@ -3572,7 +3932,7 @@ var STATISTICS_TYPE_ENUM = {
|
|
|
3572
3932
|
};
|
|
3573
3933
|
|
|
3574
3934
|
// src/exulu/memory/tools.ts
|
|
3575
|
-
import { z as
|
|
3935
|
+
import { z as z10 } from "zod";
|
|
3576
3936
|
|
|
3577
3937
|
// src/exulu/memory/creator-id.ts
|
|
3578
3938
|
function creatorId(value) {
|
|
@@ -5351,6 +5711,166 @@ var defaultChunker = async (item, maxChunkSize) => {
|
|
|
5351
5711
|
return { item, chunks };
|
|
5352
5712
|
};
|
|
5353
5713
|
|
|
5714
|
+
// src/exulu/item-write.ts
|
|
5715
|
+
function isPlainObject2(value) {
|
|
5716
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5717
|
+
}
|
|
5718
|
+
function describeKind(value) {
|
|
5719
|
+
if (value === null) return "null";
|
|
5720
|
+
if (value === void 0) return "undefined";
|
|
5721
|
+
if (Array.isArray(value)) return "an array";
|
|
5722
|
+
const kind = typeof value;
|
|
5723
|
+
return /^[aeiou]/.test(kind) ? `an ${kind}` : `a ${kind}`;
|
|
5724
|
+
}
|
|
5725
|
+
function hasOwnKey(target, key) {
|
|
5726
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
5727
|
+
}
|
|
5728
|
+
function safeStringify(value) {
|
|
5729
|
+
try {
|
|
5730
|
+
return JSON.stringify(value);
|
|
5731
|
+
} catch {
|
|
5732
|
+
return String(value);
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
function omitNullEntries(value) {
|
|
5736
|
+
const filtered = /* @__PURE__ */ Object.create(null);
|
|
5737
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
5738
|
+
if (inner !== null) filtered[key] = inner;
|
|
5739
|
+
}
|
|
5740
|
+
return filtered;
|
|
5741
|
+
}
|
|
5742
|
+
function mergeClearRefusalMessage(fieldName) {
|
|
5743
|
+
return `Write to field "${fieldName}" rejected: a merge patch's own value cannot be null. A bare null here would clear the entire field, and clearing a field is a replace, not a merge. To clear "${fieldName}" entirely, resend it WITHOUT "merge". To delete specific keys instead, keep merging and set only those keys' values to null.`;
|
|
5744
|
+
}
|
|
5745
|
+
function requiredNullRefusalMessage(fieldName) {
|
|
5746
|
+
return `Write to field "${fieldName}" rejected: this field is required and cannot be null. Send a value for "${fieldName}", or omit it from this write to leave it unchanged.`;
|
|
5747
|
+
}
|
|
5748
|
+
function mergeNonObjectRefusalMessage(fieldName, value) {
|
|
5749
|
+
const kind = describeKind(value);
|
|
5750
|
+
return `Write to field "${fieldName}" rejected: a merge patch must be a JSON object with named keys, but ${kind} was sent (${safeStringify(value)}). A merge patch cannot be ${kind} \u2014 only its object keys are merged. To replace "${fieldName}" entirely with ${kind}, resend it WITHOUT "merge".`;
|
|
5751
|
+
}
|
|
5752
|
+
function mergeStoredNonObjectRefusalMessage(fieldName, stored) {
|
|
5753
|
+
const kind = describeKind(stored);
|
|
5754
|
+
return `Write to field "${fieldName}" rejected: the STORED value is ${kind}, not a JSON object with named keys (${safeStringify(stored)}), so a merge patch cannot be combined into it. A merge combines keys into an EXISTING object; "${fieldName}" does not currently hold one. To replace "${fieldName}" entirely, resend it WITHOUT "merge".`;
|
|
5755
|
+
}
|
|
5756
|
+
function stringParseFailedMessage(fieldName, raw, schema) {
|
|
5757
|
+
const base = `Write to field "${fieldName}" rejected: the value is a string, but it does not parse as JSON (${safeStringify(raw)}). A json field may be sent as a serialized JSON string, but the string itself must be valid JSON.`;
|
|
5758
|
+
if (!schema) return base;
|
|
5759
|
+
const validPaths = schemaPaths(schema);
|
|
5760
|
+
const validList = validPaths.length > 0 ? validPaths.join(", ") : "(the schema declares no paths)";
|
|
5761
|
+
return `${base} Valid paths for "${fieldName}": ${validList}.`;
|
|
5762
|
+
}
|
|
5763
|
+
function shapeRefusalMessage(fieldName, value, schema) {
|
|
5764
|
+
const kind = describeKind(value);
|
|
5765
|
+
const validPaths = schemaPaths(schema);
|
|
5766
|
+
const validList = validPaths.length > 0 ? validPaths.join(", ") : "(the schema declares no paths)";
|
|
5767
|
+
return `Write to field "${fieldName}" rejected: the value must be a JSON object with named keys, but ${kind} was sent (${safeStringify(value)}). Valid paths for "${fieldName}": ${validList}.`;
|
|
5768
|
+
}
|
|
5769
|
+
function mergeUnknownFieldMessage(name, reason, mergeableNames) {
|
|
5770
|
+
const availableList = mergeableNames.length > 0 ? mergeableNames.map((mergeable) => `"${mergeable}"`).join(", ") : "(none \u2014 this write sends no json field, so there is nothing to merge into)";
|
|
5771
|
+
const why = reason === "not-json" ? `"${name}" is not a json field of this item` : `"${name}" is a json field but this write sends no value for it`;
|
|
5772
|
+
return `Write rejected: "merge" names "${name}", but ${why}. Every name in "merge" must be a json field that this same write sends a value for \u2014 an unmatched name would otherwise silently REPLACE that field instead of merging into it, deleting every stored key the value sent does not mention. json fields this write can merge into: ${availableList}.`;
|
|
5773
|
+
}
|
|
5774
|
+
function missingKeysRefusalMessage(fieldName, missing, schema) {
|
|
5775
|
+
const plural = missing.length > 1;
|
|
5776
|
+
const missingList = missing.map((key) => `"${key}"`).join(", ");
|
|
5777
|
+
const validPaths = schemaPaths(schema);
|
|
5778
|
+
const validList = validPaths.length > 0 ? validPaths.join(", ") : "(the schema declares no paths)";
|
|
5779
|
+
return `Write to field "${fieldName}" rejected: required ${plural ? "keys" : "key"} ${missingList} ${plural ? "are" : "is"} missing. This write REPLACES "${fieldName}" (it is not named in "merge"), so the value sent must be complete. To change only some keys and keep the rest, resend this write with "merge": ["${fieldName}"]. To clear "${fieldName}" entirely, send {}. Valid paths for "${fieldName}": ${validList}.`;
|
|
5780
|
+
}
|
|
5781
|
+
function refusalMessage(fieldName, badPaths, schema) {
|
|
5782
|
+
const plural = badPaths.length > 1;
|
|
5783
|
+
const badList = badPaths.map((path3) => `"${path3}"`).join(", ");
|
|
5784
|
+
const validPaths = schemaPaths(schema);
|
|
5785
|
+
const validList = validPaths.length > 0 ? validPaths.join(", ") : "(the schema declares no paths)";
|
|
5786
|
+
return `Write to field "${fieldName}" rejected: ${plural ? "paths" : "path"} ${badList} ${plural ? "do" : "does"} not match the shape declared for "${fieldName}". Valid paths for "${fieldName}": ${validList}.`;
|
|
5787
|
+
}
|
|
5788
|
+
function leafRefusalMessage(fieldName, violations) {
|
|
5789
|
+
const parts = violations.map((violation) => {
|
|
5790
|
+
const got = safeStringify(violation.received);
|
|
5791
|
+
return `"${fieldName}.${violation.path}": ${violation.expected} (got ${got})`;
|
|
5792
|
+
});
|
|
5793
|
+
return `Write to field "${fieldName}" rejected: ${parts.join("; ")}.`;
|
|
5794
|
+
}
|
|
5795
|
+
function prepareItemWrite(args) {
|
|
5796
|
+
const { fields, existing, input, merge } = args;
|
|
5797
|
+
const fieldsByName = new Map(fields.map((field) => [field.name, field]));
|
|
5798
|
+
const values = {};
|
|
5799
|
+
if (merge && merge.length > 0) {
|
|
5800
|
+
const mergeableNames = Object.keys(input).filter((name) => fieldsByName.get(name)?.type === "json");
|
|
5801
|
+
for (const name of merge) {
|
|
5802
|
+
if (fieldsByName.get(name)?.type !== "json") {
|
|
5803
|
+
return { ok: false, message: mergeUnknownFieldMessage(String(name), "not-json", mergeableNames) };
|
|
5804
|
+
}
|
|
5805
|
+
if (!hasOwnKey(input, name)) {
|
|
5806
|
+
return { ok: false, message: mergeUnknownFieldMessage(String(name), "absent", mergeableNames) };
|
|
5807
|
+
}
|
|
5808
|
+
}
|
|
5809
|
+
}
|
|
5810
|
+
for (const [key, value] of Object.entries(input)) {
|
|
5811
|
+
const field = fieldsByName.get(key);
|
|
5812
|
+
const schema = field?.type === "json" ? field.schema : void 0;
|
|
5813
|
+
const isMergeField = field?.type === "json" && (merge?.includes(key) ?? false);
|
|
5814
|
+
let checkValue = value;
|
|
5815
|
+
let stringParseFailed = false;
|
|
5816
|
+
if (field?.type === "json" && typeof value === "string") {
|
|
5817
|
+
try {
|
|
5818
|
+
checkValue = JSON.parse(value);
|
|
5819
|
+
} catch {
|
|
5820
|
+
stringParseFailed = true;
|
|
5821
|
+
}
|
|
5822
|
+
}
|
|
5823
|
+
if (isMergeField && checkValue === null) {
|
|
5824
|
+
return { ok: false, message: mergeClearRefusalMessage(key) };
|
|
5825
|
+
}
|
|
5826
|
+
if (!isMergeField && field?.type === "json" && checkValue === null) {
|
|
5827
|
+
if (schema && field.required === true) {
|
|
5828
|
+
return { ok: false, message: requiredNullRefusalMessage(key) };
|
|
5829
|
+
}
|
|
5830
|
+
Object.defineProperty(values, key, { value, writable: true, enumerable: true, configurable: true });
|
|
5831
|
+
continue;
|
|
5832
|
+
}
|
|
5833
|
+
if (stringParseFailed && (isMergeField || schema && requiresPlainObject(schema))) {
|
|
5834
|
+
return { ok: false, message: stringParseFailedMessage(key, value, schema) };
|
|
5835
|
+
}
|
|
5836
|
+
if (isMergeField && (!schema || !requiresPlainObject(schema)) && !isPlainObject2(checkValue)) {
|
|
5837
|
+
return { ok: false, message: mergeNonObjectRefusalMessage(key, checkValue) };
|
|
5838
|
+
}
|
|
5839
|
+
if (isMergeField && isPlainObject2(checkValue)) {
|
|
5840
|
+
const stored = existing?.[key];
|
|
5841
|
+
if (stored !== null && stored !== void 0 && !isPlainObject2(stored)) {
|
|
5842
|
+
return { ok: false, message: mergeStoredNonObjectRefusalMessage(key, stored) };
|
|
5843
|
+
}
|
|
5844
|
+
}
|
|
5845
|
+
if (schema) {
|
|
5846
|
+
if (requiresPlainObject(schema) && !isPlainObject2(checkValue) && !schema.safeParse(checkValue).success) {
|
|
5847
|
+
return { ok: false, message: shapeRefusalMessage(key, checkValue, schema) };
|
|
5848
|
+
}
|
|
5849
|
+
const toValidate = isMergeField && isPlainObject2(checkValue) ? omitNullEntries(checkValue) : checkValue;
|
|
5850
|
+
const badPaths = unknownPaths(schema, toValidate);
|
|
5851
|
+
if (badPaths.length > 0) {
|
|
5852
|
+
return { ok: false, message: refusalMessage(key, badPaths, schema) };
|
|
5853
|
+
}
|
|
5854
|
+
const violations = leafViolations(schema, toValidate);
|
|
5855
|
+
if (violations.length > 0) {
|
|
5856
|
+
return { ok: false, message: leafRefusalMessage(key, violations) };
|
|
5857
|
+
}
|
|
5858
|
+
if (!isMergeField && isPlainObject2(checkValue) && Object.keys(checkValue).length > 0) {
|
|
5859
|
+
const missing = missingRequiredKeys(schema, checkValue);
|
|
5860
|
+
if (missing.length > 0) {
|
|
5861
|
+
return { ok: false, message: missingKeysRefusalMessage(key, missing, schema) };
|
|
5862
|
+
}
|
|
5863
|
+
}
|
|
5864
|
+
}
|
|
5865
|
+
if (isMergeField && isPlainObject2(checkValue)) {
|
|
5866
|
+
Object.defineProperty(values, key, { value: mergeJson(existing?.[key], checkValue), writable: true, enumerable: true, configurable: true });
|
|
5867
|
+
} else {
|
|
5868
|
+
Object.defineProperty(values, key, { value, writable: true, enumerable: true, configurable: true });
|
|
5869
|
+
}
|
|
5870
|
+
}
|
|
5871
|
+
return { ok: true, values };
|
|
5872
|
+
}
|
|
5873
|
+
|
|
5354
5874
|
// src/exulu/litellm/parse-embedding-models.ts
|
|
5355
5875
|
import { existsSync, readFileSync } from "fs";
|
|
5356
5876
|
import { resolve } from "path";
|
|
@@ -5633,14 +6153,14 @@ function randomizedPCA(rows, dims, k, seed, iterations) {
|
|
|
5633
6153
|
for (const row of rows) {
|
|
5634
6154
|
const centered = new Float64Array(dims);
|
|
5635
6155
|
for (let d = 0; d < dims; d += 1) centered[d] = (row[d] ?? 0) - (mean[d] ?? 0);
|
|
5636
|
-
const
|
|
6156
|
+
const z18 = new Float64Array(basis.length);
|
|
5637
6157
|
for (const [b, vec] of basis.entries()) {
|
|
5638
6158
|
let dot = 0;
|
|
5639
6159
|
for (let d = 0; d < dims; d += 1) dot += (centered[d] ?? 0) * (vec[d] ?? 0);
|
|
5640
|
-
|
|
6160
|
+
z18[b] = dot;
|
|
5641
6161
|
}
|
|
5642
6162
|
for (const [b, target] of next.entries()) {
|
|
5643
|
-
const scale =
|
|
6163
|
+
const scale = z18[b] ?? 0;
|
|
5644
6164
|
if (scale === 0) continue;
|
|
5645
6165
|
for (let d = 0; d < dims; d += 1) target[d] = (target[d] ?? 0) + (centered[d] ?? 0) * scale;
|
|
5646
6166
|
}
|
|
@@ -5738,12 +6258,12 @@ function ridgeFit(Z, Y, lambda) {
|
|
|
5738
6258
|
});
|
|
5739
6259
|
return { map, intercept };
|
|
5740
6260
|
}
|
|
5741
|
-
function applyMap(
|
|
6261
|
+
function applyMap(z18, map, intercept) {
|
|
5742
6262
|
const out = [];
|
|
5743
6263
|
for (let j = 0; j < 3; j += 1) {
|
|
5744
6264
|
let v = intercept[j] ?? 0;
|
|
5745
6265
|
const row = map[j] ?? [];
|
|
5746
|
-
for (let d = 0; d < row.length; d += 1) v += (row[d] ?? 0) * (
|
|
6266
|
+
for (let d = 0; d < row.length; d += 1) v += (row[d] ?? 0) * (z18[d] ?? 0);
|
|
5747
6267
|
out.push(Number.isFinite(v) ? v : 0);
|
|
5748
6268
|
}
|
|
5749
6269
|
return [out[0] ?? 0, out[1] ?? 0, out[2] ?? 0];
|
|
@@ -5766,8 +6286,8 @@ function fitResidual(Z, Y, map, intercept) {
|
|
|
5766
6286
|
for (let i = 0; i < Z.length; i += 1) {
|
|
5767
6287
|
const zi = Z[i] ?? [];
|
|
5768
6288
|
const yi = Y[i] ?? [];
|
|
5769
|
-
const [x, y,
|
|
5770
|
-
total += Math.hypot(x - finite(yi[0]), y - finite(yi[1]),
|
|
6289
|
+
const [x, y, z18] = applyMap(zi, map, intercept);
|
|
6290
|
+
total += Math.hypot(x - finite(yi[0]), y - finite(yi[1]), z18 - finite(yi[2]));
|
|
5771
6291
|
}
|
|
5772
6292
|
return finite(total / Z.length);
|
|
5773
6293
|
}
|
|
@@ -5907,8 +6427,8 @@ async function chunkCoordinates({
|
|
|
5907
6427
|
}
|
|
5908
6428
|
return null;
|
|
5909
6429
|
}
|
|
5910
|
-
const [x, y,
|
|
5911
|
-
return { x, y, z:
|
|
6430
|
+
const [x, y, z18] = applyMap(projectComponents(l2normalize(v), mean, basis), projection.map, projection.intercept);
|
|
6431
|
+
return { x, y, z: z18 };
|
|
5912
6432
|
});
|
|
5913
6433
|
} catch (e) {
|
|
5914
6434
|
console.error("[EXULU] could not compute chunk coordinates", e instanceof Error ? e.message : String(e));
|
|
@@ -6348,61 +6868,6 @@ var applyAccessControl = (table, query, user, field_prefix) => {
|
|
|
6348
6868
|
return query;
|
|
6349
6869
|
};
|
|
6350
6870
|
|
|
6351
|
-
// src/graphql/utilities/convert-graphql-filter-operator-to-pg-query.ts
|
|
6352
|
-
var convertGraphqlOperatorToPostgresQuery = (query, fieldName, operators, table, field_prefix) => {
|
|
6353
|
-
const field = table?.fields.find((f) => f.name === fieldName);
|
|
6354
|
-
const isJsonField = field?.type === "json";
|
|
6355
|
-
const prefix = field_prefix ? field_prefix + "." : "";
|
|
6356
|
-
fieldName = prefix + fieldName;
|
|
6357
|
-
console.log("[EXULU] operators", operators);
|
|
6358
|
-
if (operators.eq !== void 0) {
|
|
6359
|
-
if (isJsonField) {
|
|
6360
|
-
query = query.whereRaw(`?? = ?::jsonb`, [fieldName, JSON.stringify(operators.eq)]);
|
|
6361
|
-
} else {
|
|
6362
|
-
query = query.where(fieldName, operators.eq);
|
|
6363
|
-
}
|
|
6364
|
-
}
|
|
6365
|
-
if (operators.ne !== void 0) {
|
|
6366
|
-
if (isJsonField) {
|
|
6367
|
-
query = query.whereRaw(`?? IS DISTINCT FROM ?::jsonb`, [
|
|
6368
|
-
fieldName,
|
|
6369
|
-
JSON.stringify(operators.ne)
|
|
6370
|
-
]);
|
|
6371
|
-
} else {
|
|
6372
|
-
query = query.whereRaw(`?? IS DISTINCT FROM ?`, [fieldName, operators.ne]);
|
|
6373
|
-
}
|
|
6374
|
-
}
|
|
6375
|
-
if (operators.in !== void 0) {
|
|
6376
|
-
if (isJsonField) {
|
|
6377
|
-
const conditions = operators.in.map(() => `?? = ?::jsonb`).join(" OR ");
|
|
6378
|
-
const bindings = operators.in.flatMap((val) => [fieldName, JSON.stringify(val)]);
|
|
6379
|
-
query = query.whereRaw(`(${conditions})`, bindings);
|
|
6380
|
-
} else {
|
|
6381
|
-
query = query.whereIn(fieldName, operators.in);
|
|
6382
|
-
}
|
|
6383
|
-
}
|
|
6384
|
-
if (operators.contains !== void 0) {
|
|
6385
|
-
if (isJsonField) {
|
|
6386
|
-
query = query.whereRaw(`?? @> ?::jsonb`, [fieldName, JSON.stringify(operators.contains)]);
|
|
6387
|
-
} else {
|
|
6388
|
-
query = query.where(fieldName, "ilike", `%${operators.contains}%`);
|
|
6389
|
-
}
|
|
6390
|
-
}
|
|
6391
|
-
if (operators.lte !== void 0) {
|
|
6392
|
-
console.log("[EXULU] operators.lte", operators.lte);
|
|
6393
|
-
console.log("[EXULU] fieldName", fieldName);
|
|
6394
|
-
if (operators.lte === 0 || operators.lte === "0") {
|
|
6395
|
-
query = query.whereNull(fieldName).orWhere(fieldName, "=", 0);
|
|
6396
|
-
} else {
|
|
6397
|
-
query = query.where(fieldName, "<=", operators.lte);
|
|
6398
|
-
}
|
|
6399
|
-
}
|
|
6400
|
-
if (operators.gte !== void 0) {
|
|
6401
|
-
query = query.where(fieldName, ">=", operators.gte);
|
|
6402
|
-
}
|
|
6403
|
-
return query;
|
|
6404
|
-
};
|
|
6405
|
-
|
|
6406
6871
|
// src/graphql/resolvers/apply-filters.ts
|
|
6407
6872
|
var applyFilters = (query, filters, table, field_prefix) => {
|
|
6408
6873
|
if (!filters) {
|
|
@@ -6575,29 +7040,29 @@ var resolveEntityModel = async (context) => {
|
|
|
6575
7040
|
|
|
6576
7041
|
// src/exulu/entities/extractor.ts
|
|
6577
7042
|
import { generateText as generateText2, Output as Output2 } from "ai";
|
|
6578
|
-
import { z as
|
|
7043
|
+
import { z as z9 } from "zod";
|
|
6579
7044
|
var CHUNK_BATCH_SIZE = 30;
|
|
6580
7045
|
var MAX_SUGGESTIONS = 5;
|
|
6581
|
-
var mentionSchema =
|
|
6582
|
-
entities:
|
|
6583
|
-
|
|
6584
|
-
chunkIndex:
|
|
6585
|
-
type:
|
|
6586
|
-
mention:
|
|
6587
|
-
canonical:
|
|
6588
|
-
confidence:
|
|
7046
|
+
var mentionSchema = z9.object({
|
|
7047
|
+
entities: z9.array(
|
|
7048
|
+
z9.object({
|
|
7049
|
+
chunkIndex: z9.number().int().describe("Index of the chunk this entity was found in."),
|
|
7050
|
+
type: z9.string().describe("One of the provided entity type names."),
|
|
7051
|
+
mention: z9.string().describe("The exact surface form as it appears in the text."),
|
|
7052
|
+
canonical: z9.string().describe("The canonical, language-normalized name used to merge variants."),
|
|
7053
|
+
confidence: z9.number().min(0).max(1).describe("Confidence 0..1 that this is a valid entity.")
|
|
6589
7054
|
})
|
|
6590
7055
|
),
|
|
6591
|
-
suggestedTypes:
|
|
6592
|
-
|
|
6593
|
-
name:
|
|
6594
|
-
description:
|
|
6595
|
-
mentions:
|
|
6596
|
-
|
|
6597
|
-
chunkIndex:
|
|
6598
|
-
mention:
|
|
6599
|
-
canonical:
|
|
6600
|
-
confidence:
|
|
7056
|
+
suggestedTypes: z9.array(
|
|
7057
|
+
z9.object({
|
|
7058
|
+
name: z9.string().describe("A concise NEW entity type name, e.g. 'Error Code', 'Component'."),
|
|
7059
|
+
description: z9.string().describe("What this type captures, one sentence."),
|
|
7060
|
+
mentions: z9.array(
|
|
7061
|
+
z9.object({
|
|
7062
|
+
chunkIndex: z9.number().int().describe("Index of the chunk this mention was found in."),
|
|
7063
|
+
mention: z9.string().describe("The exact surface form as it appears in the text."),
|
|
7064
|
+
canonical: z9.string().describe("Canonical, language-normalized name."),
|
|
7065
|
+
confidence: z9.number().min(0).max(1).describe("Confidence 0..1.")
|
|
6601
7066
|
})
|
|
6602
7067
|
).describe("Every mention of this new type found in the provided chunks.")
|
|
6603
7068
|
})
|
|
@@ -8159,6 +8624,10 @@ var ExuluContext2 = class {
|
|
|
8159
8624
|
}
|
|
8160
8625
|
item.rights_mode = sanitizeItemRightsMode(item.rights_mode, this.configuration.defaultRightsMode);
|
|
8161
8626
|
const { db } = await postgresClient();
|
|
8627
|
+
const createValidation = prepareItemWrite({ fields: this.fields, existing: null, input: item });
|
|
8628
|
+
if (!createValidation.ok) {
|
|
8629
|
+
throw new Error(createValidation.message);
|
|
8630
|
+
}
|
|
8162
8631
|
Object.keys(item).forEach((key) => {
|
|
8163
8632
|
if (this.fields.find((field) => field.name === key)?.type === "json") {
|
|
8164
8633
|
if (typeof item[key] === "object" || Array.isArray(item[key])) {
|
|
@@ -8235,7 +8704,7 @@ var ExuluContext2 = class {
|
|
|
8235
8704
|
job: jobs.length > 0 ? jobs.join(",") : void 0
|
|
8236
8705
|
};
|
|
8237
8706
|
};
|
|
8238
|
-
updateItem = async (item, config, user, role, generateEmbeddingsOverwrite, runProcessorOverwrite) => {
|
|
8707
|
+
updateItem = async (item, config, user, role, generateEmbeddingsOverwrite, runProcessorOverwrite, merge) => {
|
|
8239
8708
|
console.log("[EXULU] updating item", item);
|
|
8240
8709
|
const { db } = await postgresClient();
|
|
8241
8710
|
if (item.field) {
|
|
@@ -8245,16 +8714,26 @@ var ExuluContext2 = class {
|
|
|
8245
8714
|
if (!record) {
|
|
8246
8715
|
throw new Error("Item not found.");
|
|
8247
8716
|
}
|
|
8248
|
-
|
|
8717
|
+
const prepared = prepareItemWrite({
|
|
8718
|
+
fields: this.fields,
|
|
8719
|
+
existing: record,
|
|
8720
|
+
input: item,
|
|
8721
|
+
merge
|
|
8722
|
+
});
|
|
8723
|
+
if (!prepared.ok) {
|
|
8724
|
+
throw new Error(prepared.message);
|
|
8725
|
+
}
|
|
8726
|
+
const values = prepared.values;
|
|
8727
|
+
Object.keys(values).forEach((key) => {
|
|
8249
8728
|
if (this.fields.find((field) => field.name === key)?.type === "json") {
|
|
8250
|
-
if (typeof
|
|
8251
|
-
|
|
8729
|
+
if (typeof values[key] === "object" || Array.isArray(values[key])) {
|
|
8730
|
+
values[key] = JSON.stringify(values[key]);
|
|
8252
8731
|
}
|
|
8253
8732
|
}
|
|
8254
8733
|
});
|
|
8255
8734
|
const mutation = db.from(getTableName(this.id)).where({ id: record.id }).update({
|
|
8256
|
-
...
|
|
8257
|
-
tags:
|
|
8735
|
+
...values,
|
|
8736
|
+
tags: values.tags ? Array.isArray(values.tags) ? values.tags.join(",") : values.tags : void 0
|
|
8258
8737
|
}).returning("id");
|
|
8259
8738
|
await mutation;
|
|
8260
8739
|
let jobs = [];
|
|
@@ -8265,7 +8744,17 @@ var ExuluContext2 = class {
|
|
|
8265
8744
|
const { job: processorJob, result: processorResult } = await this.processField(
|
|
8266
8745
|
"api",
|
|
8267
8746
|
{
|
|
8268
|
-
|
|
8747
|
+
// `values`, not `item` (coordinator ruling, Task 4 fix round 1):
|
|
8748
|
+
// the fence on "don't change processor behaviour" is about WHEN
|
|
8749
|
+
// a processor fires, not WHAT it sees once it does. Before
|
|
8750
|
+
// merge existed, the patch WAS the result, so this was never a
|
|
8751
|
+
// live distinction; `mv_pitches`'s processor (trigger: "always")
|
|
8752
|
+
// is the first real consumer of a merge-listed json field, so a
|
|
8753
|
+
// processor seeing a bare patch instead of the full merged
|
|
8754
|
+
// object is live, not latent. `values` carries the SAME keys
|
|
8755
|
+
// `item` did -- unchanged values pass through by reference --
|
|
8756
|
+
// so this is a no-op for every call that doesn't use `merge`.
|
|
8757
|
+
...values,
|
|
8269
8758
|
id: record.id
|
|
8270
8759
|
},
|
|
8271
8760
|
config,
|
|
@@ -10332,7 +10821,20 @@ var convertContextToTableDefinition = (context) => {
|
|
|
10332
10821
|
index: field.index,
|
|
10333
10822
|
enumValues: field.enumValues,
|
|
10334
10823
|
allowedFileTypes: field.allowedFileTypes,
|
|
10335
|
-
unique: field.unique
|
|
10824
|
+
unique: field.unique,
|
|
10825
|
+
// Task 4 fix round 2, Critical: without this, every context item
|
|
10826
|
+
// table's fields lose their declared json schema on the way into
|
|
10827
|
+
// createMutations/createQueries -- the GraphQL write path (and
|
|
10828
|
+
// vector-search.ts's filter path, Task 5) would see `schema:
|
|
10829
|
+
// undefined` for every field, no matter what the context declares.
|
|
10830
|
+
// This is an explicit allowlist with NO spread (by design, so a
|
|
10831
|
+
// write-only secret like `hidden` doesn't leak into read-side SDL by
|
|
10832
|
+
// accident) -- which also means every new ExuluContextFieldDefinition
|
|
10833
|
+
// property has to be added here deliberately. `hidden` itself is a
|
|
10834
|
+
// known, still-open instance of exactly this failure mode (not fixed
|
|
10835
|
+
// here -- out of this task's scope); `schema` must not become a
|
|
10836
|
+
// second one.
|
|
10837
|
+
schema: field.schema
|
|
10336
10838
|
}))
|
|
10337
10839
|
};
|
|
10338
10840
|
definition.fields.push({
|
|
@@ -10622,7 +11124,7 @@ async function findVisible(context, id, user) {
|
|
|
10622
11124
|
}
|
|
10623
11125
|
function createMemoryTools({ agent, context, user }) {
|
|
10624
11126
|
const types = memoryTypeValues(context);
|
|
10625
|
-
const typeSchema = types.length > 0 ?
|
|
11127
|
+
const typeSchema = types.length > 0 ? z10.enum(types) : z10.string();
|
|
10626
11128
|
const category = `${agent.name}_memory`;
|
|
10627
11129
|
const remember = new ExuluTool({
|
|
10628
11130
|
id: "memory_remember",
|
|
@@ -10632,12 +11134,12 @@ function createMemoryTools({ agent, context, user }) {
|
|
|
10632
11134
|
config: [],
|
|
10633
11135
|
needsApproval: true,
|
|
10634
11136
|
description: `Propose saving ONE fact, preference, decision or instruction the user shared to ${agent.name}'s long-term memory. The user reviews the wording and who can see it on a card before anything is saved; never ask about visibility yourself unless the user raised it, and never claim something was saved until this tool returns memory_saved. Call it once per fact, in the user's own words.`,
|
|
10635
|
-
inputSchema:
|
|
10636
|
-
title:
|
|
10637
|
-
information:
|
|
11137
|
+
inputSchema: z10.object({
|
|
11138
|
+
title: z10.string().describe("Short title, max 80 characters"),
|
|
11139
|
+
information: z10.string().describe("The fact in one or two sentences, in the user's own words"),
|
|
10638
11140
|
type: typeSchema.describe(`Memory type. One of: ${types.join(", ")}`),
|
|
10639
|
-
whySaved:
|
|
10640
|
-
visibility:
|
|
11141
|
+
whySaved: z10.string().describe("Why this is worth remembering: the question or topic that triggered it"),
|
|
11142
|
+
visibility: z10.enum(["private", "public"]).optional().describe("Only when the user explicitly said who may see it")
|
|
10641
11143
|
}),
|
|
10642
11144
|
execute: async (params) => {
|
|
10643
11145
|
const { user: u, exuluConfig, memoryDecision } = params;
|
|
@@ -10721,12 +11223,12 @@ function createMemoryTools({ agent, context, user }) {
|
|
|
10721
11223
|
config: [],
|
|
10722
11224
|
needsApproval: true,
|
|
10723
11225
|
description: `Propose a correction to an existing memory of ${agent.name} (use the item_id from the memory block). Only the person who saved it, people with write access, or admins can change it; otherwise the result names the creator so you can suggest asking them. The user confirms on a card before anything changes.`,
|
|
10724
|
-
inputSchema:
|
|
10725
|
-
memoryId:
|
|
10726
|
-
information:
|
|
10727
|
-
title:
|
|
11226
|
+
inputSchema: z10.object({
|
|
11227
|
+
memoryId: z10.string().describe("item_id of the memory to change"),
|
|
11228
|
+
information: z10.string().optional().describe("New wording, if it changes"),
|
|
11229
|
+
title: z10.string().optional(),
|
|
10728
11230
|
type: typeSchema.optional(),
|
|
10729
|
-
reason:
|
|
11231
|
+
reason: z10.string().describe("What the user said that contradicts or refines the memory")
|
|
10730
11232
|
}),
|
|
10731
11233
|
execute: async (params) => {
|
|
10732
11234
|
const { user: u, exuluConfig, memoryDecision } = params;
|
|
@@ -10765,9 +11267,9 @@ function createMemoryTools({ agent, context, user }) {
|
|
|
10765
11267
|
config: [],
|
|
10766
11268
|
needsApproval: true,
|
|
10767
11269
|
description: `Propose deleting one of ${agent.name}'s memories when the user asks to forget it (use the item_id from the memory block). Same access rule as update_memory; the user confirms on a card before anything is deleted.`,
|
|
10768
|
-
inputSchema:
|
|
10769
|
-
memoryId:
|
|
10770
|
-
reason:
|
|
11270
|
+
inputSchema: z10.object({
|
|
11271
|
+
memoryId: z10.string().describe("item_id of the memory to delete"),
|
|
11272
|
+
reason: z10.string().describe("What the user said")
|
|
10771
11273
|
}),
|
|
10772
11274
|
execute: async (params) => {
|
|
10773
11275
|
const { user: u } = params;
|
|
@@ -10863,7 +11365,7 @@ function collectMemoryDecisions(messages) {
|
|
|
10863
11365
|
}
|
|
10864
11366
|
|
|
10865
11367
|
// src/templates/tools/context-write-tools.ts
|
|
10866
|
-
import { z as
|
|
11368
|
+
import { z as z12 } from "zod";
|
|
10867
11369
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
10868
11370
|
|
|
10869
11371
|
// src/exulu/session-files.ts
|
|
@@ -10947,11 +11449,11 @@ var checkItemWriteAccess = async (context, record, user) => {
|
|
|
10947
11449
|
};
|
|
10948
11450
|
|
|
10949
11451
|
// src/templates/tools/kb-editor-config.ts
|
|
10950
|
-
import { z as
|
|
11452
|
+
import { z as z11 } from "zod";
|
|
10951
11453
|
var KB_EDITOR_TOOL_ID = "knowledge_base_editor";
|
|
10952
|
-
var permissionsSchema =
|
|
10953
|
-
create:
|
|
10954
|
-
update:
|
|
11454
|
+
var permissionsSchema = z11.object({
|
|
11455
|
+
create: z11.boolean().catch(false).default(false),
|
|
11456
|
+
update: z11.boolean().catch(false).default(false)
|
|
10955
11457
|
});
|
|
10956
11458
|
var emptyConfig = () => ({
|
|
10957
11459
|
enabled: false,
|
|
@@ -11022,21 +11524,22 @@ var buildWriteSchema = (context, mode) => {
|
|
|
11022
11524
|
const shape = {};
|
|
11023
11525
|
const contentKeys = [];
|
|
11024
11526
|
const fileFields = [];
|
|
11527
|
+
const jsonFieldNames = [];
|
|
11025
11528
|
const addContent = (key, schema, required) => {
|
|
11026
11529
|
shape[key] = required && mode === "create" ? schema : schema.optional();
|
|
11027
11530
|
contentKeys.push(key);
|
|
11028
11531
|
};
|
|
11029
11532
|
if (mode === "update") {
|
|
11030
|
-
shape["id"] =
|
|
11031
|
-
shape["external_id"] =
|
|
11533
|
+
shape["id"] = z12.string().optional().describe("The id of the item to update.");
|
|
11534
|
+
shape["external_id"] = z12.string().optional().describe("The external_id of the item to update, if the id is unknown. Lookup only \u2014 it is never changed.");
|
|
11032
11535
|
}
|
|
11033
|
-
addContent("name",
|
|
11034
|
-
addContent("description",
|
|
11035
|
-
addContent("tags",
|
|
11536
|
+
addContent("name", z12.string().describe("The name of the item."), true);
|
|
11537
|
+
addContent("description", z12.string().describe("A description of the item."), false);
|
|
11538
|
+
addContent("tags", z12.array(z12.string()).describe("Tags for the item."), false);
|
|
11036
11539
|
if (mode === "create") {
|
|
11037
11540
|
addContent(
|
|
11038
11541
|
"external_id",
|
|
11039
|
-
|
|
11542
|
+
z12.string().describe("An optional external identifier for the item, e.g. an id from a source system."),
|
|
11040
11543
|
false
|
|
11041
11544
|
);
|
|
11042
11545
|
}
|
|
@@ -11049,7 +11552,7 @@ var buildWriteSchema = (context, mode) => {
|
|
|
11049
11552
|
const allowed = (field.allowedFileTypes ?? []).map((ext) => ext.toLowerCase());
|
|
11050
11553
|
const column = `${field.name}_s3key`;
|
|
11051
11554
|
const allowedNote = allowed.length ? ` Allowed types: ${allowed.join(", ")}.` : "";
|
|
11052
|
-
shape[field.name] = (field.required === true && mode === "create" ?
|
|
11555
|
+
shape[field.name] = (field.required === true && mode === "create" ? z12.string() : z12.string().optional()).describe(
|
|
11053
11556
|
`The ${field.name} file: the bare name of a file from this session's files (as listed there, no path).${allowedNote}` + (mode === "update" ? " Omit to keep the current file." : "")
|
|
11054
11557
|
);
|
|
11055
11558
|
contentKeys.push(column);
|
|
@@ -11059,32 +11562,38 @@ var buildWriteSchema = (context, mode) => {
|
|
|
11059
11562
|
let schema;
|
|
11060
11563
|
switch (field.type) {
|
|
11061
11564
|
case "enum":
|
|
11062
|
-
schema =
|
|
11565
|
+
schema = z12.string().describe(
|
|
11063
11566
|
`The ${field.name} of the item. Must be one of: ${(field.enumValues ?? []).join(", ")}`
|
|
11064
11567
|
);
|
|
11065
11568
|
break;
|
|
11066
11569
|
case "json":
|
|
11067
|
-
|
|
11570
|
+
jsonFieldNames.push(field.name);
|
|
11571
|
+
schema = field.schema ? loosenForTransport(field.schema).describe(`The ${field.name} of the item.`) : z12.string().describe(`The ${field.name} of the item, as a valid JSON string.`);
|
|
11068
11572
|
break;
|
|
11069
11573
|
case "markdown":
|
|
11070
|
-
schema =
|
|
11574
|
+
schema = z12.string().describe(`The ${field.name} of the item, as a valid Markdown string.`);
|
|
11071
11575
|
break;
|
|
11072
11576
|
case "date":
|
|
11073
|
-
schema =
|
|
11577
|
+
schema = z12.string().describe(`The ${field.name} of the item, as an ISO-8601 date string.`);
|
|
11074
11578
|
break;
|
|
11075
11579
|
case "number":
|
|
11076
|
-
schema =
|
|
11580
|
+
schema = z12.number().describe(`The ${field.name} of the item.`);
|
|
11077
11581
|
break;
|
|
11078
11582
|
case "boolean":
|
|
11079
|
-
schema =
|
|
11583
|
+
schema = z12.boolean().describe(`The ${field.name} of the item.`);
|
|
11080
11584
|
break;
|
|
11081
11585
|
default:
|
|
11082
|
-
schema =
|
|
11586
|
+
schema = z12.string().describe(`The ${field.name} of the item.`);
|
|
11083
11587
|
break;
|
|
11084
11588
|
}
|
|
11085
11589
|
addContent(field.name, schema, field.required === true);
|
|
11086
11590
|
}
|
|
11087
|
-
|
|
11591
|
+
if (mode === "update" && jsonFieldNames.length > 0 && !shape["merge"]) {
|
|
11592
|
+
shape["merge"] = z12.array(z12.string()).optional().describe(
|
|
11593
|
+
`Names of json fields in THIS call (choose from: ${jsonFieldNames.join(", ")}) whose given value should be merged into the stored value instead of replacing it: only the keys given are changed, every other stored key is kept, and giving a key an explicit null value deletes just that key. Omit a field's name here (or omit "merge" entirely) to replace its whole value, as normal. Every name must be spelled exactly as listed above AND be a field you are sending a value for in this same call; a name that is neither is refused, not ignored. Do not run two merges on the same item at once: a merge reads the stored value and writes the combined result in two steps with no lock, so overlapping merges can lose one of them.`
|
|
11594
|
+
);
|
|
11595
|
+
}
|
|
11596
|
+
return { shape, contentKeys, fileFields, jsonFieldNames };
|
|
11088
11597
|
};
|
|
11089
11598
|
var BARE_FILENAME = /^[^/\\]+$/;
|
|
11090
11599
|
var attachSessionFiles = async (params, fileFields, deps) => {
|
|
@@ -11162,7 +11671,7 @@ var createContextWriteTools = (context, perms, skipApproval, deps = {}) => {
|
|
|
11162
11671
|
category: "knowledge_base_editing",
|
|
11163
11672
|
description: `Create a new item in the "${context.name}" knowledge base.${contextLabel}${fileNote}`,
|
|
11164
11673
|
type: "function",
|
|
11165
|
-
inputSchema:
|
|
11674
|
+
inputSchema: z12.object(shape),
|
|
11166
11675
|
config: [],
|
|
11167
11676
|
needsApproval: !skipApproval,
|
|
11168
11677
|
execute: async (params) => {
|
|
@@ -11215,7 +11724,7 @@ var createContextWriteTools = (context, perms, skipApproval, deps = {}) => {
|
|
|
11215
11724
|
category: "knowledge_base_editing",
|
|
11216
11725
|
description: `Update an existing item in the "${context.name}" knowledge base. Provide the item's id (or external_id) plus only the fields to change; omitted fields keep their values.${fileNote}`,
|
|
11217
11726
|
type: "function",
|
|
11218
|
-
inputSchema:
|
|
11727
|
+
inputSchema: z12.object(shape),
|
|
11219
11728
|
config: [],
|
|
11220
11729
|
needsApproval: !skipApproval,
|
|
11221
11730
|
execute: async (params) => {
|
|
@@ -11250,7 +11759,16 @@ var createContextWriteTools = (context, perms, skipApproval, deps = {}) => {
|
|
|
11250
11759
|
return { result: "No fields to update were provided." };
|
|
11251
11760
|
}
|
|
11252
11761
|
patch.id = existing.id;
|
|
11253
|
-
const
|
|
11762
|
+
const merge = Array.isArray(params.merge) ? params.merge : void 0;
|
|
11763
|
+
const { job } = await context.updateItem(
|
|
11764
|
+
patch,
|
|
11765
|
+
exuluConfig,
|
|
11766
|
+
user?.id,
|
|
11767
|
+
user?.role?.id,
|
|
11768
|
+
void 0,
|
|
11769
|
+
void 0,
|
|
11770
|
+
merge
|
|
11771
|
+
);
|
|
11254
11772
|
const fresh = await context.getItem({ item: { id: existing.id } });
|
|
11255
11773
|
const summary = { id: existing.id };
|
|
11256
11774
|
for (const key of contentKeys) {
|
|
@@ -11280,7 +11798,7 @@ var createKbEditorPickerTool = () => new ExuluTool({
|
|
|
11280
11798
|
category: "default",
|
|
11281
11799
|
description: "Let this agent create or update items in selected knowledge bases during chat, including attaching files from the session's files to file fields. Configure per knowledge base whether the agent may create and/or update items.",
|
|
11282
11800
|
type: "function",
|
|
11283
|
-
inputSchema:
|
|
11801
|
+
inputSchema: z12.object({}),
|
|
11284
11802
|
config: [
|
|
11285
11803
|
{
|
|
11286
11804
|
name: "knowledge_bases",
|
|
@@ -11319,7 +11837,7 @@ var collectKbWriteTools = (agent, contexts, deps = {}) => {
|
|
|
11319
11837
|
|
|
11320
11838
|
// src/templates/tools/skill-author-tools.ts
|
|
11321
11839
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
11322
|
-
import { z as
|
|
11840
|
+
import { z as z13 } from "zod";
|
|
11323
11841
|
|
|
11324
11842
|
// ee/rbac-resolver.ts
|
|
11325
11843
|
var RBACResolver = async (db, entityName, resourceId, rights_mode) => {
|
|
@@ -11623,7 +12141,7 @@ var createSkillAuthorTools = (agent, deps = {}) => {
|
|
|
11623
12141
|
config: [],
|
|
11624
12142
|
needsApproval: false,
|
|
11625
12143
|
description: "List the skills in this instance's library that the current user may read: name, description and current version. Use it before creating a skill to avoid duplicates, and before updating one.",
|
|
11626
|
-
inputSchema:
|
|
12144
|
+
inputSchema: z13.object({ query: z13.string().optional().describe("Optional substring to filter by name or description") }),
|
|
11627
12145
|
execute: async (params) => {
|
|
11628
12146
|
const { user } = params;
|
|
11629
12147
|
if (!user?.id) return err2("Skills require a signed-in user.");
|
|
@@ -11649,9 +12167,9 @@ var createSkillAuthorTools = (agent, deps = {}) => {
|
|
|
11649
12167
|
config: [],
|
|
11650
12168
|
needsApproval: false,
|
|
11651
12169
|
description: "Read a skill the user may access: its file list and the content of SKILL.md, or of one file by path. Use it before updating a skill so you change only what must change.",
|
|
11652
|
-
inputSchema:
|
|
11653
|
-
skill:
|
|
11654
|
-
path:
|
|
12170
|
+
inputSchema: z13.object({
|
|
12171
|
+
skill: z13.string().describe("The skill's name or id"),
|
|
12172
|
+
path: z13.string().optional().describe("A file path inside the skill to read instead of SKILL.md")
|
|
11655
12173
|
}),
|
|
11656
12174
|
execute: async (params) => {
|
|
11657
12175
|
const { user, exuluConfig } = params;
|
|
@@ -11696,10 +12214,10 @@ ${content}`
|
|
|
11696
12214
|
needsApproval: !config.skipApproval,
|
|
11697
12215
|
needsApprovalFn: approvalFn,
|
|
11698
12216
|
description: "Propose a NEW skill from a procedure the user just completed. Give it a short name, a one-line description, and its files: a SKILL.md with frontmatter and clear steps, plus reference files only where useful. The user confirms name, description and visibility on a card before anything is created; never claim it exists until this tool returns skill_created.",
|
|
11699
|
-
inputSchema:
|
|
11700
|
-
name:
|
|
11701
|
-
description:
|
|
11702
|
-
files:
|
|
12217
|
+
inputSchema: z13.object({
|
|
12218
|
+
name: z13.string().describe("Short, specific skill name (e.g. 'quarterly-report-from-crm')"),
|
|
12219
|
+
description: z13.string().describe("One line: what the skill does and when to use it"),
|
|
12220
|
+
files: z13.array(z13.object({ path: z13.string().describe("Relative path inside the skill, e.g. SKILL.md or references/checklist.md"), content: z13.string() })).min(1).describe("The skill's files; SKILL.md is required")
|
|
11703
12221
|
}),
|
|
11704
12222
|
execute: async (params) => {
|
|
11705
12223
|
const { user, exuluConfig } = params;
|
|
@@ -11765,12 +12283,12 @@ ${content}`
|
|
|
11765
12283
|
needsApproval: !config.skipApproval,
|
|
11766
12284
|
needsApprovalFn: approvalFn,
|
|
11767
12285
|
description: "Publish a new version of an existing skill the user may write: pass only the files to add or replace (full content each) and, optionally, paths to remove. Unchanged files carry over. Read the skill first with skill_read. The user confirms on a card; never claim the change happened until this tool returns skill_updated.",
|
|
11768
|
-
inputSchema:
|
|
11769
|
-
skill:
|
|
11770
|
-
files:
|
|
11771
|
-
deletePaths:
|
|
11772
|
-
description:
|
|
11773
|
-
label:
|
|
12286
|
+
inputSchema: z13.object({
|
|
12287
|
+
skill: z13.string().describe("The skill's name or id"),
|
|
12288
|
+
files: z13.array(z13.object({ path: z13.string(), content: z13.string() })).optional().describe("Files to add or replace, full content each"),
|
|
12289
|
+
deletePaths: z13.array(z13.string()).optional().describe("Paths to remove in the new version"),
|
|
12290
|
+
description: z13.string().optional().describe("A new one-line description, if it changed"),
|
|
12291
|
+
label: z13.string().optional().describe("A short label for this version, e.g. 'Added the review checklist'")
|
|
11774
12292
|
}),
|
|
11775
12293
|
execute: async (params) => {
|
|
11776
12294
|
const { user, exuluConfig } = params;
|
|
@@ -11847,7 +12365,7 @@ var createSkillAuthorPickerTool = () => new ExuluTool({
|
|
|
11847
12365
|
category: "default",
|
|
11848
12366
|
description: "Let this agent create skills and publish new versions of existing ones from the chat, with the user's consent on a card. Adds a system-prompt hint to offer a skill only after complex, recurring, multi-step work \u2014 never for a single question or correction.",
|
|
11849
12367
|
type: "function",
|
|
11850
|
-
inputSchema:
|
|
12368
|
+
inputSchema: z13.object({}),
|
|
11851
12369
|
config: [
|
|
11852
12370
|
{ name: "create", description: "The agent may propose new skills.", type: "boolean", default: true },
|
|
11853
12371
|
{ name: "update", description: "The agent may publish new versions of skills the user can write.", type: "boolean", default: true },
|
|
@@ -12816,7 +13334,7 @@ var buildSkillSandboxEvent = (ctx, opts = {}) => {
|
|
|
12816
13334
|
// ee/invoke-skills/create-sandbox.ts
|
|
12817
13335
|
import { createBashTool } from "bash-tool";
|
|
12818
13336
|
import { tool as tool2 } from "ai";
|
|
12819
|
-
import { z as
|
|
13337
|
+
import { z as z14 } from "zod";
|
|
12820
13338
|
import CryptoJS3 from "crypto-js";
|
|
12821
13339
|
var getAllExuluVariables = async () => {
|
|
12822
13340
|
const { db } = await postgresClient();
|
|
@@ -13340,9 +13858,9 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
13340
13858
|
});
|
|
13341
13859
|
const writeFileTool = tool2({
|
|
13342
13860
|
description: 'Write content to a file in the sandbox. Creates parent directories if needed. Paths are always resolved against the session sandbox root \u2014 both relative paths ("skills/<Skill name>/SKILL.md") and leading-slash paths ("/skills/<Skill name>/SKILL.md") work and reach the same file. When the path is under the session artifact tree, the file is also uploaded to S3 and a short-lived presigned URL is returned in the tool output.',
|
|
13343
|
-
inputSchema:
|
|
13344
|
-
path:
|
|
13345
|
-
content:
|
|
13861
|
+
inputSchema: z14.object({
|
|
13862
|
+
path: z14.string().describe("The path where the file should be written. Relative paths and leading-slash paths are both resolved against the session sandbox root."),
|
|
13863
|
+
content: z14.string().describe("The content to write to the file")
|
|
13346
13864
|
}),
|
|
13347
13865
|
execute: async ({ path: path3, content }) => {
|
|
13348
13866
|
const resolvedPath = resolveSessionPath(path3, sessionDir);
|
|
@@ -13361,8 +13879,8 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
13361
13879
|
});
|
|
13362
13880
|
const readFileTool = tool2({
|
|
13363
13881
|
description: 'Read the contents of a file from the sandbox. Paths are always resolved against the session sandbox root \u2014 both relative paths ("skills/<Skill name>/SKILL.md") and leading-slash paths ("/skills/<Skill name>/SKILL.md") work and reach the same file. Skills live in a folder per skill: "skills/<Skill name>/SKILL.md", never "skills/<Skill name>.md". If the file does not exist, the error message is surfaced verbatim.',
|
|
13364
|
-
inputSchema:
|
|
13365
|
-
path:
|
|
13882
|
+
inputSchema: z14.object({
|
|
13883
|
+
path: z14.string().describe("The path of the file to read. Relative paths and leading-slash paths are both resolved against the session sandbox root.")
|
|
13366
13884
|
}),
|
|
13367
13885
|
execute: async ({ path: path3 }) => {
|
|
13368
13886
|
const resolvedPath = resolveSessionPath(path3, sessionDir);
|
|
@@ -13379,8 +13897,8 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
13379
13897
|
const originalBashTool = tools.bash;
|
|
13380
13898
|
const bashTool = tool2({
|
|
13381
13899
|
description: originalBashTool.description ?? "",
|
|
13382
|
-
inputSchema:
|
|
13383
|
-
command:
|
|
13900
|
+
inputSchema: z14.object({
|
|
13901
|
+
command: z14.string().describe("The bash command to execute.")
|
|
13384
13902
|
}),
|
|
13385
13903
|
execute: async (args, opts) => {
|
|
13386
13904
|
const before = persistenceEnabled ? await snapshotSessionArtifacts() : null;
|
|
@@ -13652,7 +14170,7 @@ var buildAuthToolModelOutput = (tool3) => ({ output }) => {
|
|
|
13652
14170
|
};
|
|
13653
14171
|
|
|
13654
14172
|
// src/templates/tools/session-file-read-tool.ts
|
|
13655
|
-
import { z as
|
|
14173
|
+
import { z as z15 } from "zod";
|
|
13656
14174
|
var DEFAULT_LIMIT = 250;
|
|
13657
14175
|
var MAX_CONTENT_CHARS = 16e3;
|
|
13658
14176
|
var SESSION_FILE_READ_TOOL_NAME = "read_session_file";
|
|
@@ -13705,10 +14223,10 @@ var createSessionFileReadTool = ({
|
|
|
13705
14223
|
name: SESSION_FILE_READ_TOOL_NAME,
|
|
13706
14224
|
needsApproval: false,
|
|
13707
14225
|
description: "Read a line range from a file stored in this session's files \u2014 including offloaded tool outputs (tool-output-*.txt) and uploaded documents. Use offset (1-based line number) and limit to page through large files instead of reading everything at once.",
|
|
13708
|
-
inputSchema:
|
|
13709
|
-
filename:
|
|
13710
|
-
offset:
|
|
13711
|
-
limit:
|
|
14226
|
+
inputSchema: z15.object({
|
|
14227
|
+
filename: z15.string().describe('Exact session file name as referenced in a truncation notice, e.g. "tool-output-web_search-a1b2c3d4.txt"'),
|
|
14228
|
+
offset: z15.number().int().min(1).optional().describe("1-based first line to read (default 1)"),
|
|
14229
|
+
limit: z15.number().int().min(1).max(1e3).optional().describe(`Number of lines to read (default ${DEFAULT_LIMIT})`)
|
|
13712
14230
|
}),
|
|
13713
14231
|
type: "function",
|
|
13714
14232
|
category: "session",
|
|
@@ -13721,7 +14239,7 @@ var createSessionFileReadTool = ({
|
|
|
13721
14239
|
};
|
|
13722
14240
|
|
|
13723
14241
|
// src/templates/tools/parse-document-tool.ts
|
|
13724
|
-
import { z as
|
|
14242
|
+
import { z as z16 } from "zod";
|
|
13725
14243
|
import { extname } from "path";
|
|
13726
14244
|
import { parseOfficeAsync as parseOfficeAsync2 } from "officeparser";
|
|
13727
14245
|
|
|
@@ -14090,11 +14608,11 @@ ${text.trim()}`).join("\n");
|
|
|
14090
14608
|
name: PARSE_DOCUMENT_TOOL_NAME,
|
|
14091
14609
|
needsApproval: false,
|
|
14092
14610
|
description: `Extract the text of an uploaded PDF or Office document from this session's files, with "--- page N ---" markers for PDFs so you can locate content by page. Free and fast (no OCR): works only on documents with a real text layer. To SEE a page or an image inside a document, use view_document_page.`,
|
|
14093
|
-
inputSchema:
|
|
14094
|
-
filename:
|
|
14095
|
-
pages:
|
|
14096
|
-
offset:
|
|
14097
|
-
limit:
|
|
14611
|
+
inputSchema: z16.object({
|
|
14612
|
+
filename: z16.string().describe('Exact session file name, e.g. "report.pdf"'),
|
|
14613
|
+
pages: z16.string().optional().describe('PDF page or range to extract, e.g. "2" or "1-5" (default: all pages) (PDF only)'),
|
|
14614
|
+
offset: z16.number().int().min(1).optional().describe("1-based first output line to read (default 1)"),
|
|
14615
|
+
limit: z16.number().int().min(1).max(1e3).optional().describe(`Number of lines to read (default ${DEFAULT_LIMIT2})`)
|
|
14098
14616
|
}),
|
|
14099
14617
|
type: "function",
|
|
14100
14618
|
category: "session",
|
|
@@ -14107,7 +14625,7 @@ ${text.trim()}`).join("\n");
|
|
|
14107
14625
|
};
|
|
14108
14626
|
|
|
14109
14627
|
// src/templates/tools/view-document-page-tool.ts
|
|
14110
|
-
import { z as
|
|
14628
|
+
import { z as z17 } from "zod";
|
|
14111
14629
|
import { extname as extname3 } from "path";
|
|
14112
14630
|
|
|
14113
14631
|
// src/sessions/pdf-preview-cache.ts
|
|
@@ -14378,9 +14896,9 @@ var createViewDocumentPageTool = ({
|
|
|
14378
14896
|
name: VIEW_DOCUMENT_PAGE_TOOL_NAME,
|
|
14379
14897
|
needsApproval: false,
|
|
14380
14898
|
description: "LOOK at a page of an uploaded PDF/Office document, or at an uploaded image, from this session's files. The rendered image is attached as a user message directly after this tool result so you can visually analyze photos, charts, scans, and layouts. Use parse_document first to find which page you need. Requires a vision-capable model.",
|
|
14381
|
-
inputSchema:
|
|
14382
|
-
filename:
|
|
14383
|
-
page:
|
|
14899
|
+
inputSchema: z17.object({
|
|
14900
|
+
filename: z17.string().describe('Exact session file name, e.g. "report.pdf" or "screenshot.png"'),
|
|
14901
|
+
page: z17.number().int().min(1).optional().describe("Page number to render (default 1; ignored for image files)")
|
|
14384
14902
|
}),
|
|
14385
14903
|
type: "function",
|
|
14386
14904
|
category: "session",
|
|
@@ -14748,11 +15266,12 @@ var convertExuluToolsToAiSdkTools = async (currentTools, currentSkills, approved
|
|
|
14748
15266
|
)?.default;
|
|
14749
15267
|
const toolDescription = cur.description;
|
|
14750
15268
|
const description = userDefinedConfigDescription || defaultConfigDescription || toolDescription;
|
|
15269
|
+
const approvedForSession = approvedTools?.includes("tool-" + cur.name) ?? false;
|
|
14751
15270
|
console.log(
|
|
14752
15271
|
"[EXULU] Tool",
|
|
14753
15272
|
cur.name,
|
|
14754
15273
|
"needs approval",
|
|
14755
|
-
|
|
15274
|
+
cur.needsApprovalFn ? "per call" : isMemoryToolId(cur.id) ? true : approvedForSession ? "only answered calls" : !!cur.needsApproval
|
|
14756
15275
|
);
|
|
14757
15276
|
return {
|
|
14758
15277
|
...prev,
|
|
@@ -14761,8 +15280,16 @@ var convertExuluToolsToAiSdkTools = async (currentTools, currentSkills, approved
|
|
|
14761
15280
|
description,
|
|
14762
15281
|
// The approvedTools array uses the tool.name lookup as the frontend
|
|
14763
15282
|
// Vercel AI SDK uses the sanitized tool name as the key, so this matches.
|
|
14764
|
-
|
|
14765
|
-
//
|
|
15283
|
+
// Never a plain `false` for a tool the user allowed for this chat: the
|
|
15284
|
+
// SDK re-validates an ANSWERED approval by calling needsApproval again
|
|
15285
|
+
// and reads `false` as "deny" — see approval-revalidation.ts.
|
|
15286
|
+
needsApproval: cur.needsApprovalFn ? (input, opts) => cur.needsApprovalFn(input, opts) : isMemoryToolId(cur.id) ? true : (_input, opts) => needsApprovalForCall({
|
|
15287
|
+
toolCallId: opts.toolCallId,
|
|
15288
|
+
messages: opts.messages,
|
|
15289
|
+
approvedForSession,
|
|
15290
|
+
requiresApproval: !!cur.needsApproval
|
|
15291
|
+
// todo make configurable
|
|
15292
|
+
}),
|
|
14766
15293
|
// Auth-wrapped tools: the model sees scrub text instead of the
|
|
14767
15294
|
// credentialRequest/oauth payload; the UI stream keeps the raw
|
|
14768
15295
|
// output (spec 2026-07-22 §1.2).
|
|
@@ -14972,6 +15499,7 @@ export {
|
|
|
14972
15499
|
BaseChunker,
|
|
14973
15500
|
SentenceChunker,
|
|
14974
15501
|
defaultChunker,
|
|
15502
|
+
prepareItemWrite,
|
|
14975
15503
|
resolveEmbedder,
|
|
14976
15504
|
PROJECTION_VERSION,
|
|
14977
15505
|
PROJECTION_METHOD,
|