@capybara-hq/kernel 0.1.0-rc.115 → 0.1.0-rc.117
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/bootstrap.json +3 -3
- package/dist/agents/agents.controller.d.ts +13 -1
- package/dist/agents/agents.controller.js +24 -2
- package/dist/catalog/catalog-content.d.ts +11 -0
- package/dist/catalog/catalog-content.js +1 -0
- package/dist/catalog/catalog.service.d.ts +11 -1
- package/dist/catalog/catalog.service.js +36 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +1 -0
- package/dist/catalog/org-catalog.service.js +44 -2
- package/dist/catalog/platform-components.js +13 -0
- package/dist/catalog/plugin-connectors.d.ts +35 -0
- package/dist/catalog/plugin-connectors.js +81 -0
- package/dist/catalog/schema-path.d.ts +4 -6
- package/dist/catalog/schema-path.js +48 -21
- package/dist/channels/outbound.d.ts +5 -0
- package/dist/channels/outbound.js +6 -1
- package/dist/channels/supervisor.d.ts +5 -1
- package/dist/channels/supervisor.js +20 -1
- package/dist/conversations/conversations.controller.d.ts +46 -14
- package/dist/conversations/conversations.controller.js +82 -47
- package/dist/conversations/conversations.service.d.ts +93 -59
- package/dist/conversations/conversations.service.js +255 -72
- package/dist/conversations/events.d.ts +32 -0
- package/dist/conversations/events.js +47 -3
- package/dist/conversations/inline-tokens.d.ts +87 -0
- package/dist/conversations/inline-tokens.js +154 -0
- package/dist/conversations/permission-profiles.controller.d.ts +14 -7
- package/dist/conversations/permission-profiles.controller.js +1 -5
- package/dist/conversations/prompt-suggestions.js +2 -4
- package/dist/conversations/queue.d.ts +0 -2
- package/dist/conversations/queue.service.js +9 -13
- package/dist/db/kernel-schema.d.ts +2 -0
- package/dist/devices/devices.service.d.ts +8 -0
- package/dist/devices/devices.service.js +16 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +12 -0
- package/dist/evals/snapshot.js +4 -2
- package/dist/files/library-files.service.d.ts +13 -0
- package/dist/files/library-files.service.js +33 -6
- package/dist/net/safe-fetch.js +1 -1
- package/dist/platform/exclusions.js +11 -1
- package/dist/platform/ops/devices.ops.js +14 -0
- package/dist/runtime/context/build.d.ts +7 -2
- package/dist/runtime/context/build.js +17 -6
- package/dist/runtime/context/compaction.d.ts +3 -3
- package/dist/runtime/context/compaction.js +12 -13
- package/dist/sandbox/review/classifier.js +5 -1
- package/dist/sandbox/sandbox.service.d.ts +13 -0
- package/dist/sandbox/sandbox.service.js +51 -4
- package/dist/tools/builtins/sandbox/common.d.ts +2 -7
- package/dist/tools/builtins/sandbox/common.js +4 -2
- package/dist/tools/connector-content.controller.d.ts +6 -2
- package/dist/tools/connector-content.controller.js +13 -3
- package/dist/tools/connector-content.d.ts +55 -15
- package/dist/tools/connector-content.js +112 -54
- package/dist/tools/connectors.service.d.ts +3 -2
- package/dist/tools/connectors.service.js +6 -20
- package/dist/tools/mentionable-connectors.d.ts +88 -0
- package/dist/tools/mentionable-connectors.js +218 -0
- package/dist/tools/pipeline.d.ts +4 -0
- package/dist/tools/pipeline.js +98 -22
- package/dist/tools/specs.d.ts +13 -4
- package/dist/tools/specs.js +22 -8
- package/dist/tools/tools.module.js +7 -0
- package/dist/ui/admin-ui.controller.d.ts +5 -2
- package/dist/ui/admin-ui.controller.js +14 -1
- package/dist/ui/ui.schemas.d.ts +9 -0
- package/dist/ui/ui.schemas.js +2 -0
- package/dist/ui/views.d.ts +1 -1
- package/dist/ui/views.js +4 -5
- package/package.json +3 -3
- package/src/migrations/0201_tool_specs_text.sql +8 -0
package/dist/tools/pipeline.js
CHANGED
|
@@ -615,8 +615,15 @@ function loopbackAskRerunAfter(ask) {
|
|
|
615
615
|
* the call's live loopback port grant (Full access or the review model granted the port to the
|
|
616
616
|
* attempt that was refused it).
|
|
617
617
|
*/
|
|
618
|
-
|
|
619
|
-
|
|
618
|
+
/** The idempotency key of the `permission_reviewed` event tying a ready-grant rerun to a call. */
|
|
619
|
+
const loopbackReadyRerunIdemKey = (runId, callId) => `permission_reviewed:loopback_ready:${runId}:${callId}`;
|
|
620
|
+
function rerunPoints(ask, grant, readyRerun = null) {
|
|
621
|
+
const points = [
|
|
622
|
+
serviceRerunAfter(ask),
|
|
623
|
+
loopbackAskRerunAfter(ask),
|
|
624
|
+
grant?.attempt ?? null,
|
|
625
|
+
readyRerun,
|
|
626
|
+
];
|
|
620
627
|
return new Set(points.filter((p) => p !== null));
|
|
621
628
|
}
|
|
622
629
|
/** An ask whose approval runs the call again: it belongs to the attempt that asked. */
|
|
@@ -905,11 +912,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
905
912
|
// the call's network ask (one per call) and its live loopback port grant
|
|
906
913
|
const ask = await this.deps.approvals.networkForCall(ctx.runId, call.id);
|
|
907
914
|
const grant = await this.loopbackGrantOf(ctx.runId, call.id);
|
|
915
|
+
const readyRerun = await this.readyLoopbackRerunOf(ctx.conversationId, ctx.runId, call.id);
|
|
908
916
|
let attempt = rounds.length + 1;
|
|
909
917
|
// each time the call ran again (after its network ask, browser use spec §7.1, or a loopback
|
|
910
918
|
// grant or ask) took one attempt more: input rounds asked after a re-run come after it, so
|
|
911
919
|
// every re-run point the count has passed adds one, in order
|
|
912
|
-
const reruns = rerunPoints(ask, grant);
|
|
920
|
+
const reruns = rerunPoints(ask, grant, readyRerun);
|
|
913
921
|
if (rounds.length > 0) {
|
|
914
922
|
for (const p of [...reruns].sort((a, b) => a - b))
|
|
915
923
|
if (attempt > p)
|
|
@@ -945,10 +953,13 @@ let ToolPipeline = class ToolPipeline {
|
|
|
945
953
|
(!asksPerAttempt(ask) ||
|
|
946
954
|
ask.detail?.attempt === attempt);
|
|
947
955
|
const grantedHere = !askedHere && grant !== null && grant.attempt === attempt;
|
|
948
|
-
|
|
956
|
+
const readyRerunHere = !askedHere && !grantedHere && readyRerun === attempt;
|
|
957
|
+
if (askedHere || grantedHere || readyRerunHere) {
|
|
949
958
|
const notes = askedHere && ask !== null
|
|
950
959
|
? settledNetworkNotes(ask, approvalHours(ask))
|
|
951
|
-
:
|
|
960
|
+
: grantedHere
|
|
961
|
+
? [loopbackGrantedNote(grant.port)]
|
|
962
|
+
: [];
|
|
952
963
|
if (notes === null)
|
|
953
964
|
return approvalWait(ask);
|
|
954
965
|
const rerunsHere = !askedHere ||
|
|
@@ -1598,9 +1609,10 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1598
1609
|
let loopbackNotes = [];
|
|
1599
1610
|
if (scoped?.loopback !== undefined) {
|
|
1600
1611
|
const lb = scoped.loopback;
|
|
1601
|
-
const
|
|
1612
|
+
const otherHosts = scoped.hosts.filter((h) => serviceHostKey(h.host) !== serviceHostKey(lb.host));
|
|
1613
|
+
const handled = await this.loopbackBlocked(ctx, call, tool, input, outKey, { deviceId: scoped.deviceId, loopback: lb, url: scoped.url, otherHosts }, attempt, keptResult, rerun.loopbackRerun === true, pre, callAudit);
|
|
1602
1614
|
if (handled.kind !== "none") {
|
|
1603
|
-
serviceHosts =
|
|
1615
|
+
serviceHosts = otherHosts;
|
|
1604
1616
|
if (handled.kind === "wait") {
|
|
1605
1617
|
if (hooks && hookBase) {
|
|
1606
1618
|
fireObserve(hooks, "tool.postExecute", { ...hookBase, isError: rendered.isError, content: handled.content, durationMs }, ctx.signal, this.deps.log);
|
|
@@ -2453,7 +2465,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2453
2465
|
* A device service's refusals (browser use spec §7.1): the extension whose service asked and
|
|
2454
2466
|
* the call's attempt. Only "always" is offered; once approved the call runs again.
|
|
2455
2467
|
*/
|
|
2456
|
-
service
|
|
2468
|
+
service,
|
|
2469
|
+
/**
|
|
2470
|
+
* Plan-only pass: compute the `network_blocked` event and every refused host's note without
|
|
2471
|
+
* opening a second network ask (used when a loopback ask already takes this call's ask slot).
|
|
2472
|
+
*/
|
|
2473
|
+
planOnly) {
|
|
2457
2474
|
const hosts = blockedEventHosts(report.blocked);
|
|
2458
2475
|
if (hosts.length === 0)
|
|
2459
2476
|
return { kind: "write", event: null, notes: [] };
|
|
@@ -2500,6 +2517,16 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2500
2517
|
const addressNote = plan.addressNote;
|
|
2501
2518
|
if (plan.ask.length === 0 || offer === undefined)
|
|
2502
2519
|
return { kind: "write", event, notes: plan.notes, addressNote };
|
|
2520
|
+
// plan-only pass (loopback ask takes this call's ask slot): keep every other refused host's
|
|
2521
|
+
// note without opening a second ask
|
|
2522
|
+
if (planOnly === true) {
|
|
2523
|
+
return {
|
|
2524
|
+
kind: "write",
|
|
2525
|
+
event,
|
|
2526
|
+
notes: [...plan.notes, serviceAskedNote(plan.ask.map((h) => h.host))],
|
|
2527
|
+
addressNote,
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2503
2530
|
// one ask per call: a service call that ran again after its ask is not asked again; only a
|
|
2504
2531
|
// would-be ask is replaced, the plan's other notes (a host on the list, not yet applied) stay
|
|
2505
2532
|
if (service !== undefined &&
|
|
@@ -2580,6 +2607,15 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2580
2607
|
async loopbackGrantOf(runId, callId) {
|
|
2581
2608
|
return (await this.loopbackGrants?.forCall(runId, callId)) ?? null;
|
|
2582
2609
|
}
|
|
2610
|
+
/**
|
|
2611
|
+
* The attempt that recorded a ready-grant loopback rerun for this call, or null when none did.
|
|
2612
|
+
*/
|
|
2613
|
+
async readyLoopbackRerunOf(conversationId, runId, callId) {
|
|
2614
|
+
const ev = await this.deps.eventLog.findByIdem(conversationId, loopbackReadyRerunIdemKey(runId, callId));
|
|
2615
|
+
return ev?.type === "permission_reviewed"
|
|
2616
|
+
? (ev.payload.loopback?.readyRerunAttempt ?? null)
|
|
2617
|
+
: null;
|
|
2618
|
+
}
|
|
2583
2619
|
/**
|
|
2584
2620
|
* A device service's loopback refusal (browser loopback port grants): the port of the person's
|
|
2585
2621
|
* own device a service of an extension declaring `permissions.deviceAccess.loopbackPorts` was
|
|
@@ -2643,17 +2679,6 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2643
2679
|
port,
|
|
2644
2680
|
};
|
|
2645
2681
|
const live = await grants.liveForRoot(ctx.orgId, device.deviceId, serviceId, facts.rootConversationId);
|
|
2646
|
-
if (live.some((g) => g.port === port)) {
|
|
2647
|
-
// granted already (the panel, an earlier call): the service had not applied it yet, so the
|
|
2648
|
-
// call runs again once; refused again (or granted to this call), its result stands
|
|
2649
|
-
if (rerunning || (await grants.forCall(ctx.runId, call.id)) !== null)
|
|
2650
|
-
return { kind: "write", notes: [loopbackNotAppliedNote(port)] };
|
|
2651
|
-
await this.writeResultIn(ctx, call.id, toolKey, kept, [...pre], callAudit, []);
|
|
2652
|
-
return { kind: "rerun", notes: [] };
|
|
2653
|
-
}
|
|
2654
|
-
// a call that ran again after its grant is not decided again (the port was closed meanwhile)
|
|
2655
|
-
if (rerunning)
|
|
2656
|
-
return { kind: "write", notes: [serviceAskedNote([hp])] };
|
|
2657
2682
|
const binding = {
|
|
2658
2683
|
orgId: facts.orgId,
|
|
2659
2684
|
rootConversationId: facts.rootConversationId,
|
|
@@ -2671,6 +2696,36 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2671
2696
|
scopeRevision: facts.scopeRevision,
|
|
2672
2697
|
authorityRevision: facts.authorityRevision,
|
|
2673
2698
|
};
|
|
2699
|
+
if (live.some((g) => g.port === port)) {
|
|
2700
|
+
// granted already (the panel, an earlier call): the service had not applied it yet, so the
|
|
2701
|
+
// call runs again once; refused again (or granted to this call), its result stands
|
|
2702
|
+
if (rerunning || (await grants.forCall(ctx.runId, call.id)) !== null)
|
|
2703
|
+
return { kind: "write", notes: [loopbackNotAppliedNote(port)] };
|
|
2704
|
+
const readyCandidate = {
|
|
2705
|
+
binding,
|
|
2706
|
+
permissionScope: { writeDirectories: [], hosts: [] },
|
|
2707
|
+
scopeKind: "loopback-port",
|
|
2708
|
+
loopback: { service: serviceId, port, readyRerunAttempt: attempt },
|
|
2709
|
+
};
|
|
2710
|
+
const readyEvent = {
|
|
2711
|
+
type: "permission_reviewed",
|
|
2712
|
+
runId: ctx.runId,
|
|
2713
|
+
idemKey: loopbackReadyRerunIdemKey(ctx.runId, call.id),
|
|
2714
|
+
payload: {
|
|
2715
|
+
...readyCandidate,
|
|
2716
|
+
candidateHash: permissionScopeHash(readyCandidate),
|
|
2717
|
+
outcome: "allow",
|
|
2718
|
+
reason: "Loopback port already granted for this conversation; retrying after the device applies it.",
|
|
2719
|
+
decisionSource: "rule",
|
|
2720
|
+
crossing: "loopback-port",
|
|
2721
|
+
},
|
|
2722
|
+
};
|
|
2723
|
+
await this.writeResultIn(ctx, call.id, toolKey, kept, [readyEvent, ...pre], callAudit, []);
|
|
2724
|
+
return { kind: "rerun", notes: [] };
|
|
2725
|
+
}
|
|
2726
|
+
// a call that ran again after its grant is not decided again (the port was closed meanwhile)
|
|
2727
|
+
if (rerunning)
|
|
2728
|
+
return { kind: "write", notes: [serviceAskedNote([hp])] };
|
|
2674
2729
|
const reviewed = (outcome, reason, decisionSource) => {
|
|
2675
2730
|
const candidate = {
|
|
2676
2731
|
binding,
|
|
@@ -2755,8 +2810,29 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2755
2810
|
return { kind: "write", notes: [otherAskPendingNote([hp])] };
|
|
2756
2811
|
if ((run?.asks ?? 0) >= MAX_NETWORK_ASKS_PER_RUN)
|
|
2757
2812
|
return { kind: "write", notes: [tooManyNote([hp])] };
|
|
2758
|
-
|
|
2759
|
-
|
|
2813
|
+
// plan-only pass for other refused hosts reported alongside the loopback port, so their notes
|
|
2814
|
+
// and `network_blocked` event are kept when the loopback ask settles
|
|
2815
|
+
let otherEvent = null;
|
|
2816
|
+
let otherNotes = [];
|
|
2817
|
+
if (report.otherHosts.length > 0) {
|
|
2818
|
+
const other = await this.networkBlocked(ctx, call.id, toolKey, input, {
|
|
2819
|
+
deviceId: report.deviceId,
|
|
2820
|
+
blocked: report.otherHosts.map(({ host, layer }) => ({ host, port: 443, layer })),
|
|
2821
|
+
}, pre, callAudit, kept, undefined, undefined, {
|
|
2822
|
+
name: tool.source.kind === "plugin" ? tool.source.plugin : tool.key,
|
|
2823
|
+
attempt,
|
|
2824
|
+
url: report.url,
|
|
2825
|
+
}, true);
|
|
2826
|
+
if (other.kind === "write") {
|
|
2827
|
+
otherEvent = other.event;
|
|
2828
|
+
otherNotes = other.notes;
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
const keptWithOther = otherNotes.length === 0
|
|
2832
|
+
? kept
|
|
2833
|
+
: { ...kept, content: withNetworkNotes(kept.content, otherNotes) };
|
|
2834
|
+
const { content, outputId } = await this.keptContent(ctx, call.id, keptWithOther);
|
|
2835
|
+
const { text: _text, denialHint: _hint, ...rest } = keptWithOther;
|
|
2760
2836
|
const result = {
|
|
2761
2837
|
...rest,
|
|
2762
2838
|
content: clipKept(content),
|
|
@@ -2764,7 +2840,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2764
2840
|
};
|
|
2765
2841
|
// the service's call ran: its display-only events and tool.called now, the result once the
|
|
2766
2842
|
// ask settles
|
|
2767
|
-
const written = await this.writeResultIn(ctx, call.id, toolKey,
|
|
2843
|
+
const written = await this.writeResultIn(ctx, call.id, toolKey, keptWithOther, otherEvent !== null ? [...pre, otherEvent] : [...pre], callAudit, []);
|
|
2768
2844
|
if (written.length > 0)
|
|
2769
2845
|
await this.deps.eventLog.notify(ctx.conversationId, Math.max(...written.map((e) => e.seq)));
|
|
2770
2846
|
const ask = await this.deps.approvals.requestLoopback({
|
package/dist/tools/specs.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { ToolSpec } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
4
|
+
* Stores tool definitions by fingerprint in `capybara.tool_specs` (content-addressed: one row per
|
|
5
|
+
* fingerprint, never changed, except that a row written before `spec_text` existed gets it on the
|
|
6
|
+
* next write). `model_call` records only `{key, specHash}`; the definition lives here, so after a
|
|
7
|
+
* connector refresh or a plugin upgrade the definitions an earlier request used can still be read
|
|
8
|
+
* back and the request rebuilt from the log. `spec_text` keeps the JSON text as sent: `spec` is
|
|
9
|
+
* jsonb, which reorders keys, and a rebuilt request must serialize byte for byte like the original
|
|
10
|
+
* (a provider renders its tools from that JSON; a reordered schema misses the prompt cache).
|
|
7
11
|
*/
|
|
8
12
|
export declare function recordToolSpecs(
|
|
9
13
|
/** The pool or a transaction (a transaction is a Kysely handle too). */
|
|
@@ -11,5 +15,10 @@ db: KernelSchemaDb, specs: readonly {
|
|
|
11
15
|
specHash: string;
|
|
12
16
|
spec: ToolSpec;
|
|
13
17
|
}[]): Promise<void>;
|
|
14
|
-
/**
|
|
18
|
+
/** A stored definition: its JSON text as sent when recorded, else the jsonb value. */
|
|
19
|
+
export declare function storedToolSpec(row: {
|
|
20
|
+
spec: unknown;
|
|
21
|
+
spec_text: string | null;
|
|
22
|
+
}): ToolSpec;
|
|
23
|
+
/** The tool definition stored under a fingerprint ({@link storedToolSpec}); null when none. */
|
|
15
24
|
export declare function loadToolSpec(db: KernelSchemaDb, specHash: string): Promise<ToolSpec | null>;
|
package/dist/tools/specs.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* `
|
|
4
|
-
*
|
|
2
|
+
* Stores tool definitions by fingerprint in `capybara.tool_specs` (content-addressed: one row per
|
|
3
|
+
* fingerprint, never changed, except that a row written before `spec_text` existed gets it on the
|
|
4
|
+
* next write). `model_call` records only `{key, specHash}`; the definition lives here, so after a
|
|
5
|
+
* connector refresh or a plugin upgrade the definitions an earlier request used can still be read
|
|
6
|
+
* back and the request rebuilt from the log. `spec_text` keeps the JSON text as sent: `spec` is
|
|
7
|
+
* jsonb, which reorders keys, and a rebuilt request must serialize byte for byte like the original
|
|
8
|
+
* (a provider renders its tools from that JSON; a reordered schema misses the prompt cache).
|
|
5
9
|
*/
|
|
6
10
|
export async function recordToolSpecs(
|
|
7
11
|
/** The pool or a transaction (a transaction is a Kysely handle too). */
|
|
@@ -15,19 +19,29 @@ db, specs) {
|
|
|
15
19
|
// 按指纹排序插入:并发事务插入同一批指纹时加锁顺序一致,不会互相死锁
|
|
16
20
|
const rows = [...unique]
|
|
17
21
|
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
18
|
-
.map(([hash, spec]) =>
|
|
22
|
+
.map(([hash, spec]) => {
|
|
23
|
+
const text = JSON.stringify(spec);
|
|
24
|
+
return { spec_hash: hash, spec: text, spec_text: text };
|
|
25
|
+
});
|
|
19
26
|
await db
|
|
20
27
|
.insertInto("tool_specs")
|
|
21
28
|
.values(rows)
|
|
22
|
-
.onConflict((oc) => oc
|
|
29
|
+
.onConflict((oc) => oc
|
|
30
|
+
.column("spec_hash")
|
|
31
|
+
.doUpdateSet((eb) => ({ spec_text: eb.ref("excluded.spec_text") }))
|
|
32
|
+
.where("tool_specs.spec_text", "is", null))
|
|
23
33
|
.execute();
|
|
24
34
|
}
|
|
25
|
-
/**
|
|
35
|
+
/** A stored definition: its JSON text as sent when recorded, else the jsonb value. */
|
|
36
|
+
export function storedToolSpec(row) {
|
|
37
|
+
return (row.spec_text !== null ? JSON.parse(row.spec_text) : row.spec);
|
|
38
|
+
}
|
|
39
|
+
/** The tool definition stored under a fingerprint ({@link storedToolSpec}); null when none. */
|
|
26
40
|
export async function loadToolSpec(db, specHash) {
|
|
27
41
|
const row = await db
|
|
28
42
|
.selectFrom("tool_specs")
|
|
29
|
-
.select("spec")
|
|
43
|
+
.select(["spec", "spec_text"])
|
|
30
44
|
.where("spec_hash", "=", specHash)
|
|
31
45
|
.executeTakeFirst();
|
|
32
|
-
return row ? row
|
|
46
|
+
return row ? storedToolSpec(row) : null;
|
|
33
47
|
}
|
|
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
|
+
import { AgentLookupModule } from "../agents/agent-lookup.js";
|
|
8
9
|
import { AutomationStoreModule } from "../automations/store.module.js";
|
|
9
10
|
import { BackgroundModule } from "../background/background.module.js";
|
|
10
11
|
import { ConversationAccessModule } from "../conversations/access.js";
|
|
@@ -48,6 +49,7 @@ import { ConnectorsService } from "./connectors.service.js";
|
|
|
48
49
|
import { CredentialsModule } from "./credentials.module.js";
|
|
49
50
|
import { ToolDrift } from "./drift.js";
|
|
50
51
|
import { ConversationToolInfo, OrgExtensionTools } from "./info.js";
|
|
52
|
+
import { MentionableConnectorsService } from "./mentionable-connectors.js";
|
|
51
53
|
import { OAuthFlow } from "./oauth/flow.js";
|
|
52
54
|
import { OrgToolSwitches } from "./org-tool-switches.js";
|
|
53
55
|
import { ToolOutputs } from "./outputs.js";
|
|
@@ -121,6 +123,8 @@ ToolsModule = __decorate([
|
|
|
121
123
|
AutomationStoreModule,
|
|
122
124
|
// connector credentials (also the git gateway's, without importing this module)
|
|
123
125
|
CredentialsModule,
|
|
126
|
+
// the agent the mentionable connectors are listed for, as the viewer may see it
|
|
127
|
+
AgentLookupModule,
|
|
124
128
|
],
|
|
125
129
|
providers: [
|
|
126
130
|
PermissionApprovalJobs,
|
|
@@ -150,6 +154,8 @@ ToolsModule = __decorate([
|
|
|
150
154
|
ConversationToolInfo,
|
|
151
155
|
OrgExtensionTools,
|
|
152
156
|
OrgToolSwitches,
|
|
157
|
+
// the composer's `@` menu: the connectors an agent can be pointed at
|
|
158
|
+
MentionableConnectorsService,
|
|
153
159
|
],
|
|
154
160
|
exports: [
|
|
155
161
|
PermissionApprovalJobs,
|
|
@@ -171,6 +177,7 @@ ToolsModule = __decorate([
|
|
|
171
177
|
ConversationToolInfo,
|
|
172
178
|
OrgExtensionTools,
|
|
173
179
|
OrgToolSwitches,
|
|
180
|
+
MentionableConnectorsService,
|
|
174
181
|
],
|
|
175
182
|
})
|
|
176
183
|
], ToolsModule);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { UiActionResult, UiView } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import type { JsonValue, UiActionResult, UiView } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
3
3
|
import type { z } from "zod";
|
|
4
4
|
import { ApiTokenService } from "../identity/api-tokens.js";
|
|
5
5
|
import { type Principal } from "../identity/principal.js";
|
|
6
6
|
import { SessionService } from "../identity/sessions.js";
|
|
7
7
|
import { EmbedTokens } from "./embed-token.js";
|
|
8
|
-
import { ContributionParams, PlatformActionBody, PlatformViewQuery } from "./ui.schemas.js";
|
|
8
|
+
import { ContributionParams, PlatformActionBody, PlatformQueryBody, PlatformViewQuery } from "./ui.schemas.js";
|
|
9
9
|
import { OrgUiStreams } from "./ui-stream.js";
|
|
10
10
|
import { type UiArrangementSlot, type UiContributionItem, UiViews } from "./views.js";
|
|
11
11
|
/**
|
|
@@ -45,6 +45,9 @@ export declare class AdminUiController {
|
|
|
45
45
|
view: UiView;
|
|
46
46
|
}>;
|
|
47
47
|
action(principal: Principal, { plugin, id }: z.infer<typeof ContributionParams>, body: z.infer<typeof PlatformActionBody>): Promise<UiActionResult>;
|
|
48
|
+
query(principal: Principal, { plugin, id }: z.infer<typeof ContributionParams>, body: z.infer<typeof PlatformQueryBody>): Promise<{
|
|
49
|
+
data: JsonValue;
|
|
50
|
+
}>;
|
|
48
51
|
embedToken(principal: Principal, { plugin, id }: z.infer<typeof ContributionParams>): Promise<{
|
|
49
52
|
token: string;
|
|
50
53
|
src: string;
|
|
@@ -15,7 +15,7 @@ import { SessionService } from "../identity/sessions.js";
|
|
|
15
15
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
16
16
|
import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
|
|
17
17
|
import { EMBED_TOKEN_TTL_SECONDS, EmbedTokens } from "./embed-token.js";
|
|
18
|
-
import { ContributionParams, PlatformActionBody, PlatformViewQuery } from "./ui.schemas.js";
|
|
18
|
+
import { ContributionParams, PlatformActionBody, PlatformQueryBody, PlatformViewQuery, } from "./ui.schemas.js";
|
|
19
19
|
import { OrgUiStreams } from "./ui-stream.js";
|
|
20
20
|
import { BEARER_RE, embedSrc } from "./views.controller.js";
|
|
21
21
|
import { UiViews } from "./views.js";
|
|
@@ -25,6 +25,8 @@ class AdminUiViewQueryDto extends createZodDto(PlatformViewQuery, "AdminUiViewQu
|
|
|
25
25
|
}
|
|
26
26
|
class AdminUiActionBodyDto extends createZodDto(PlatformActionBody, "AdminUiActionBody") {
|
|
27
27
|
}
|
|
28
|
+
class AdminUiQueryBodyDto extends createZodDto(PlatformQueryBody, "AdminUiQueryBody") {
|
|
29
|
+
}
|
|
28
30
|
/**
|
|
29
31
|
* Extension UI in the admin console (UI slots spec §7, platform scope): the `platform.page`
|
|
30
32
|
* contributions, for super admins only (`@SuperAdmin`, a person: service tokens are refused), with
|
|
@@ -85,6 +87,10 @@ let AdminUiController = class AdminUiController {
|
|
|
85
87
|
...(body.answer !== undefined && { answer: body.answer }),
|
|
86
88
|
});
|
|
87
89
|
}
|
|
90
|
+
async query(principal, { plugin, id }, body) {
|
|
91
|
+
const p = requireUser(principal);
|
|
92
|
+
return this.views.query({ scope: "platform", accountId: p.account.id, plugin, id, locale: body.locale }, { query: body.query, ...(body.params !== undefined && { params: body.params }) });
|
|
93
|
+
}
|
|
88
94
|
async embedToken(principal, { plugin, id }) {
|
|
89
95
|
const p = requireUser(principal);
|
|
90
96
|
const target = await this.views.embed({
|
|
@@ -168,6 +174,13 @@ __decorate([
|
|
|
168
174
|
__param(1, ZParam(AdminUiContributionParamsDto)),
|
|
169
175
|
__param(2, ZBody(AdminUiActionBodyDto))
|
|
170
176
|
], AdminUiController.prototype, "action", null);
|
|
177
|
+
__decorate([
|
|
178
|
+
Post("query/:plugin/:id"),
|
|
179
|
+
HttpCode(200),
|
|
180
|
+
__param(0, CurrentPrincipal()),
|
|
181
|
+
__param(1, ZParam(AdminUiContributionParamsDto)),
|
|
182
|
+
__param(2, ZBody(AdminUiQueryBodyDto))
|
|
183
|
+
], AdminUiController.prototype, "query", null);
|
|
171
184
|
__decorate([
|
|
172
185
|
Post("embeds/:plugin/:id/token"),
|
|
173
186
|
HttpCode(200),
|
package/dist/ui/ui.schemas.d.ts
CHANGED
|
@@ -91,5 +91,14 @@ export declare const PlatformActionBody: z.ZodObject<{
|
|
|
91
91
|
zh: "zh";
|
|
92
92
|
}>>;
|
|
93
93
|
}, z.core.$strip>;
|
|
94
|
+
/** `POST /api/v1/admin/ui/query/:plugin/:id`: a component query of a platform page (no context id). */
|
|
95
|
+
export declare const PlatformQueryBody: z.ZodObject<{
|
|
96
|
+
query: z.ZodString;
|
|
97
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
98
|
+
locale: z.ZodDefault<z.ZodEnum<{
|
|
99
|
+
en: "en";
|
|
100
|
+
zh: "zh";
|
|
101
|
+
}>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
94
103
|
/** The slot catalog route the Platform operation `ui.slots` mirrors (`check:platform-ops` key). */
|
|
95
104
|
export declare const UI_ROUTES: readonly RouteSchemas[];
|
package/dist/ui/ui.schemas.js
CHANGED
|
@@ -87,5 +87,7 @@ export const EmbedTokenBody = z
|
|
|
87
87
|
export const PlatformViewQuery = z.object({ locale: Locale });
|
|
88
88
|
/** `POST /api/v1/admin/ui/actions/:plugin/:id`: an action of a platform page (no context id). */
|
|
89
89
|
export const PlatformActionBody = ActionBody.omit({ conversationId: true, agentId: true });
|
|
90
|
+
/** `POST /api/v1/admin/ui/query/:plugin/:id`: a component query of a platform page (no context id). */
|
|
91
|
+
export const PlatformQueryBody = QueryBody.omit({ conversationId: true, agentId: true });
|
|
90
92
|
/** The slot catalog route the Platform operation `ui.slots` mirrors (`check:platform-ops` key). */
|
|
91
93
|
export const UI_ROUTES = [{ route: "GET /api/v1/ui/slots" }];
|
package/dist/ui/views.d.ts
CHANGED
|
@@ -225,7 +225,7 @@ export declare class UiViews {
|
|
|
225
225
|
* result that is not JSON or over `UI_LIMITS.componentQueryBytes` 502
|
|
226
226
|
* `ui.query_result_too_large`.
|
|
227
227
|
*/
|
|
228
|
-
query(t:
|
|
228
|
+
query(t: UiTarget, input: {
|
|
229
229
|
query: string;
|
|
230
230
|
params?: unknown;
|
|
231
231
|
}): Promise<{
|
package/dist/ui/views.js
CHANGED
|
@@ -488,18 +488,17 @@ let UiViews = class UiViews {
|
|
|
488
488
|
throw new ApiError("ui.query_params_too_large", `params must be at most ${UI_LIMITS.componentQueryParamsBytes} bytes as JSON`);
|
|
489
489
|
}
|
|
490
490
|
const handler = resolved.entry.query;
|
|
491
|
-
|
|
492
|
-
const args = resolved.args;
|
|
491
|
+
const scopeField = t.scope === "platform" ? { scope: "platform" } : { orgId: t.orgId };
|
|
493
492
|
const data = await callExtension({
|
|
494
493
|
log: this.d.log,
|
|
495
494
|
plugin: t.plugin,
|
|
496
495
|
what: "query",
|
|
497
|
-
fields: { plugin: t.plugin, contribution: t.id, query: input.query,
|
|
496
|
+
fields: { plugin: t.plugin, contribution: t.id, query: input.query, ...scopeField },
|
|
498
497
|
timeoutMs: UI_QUERY_TIMEOUT_MS,
|
|
499
498
|
failCode: "ui.query_failed",
|
|
500
499
|
timeoutCode: "ui.query_timeout",
|
|
501
500
|
failMessage: `Plugin ${t.plugin} failed to answer query ${input.query} of ${t.id}`,
|
|
502
|
-
fn: (signal) => handler({ ...args, query: input.query, params, signal }),
|
|
501
|
+
fn: (signal) => handler({ ...resolved.args, query: input.query, params, signal }),
|
|
503
502
|
});
|
|
504
503
|
let json;
|
|
505
504
|
try {
|
|
@@ -514,7 +513,7 @@ let UiViews = class UiViews {
|
|
|
514
513
|
plugin: t.plugin,
|
|
515
514
|
contribution: t.id,
|
|
516
515
|
query: input.query,
|
|
517
|
-
|
|
516
|
+
...scopeField,
|
|
518
517
|
...(bytes !== undefined && { bytes }),
|
|
519
518
|
});
|
|
520
519
|
throw new ApiError("ui.query_result_too_large", `Plugin ${t.plugin} returned a query result that is not JSON of at most ${UI_LIMITS.componentQueryBytes} bytes`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.117",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"yaml": "^2.9.1",
|
|
67
67
|
"yauzl": "3.4.0",
|
|
68
68
|
"zod": "^4.6.7",
|
|
69
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.92"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@types/ws": "^8.18.2",
|
|
76
76
|
"@types/yauzl": "3.4.0",
|
|
77
77
|
"ws": "^8.22.0",
|
|
78
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
78
|
+
"@capybara-hq/testing": "0.1.0-rc.51"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsc -b"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- The exact JSON text of a tool definition as the runtime sent it. `spec` is jsonb, which reorders
|
|
2
|
+
-- object keys (shorter keys first), so a request rebuilt from it (an eval replay, the prompt
|
|
3
|
+
-- suggestion's side request) serialized its input schemas in another key order than the original
|
|
4
|
+
-- request: a provider renders the tools from that JSON, so the rebuilt prompt differed and missed
|
|
5
|
+
-- the prompt cache from the tools on. Readers prefer `spec_text`; null on rows written before it
|
|
6
|
+
-- (filled by the next write of the same fingerprint).
|
|
7
|
+
|
|
8
|
+
ALTER TABLE tool_specs ADD COLUMN IF NOT EXISTS spec_text text;
|