@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ConversationSource, TriggerSubject } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { AgentLookup } from "../agents/agent-lookup.js";
|
|
3
|
-
import type { ModelRef } from "../agents/definition.js";
|
|
3
|
+
import type { AgentDefinition, ModelRef } from "../agents/definition.js";
|
|
4
4
|
import type { AgentAvatarView } from "../agents/profile.js";
|
|
5
5
|
import type { AutomationEventMarker, ScheduleMarker } from "../automations/types.js";
|
|
6
6
|
import type { ConversationSubject, TitleSource } from "../db/kernel-schema.js";
|
|
@@ -19,11 +19,13 @@ import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js
|
|
|
19
19
|
import { type RenderedInvocation, SkillInvoker } from "../skills/invoke.js";
|
|
20
20
|
import { type ApprovalRecord, ApprovalsService } from "../tools/approvals.service.js";
|
|
21
21
|
import { ConnectorContent } from "../tools/connector-content.js";
|
|
22
|
+
import { MentionableConnectorsService } from "../tools/mentionable-connectors.js";
|
|
22
23
|
import { type QuestionRecord, QuestionsService } from "../tools/questions.service.js";
|
|
23
24
|
import { ConversationAccess } from "./access.js";
|
|
24
25
|
import { type AgentTreeNode } from "./agent-tree.js";
|
|
25
26
|
import { EventLog } from "./event-log.js";
|
|
26
27
|
import { type ConversationEvent, type LogContentBlock } from "./events.js";
|
|
28
|
+
import { type InlineEntry, type MessageToken } from "./inline-tokens.js";
|
|
27
29
|
import { type ImSenderContext } from "./message-context.js";
|
|
28
30
|
import type { PermissionSelection } from "./permission-profiles.schemas.js";
|
|
29
31
|
import { PermissionProfilesService } from "./permission-profiles.service.js";
|
|
@@ -212,21 +214,31 @@ export interface RunControl {
|
|
|
212
214
|
includeSelf?: boolean;
|
|
213
215
|
}): Promise<number>;
|
|
214
216
|
}
|
|
215
|
-
/** 消息附件引用(连接器 + 资源 URI)。 */
|
|
216
|
-
export interface AttachmentRef {
|
|
217
|
-
connectorId: string;
|
|
218
|
-
uri: string;
|
|
219
|
-
}
|
|
220
217
|
/**
|
|
221
218
|
* Resolved `@` resources and referenced project files: the blocks after the user text (the
|
|
222
|
-
* resources' bodies, then one text block per project file) and their metadata.
|
|
219
|
+
* resources' bodies, then one text block per project file) and their metadata. A message with
|
|
220
|
+
* `tokens` (composer inline tokens spec §3) also gets its rendered text, where its placeholders
|
|
221
|
+
* stand, its connector mentions and its file tokens.
|
|
223
222
|
*/
|
|
224
223
|
export interface ResolvedExtra {
|
|
225
224
|
blocks: {
|
|
226
225
|
type: "text";
|
|
227
226
|
text: string;
|
|
228
227
|
}[];
|
|
229
|
-
/**
|
|
228
|
+
/**
|
|
229
|
+
* The text with each token marker replaced by its placeholder (a skill invocation's trimmed
|
|
230
|
+
* arguments); absent: the message has no tokens and its text is used as typed.
|
|
231
|
+
*/
|
|
232
|
+
text?: string;
|
|
233
|
+
/** Where each placeholder stands in {@link text} (`payload.inline`, display only). */
|
|
234
|
+
inline?: InlineEntry[];
|
|
235
|
+
/** The connectors the message names (`payload.connectorMentions`), in block order. */
|
|
236
|
+
connectorMentions?: ConnectorMention[];
|
|
237
|
+
/** The library files the message's file tokens name, in text order, before the uploads. */
|
|
238
|
+
fileTokenIds?: string[];
|
|
239
|
+
/** The label of each file (file tokens and uploads), numbered across them (spec §3.2). */
|
|
240
|
+
fileLabels?: Map<string, string>;
|
|
241
|
+
/** The resources' metadata in the user_message (payload fields `appId` / `appName`, C27). */
|
|
230
242
|
attachments: {
|
|
231
243
|
appId: string;
|
|
232
244
|
appName: string;
|
|
@@ -245,6 +257,26 @@ export interface ResolvedExtra {
|
|
|
245
257
|
*/
|
|
246
258
|
conversationRefs?: ConversationRefMeta[];
|
|
247
259
|
}
|
|
260
|
+
/** One connector a message names, as `payload.connectorMentions` records it (spec §3.5). */
|
|
261
|
+
export interface ConnectorMention {
|
|
262
|
+
connectorId: string;
|
|
263
|
+
slug: string;
|
|
264
|
+
name: string;
|
|
265
|
+
/** The agent's offered tools of it at send time. */
|
|
266
|
+
toolCount: number;
|
|
267
|
+
/**
|
|
268
|
+
* Its offered tool keys when it offers at most 20 (else empty), loaded from this message on when
|
|
269
|
+
* a step runs with tool search (inert without it).
|
|
270
|
+
*/
|
|
271
|
+
loadedTools: string[];
|
|
272
|
+
}
|
|
273
|
+
/** Where the agent's tools are resolved for a message that names connectors or resources. */
|
|
274
|
+
export interface MessageAgentContext {
|
|
275
|
+
agent: AgentDefinition;
|
|
276
|
+
source: ConversationSource;
|
|
277
|
+
/** The conversation the step's sandbox tools follow; absent for a conversation being created. */
|
|
278
|
+
sandboxConversationId?: string | undefined;
|
|
279
|
+
}
|
|
248
280
|
/** One referenced conversation as `payload.conversationRefs` names it. */
|
|
249
281
|
export interface ConversationRefMeta {
|
|
250
282
|
id: string;
|
|
@@ -273,6 +305,12 @@ export interface ProjectFilesTarget {
|
|
|
273
305
|
* the `user_message`, so replay rebuilds it from the log as it is.
|
|
274
306
|
*/
|
|
275
307
|
export declare const projectFileText: (path: string, root: string) => string;
|
|
308
|
+
/**
|
|
309
|
+
* The files' blocks with a `[file: <label>]` text block before each media block (composer inline
|
|
310
|
+
* tokens spec §3.3), so the model reads which file each one is (an image is sent bare). A file
|
|
311
|
+
* with no given label is labelled by its name, numbered after the given labels.
|
|
312
|
+
*/
|
|
313
|
+
export declare function withFileLines(blocks: readonly LogContentBlock[], labels?: ReadonlyMap<string, string>): LogContentBlock[];
|
|
276
314
|
export { userMessageIdemKey } from "./idem-keys.js";
|
|
277
315
|
/** The longest conversation title (characters, after trimming). */
|
|
278
316
|
export declare const CONVERSATION_TITLE_MAX_CHARS = 120;
|
|
@@ -285,22 +323,12 @@ export declare const EVENTS_TURN_EXTEND = 2000;
|
|
|
285
323
|
export interface UserMessageInput {
|
|
286
324
|
text: string;
|
|
287
325
|
clientMessageId?: string;
|
|
288
|
-
attachments?: AttachmentRef[];
|
|
289
|
-
files?: string[];
|
|
290
326
|
/**
|
|
291
|
-
*
|
|
292
|
-
*
|
|
327
|
+
* Inline tokens (composer inline tokens spec §3.1), one U+FFFC in `text` each, in order:
|
|
328
|
+
* connectors, connector resources, library files, project files and conversations.
|
|
293
329
|
*/
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}[];
|
|
297
|
-
/**
|
|
298
|
-
* The sender's own conversations referenced by id (@ conversations spec §1): each is read at
|
|
299
|
-
* send time into one text block ({@link conversationRefText}).
|
|
300
|
-
*/
|
|
301
|
-
conversationRefs?: {
|
|
302
|
-
id: string;
|
|
303
|
-
}[];
|
|
330
|
+
tokens?: MessageToken[];
|
|
331
|
+
files?: string[];
|
|
304
332
|
/** Switch the conversation's model from the next run (the agent's own model = back to it). */
|
|
305
333
|
model?: ModelRef;
|
|
306
334
|
/** Switch the effort (one of the model's declared `effort` values). */
|
|
@@ -394,15 +422,17 @@ export declare class ConversationsService {
|
|
|
394
422
|
private readonly ceilings;
|
|
395
423
|
/** Owes the snapshot deletions of the shares a deletion revokes (file sharing spec §9). */
|
|
396
424
|
private readonly outbox;
|
|
425
|
+
/** The agent's tools for a message naming connectors or resources (inline tokens §3.4). */
|
|
426
|
+
private readonly mentions;
|
|
397
427
|
constructor(permissions: Pick<PermissionProfilesService, "initialize" | "lockInitial">, db: KernelDb, eventLog: EventLog, agents: Pick<AgentLookup, "get">, access: Pick<ConversationAccess, "isAccessible">,
|
|
398
428
|
/** Starts and stops the conversation's runs. */
|
|
399
429
|
runs: RunControl,
|
|
400
430
|
/** Resolves a switched-to model and its declared parameters (UI refresh B). */
|
|
401
431
|
providers: Pick<ProviderRegistry, "resolve">,
|
|
402
432
|
/** Reads `@` resources with the sender's credentials. */
|
|
403
|
-
content: Pick<ConnectorContent, "
|
|
433
|
+
content: Pick<ConnectorContent, "readResources">,
|
|
404
434
|
/** Attaches the sender's library files to the conversation in the message's transaction. */
|
|
405
|
-
libraryFiles: Pick<LibraryFilesService, "attachForMessage">,
|
|
435
|
+
libraryFiles: Pick<LibraryFilesService, "attachForMessage" | "labelsFor" | "checkMessageFileCount">,
|
|
406
436
|
/** Renders a person's skill invocation (phase D). */
|
|
407
437
|
invoker: Pick<SkillInvoker, "prepare">,
|
|
408
438
|
/** Stops a deleted conversation's background tasks. */
|
|
@@ -418,7 +448,9 @@ export declare class ConversationsService {
|
|
|
418
448
|
/** ... and its pending network asks (network ask-to-allow spec §6.7). */
|
|
419
449
|
approvals: Pick<ApprovalsService, "skipNetworkIn">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost, ceilings: PermissionCeilingWrites,
|
|
420
450
|
/** Owes the snapshot deletions of the shares a deletion revokes (file sharing spec §9). */
|
|
421
|
-
outbox: Pick<OutboxService, "add"
|
|
451
|
+
outbox: Pick<OutboxService, "add">,
|
|
452
|
+
/** The agent's tools for a message naming connectors or resources (inline tokens §3.4). */
|
|
453
|
+
mentions: Pick<MentionableConnectorsService, "resolveForMessage">);
|
|
422
454
|
/**
|
|
423
455
|
* Creates an empty conversation bound to its device (`pick`, see
|
|
424
456
|
* {@link ConversationDevices.forNew}); an agent the account cannot use →
|
|
@@ -613,26 +645,17 @@ export declare class ConversationsService {
|
|
|
613
645
|
* ends. A failed `ensureRun` is logged, not thrown: the message's transaction owes the ensure-run
|
|
614
646
|
* backstop, which starts the run once the queue is reachable (transactional outbox spec §6).
|
|
615
647
|
*
|
|
616
|
-
* `
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
* `
|
|
620
|
-
* `clientMessageId` returns the written event without
|
|
648
|
+
* `tokens` (composer inline tokens spec §3): resolved as the sender before the write
|
|
649
|
+
* ({@link resolveExtra}): each marker becomes its placeholder in `content[0]`, the referenced
|
|
650
|
+
* blocks (resources, project files, conversations, connector mentions) follow it, and
|
|
651
|
+
* `payload.inline` / `connectorMentions` record them. Any refusal writes nothing; a repeated send
|
|
652
|
+
* with the same `clientMessageId` returns the written event without resolving again.
|
|
621
653
|
*
|
|
622
654
|
* `files` (uploaded attachment ids): checked and bound to this conversation in the transaction
|
|
623
655
|
* that writes the event (see {@link BindFiles}) and appended last as image / document reference
|
|
624
|
-
* blocks
|
|
625
|
-
* only references, never bytes. With empty `text` (files only: the HTTP layer ensures
|
|
626
|
-
* and no
|
|
627
|
-
*
|
|
628
|
-
* `projectFiles` (composer menus §5): checked in the conversation's stored project before the
|
|
629
|
-
* write ({@link resolveExtra}); one block each after the `@` resources' bodies, before the
|
|
630
|
-
* uploaded files' blocks, and `payload.projectFiles`. Any refusal writes nothing; a repeated
|
|
631
|
-
* send with the same `clientMessageId` returns the written event without checking again.
|
|
632
|
-
*
|
|
633
|
-
* `conversationRefs` (@ conversations spec §1): read as the sender in the same step, one block
|
|
634
|
-
* each after the project files' blocks, and `payload.conversationRefs`; refused and retried
|
|
635
|
-
* like the project files.
|
|
656
|
+
* blocks, each after its `[file: <name>]` line; any unavailable file writes nothing. The log
|
|
657
|
+
* holds only references, never bytes. With empty `text` (files only: the HTTP layer ensures
|
|
658
|
+
* `files` and no tokens then) no text block of the person's is written.
|
|
636
659
|
*/
|
|
637
660
|
postUserMessage(orgId: string, conversationId: string, accountId: string, input: UserMessageInput,
|
|
638
661
|
/** The request's signal: the project file check on the device stops when the client hangs up. */
|
|
@@ -703,19 +726,27 @@ export declare class ConversationsService {
|
|
|
703
726
|
* `skill`. The queue stores the result and sends it unchanged later.
|
|
704
727
|
*/
|
|
705
728
|
prepareQueuedSkill(orgId: string, conv: ConversationView, accountId: string, input: Pick<UserMessageInput, "skill" | "text">): Promise<RenderedInvocation | undefined>;
|
|
706
|
-
/**
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
*
|
|
712
|
-
*
|
|
713
|
-
*
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
|
|
718
|
-
|
|
729
|
+
/** Resolves what a message's tokens reference before it is written ({@link resolveTokens}). */
|
|
730
|
+
resolveExtra(orgId: string, accountId: string, input: Pick<UserMessageInput, "text" | "tokens" | "files" | "skill">, target?: ProjectFilesTarget,
|
|
731
|
+
/** Where the agent's tools are resolved; required when the tokens name connectors or resources. */
|
|
732
|
+
agentContext?: MessageAgentContext): Promise<ResolvedExtra>;
|
|
733
|
+
/**
|
|
734
|
+
* {@link resolveExtra} for a message with tokens (composer inline tokens spec §3), as the sender,
|
|
735
|
+
* outside any transaction; any refusal writes nothing. Each entity is resolved once however
|
|
736
|
+
* often its token repeats: project file paths are normalized first (a path leaving the project →
|
|
737
|
+
* `device.path_outside_project` before anything is read), then the connectors named and the
|
|
738
|
+
* resources' connectors against the agent's tools in one resolution
|
|
739
|
+
* ({@link MentionableConnectorsService.resolveForMessage}: `conversation.connector_unavailable`),
|
|
740
|
+
* the project files and the referenced conversations as without tokens, the resources last
|
|
741
|
+
* ({@link ConnectorContent.readResources}; one whose `read_resource` the agent is not offered →
|
|
742
|
+
* `connector.resources_disabled`), and the files' names. Labels are numbered per kind in text
|
|
743
|
+
* order (file tokens before uploads); each marker becomes its placeholder in the text (the trimmed
|
|
744
|
+
* arguments of a skill invocation, where `inline` then points). Blocks, in order: resources,
|
|
745
|
+
* project files, conversations, connector mentions; the files' blocks follow in the write.
|
|
746
|
+
*/
|
|
747
|
+
private resolveTokens;
|
|
748
|
+
/** The conversation's source (where it comes from: web, IM, an automation). */
|
|
749
|
+
private sourceOf;
|
|
719
750
|
/**
|
|
720
751
|
* {@link resolveExtra}'s referenced conversations (@ conversations spec §1), read as the sender
|
|
721
752
|
* outside any transaction, once each in the body's order. Each must be the sender's own chat in
|
|
@@ -735,12 +766,15 @@ export declare class ConversationsService {
|
|
|
735
766
|
* none → no blocks. The files join the conversation's files, so open pages read the list again
|
|
736
767
|
* after the commit (`changed: files`, a hint).
|
|
737
768
|
*/
|
|
738
|
-
bindIn(orgId: string, conversationId: string, accountId: string, files: readonly string[]
|
|
769
|
+
bindIn(orgId: string, conversationId: string, accountId: string, files: readonly string[],
|
|
770
|
+
/** Each file's label (composer inline tokens spec §3.2); a file not in it: its name. */
|
|
771
|
+
labels?: ReadonlyMap<string, string>): Promise<LogContentBlock[]>;
|
|
739
772
|
private userMessage;
|
|
740
773
|
/**
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
774
|
+
* Aborts the conversation's current run (queued / running / waiting): returns its runId; none →
|
|
775
|
+
* `run.not_active`. A run waiting for a person has no worker: its wait is cancelled and its end
|
|
776
|
+
* written here. Any other is broadcast through Redis, reaching whichever replica runs it; an
|
|
777
|
+
* orphaned run (no worker executing it) gets its end written directly.
|
|
744
778
|
*
|
|
745
779
|
* A root conversation's stop stops everything below it too (agent map spec §6, changed in
|
|
746
780
|
* acceptance 2026-11-13: after a person stops, the conversation stays stopped). In order:
|