@slashfi/agents-sdk 0.24.5 → 0.25.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/bm25.d.ts +46 -0
- package/dist/bm25.d.ts.map +1 -0
- package/dist/bm25.js +103 -0
- package/dist/bm25.js.map +1 -0
- package/dist/call-agent-schema.d.ts +0 -12
- package/dist/call-agent-schema.d.ts.map +1 -1
- package/dist/call-agent-schema.js +0 -13
- package/dist/call-agent-schema.js.map +1 -1
- package/dist/cjs/bm25.js +106 -0
- package/dist/cjs/bm25.js.map +1 -0
- package/dist/cjs/call-agent-schema.js +0 -13
- package/dist/cjs/call-agent-schema.js.map +1 -1
- package/dist/cjs/index.js +6 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/registry.js +0 -19
- package/dist/cjs/registry.js.map +1 -1
- package/dist/cjs/server.js +105 -7
- package/dist/cjs/server.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts +0 -3
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +0 -19
- package/dist/registry.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +105 -7
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +1 -11
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/bm25.test.ts +86 -0
- package/src/bm25.ts +146 -0
- package/src/call-agent-schema.ts +0 -14
- package/src/index.ts +13 -18
- package/src/registry.ts +1 -25
- package/src/server.ts +126 -12
- package/src/types.ts +0 -13
- package/dist/callback/index.d.ts +0 -79
- package/dist/callback/index.d.ts.map +0 -1
- package/dist/callback/index.js +0 -70
- package/dist/callback/index.js.map +0 -1
- package/dist/cjs/callback/index.js +0 -74
- package/dist/cjs/callback/index.js.map +0 -1
- package/src/callback/index.ts +0 -161
package/src/call-agent-schema.ts
CHANGED
|
@@ -63,20 +63,6 @@ export const callAgentInputSchema = {
|
|
|
63
63
|
},
|
|
64
64
|
required: ["action", "path"] as const,
|
|
65
65
|
},
|
|
66
|
-
trigger: {
|
|
67
|
-
type: "object" as const,
|
|
68
|
-
description:
|
|
69
|
-
"When present, the call is deferred and stored as a callback. " +
|
|
70
|
-
"The call executes when the trigger fires with the required values.",
|
|
71
|
-
properties: {
|
|
72
|
-
type: {
|
|
73
|
-
type: "string" as const,
|
|
74
|
-
description: "Trigger type (e.g., 'webhook')",
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
required: ["type"] as const,
|
|
78
|
-
additionalProperties: true,
|
|
79
|
-
},
|
|
80
66
|
},
|
|
81
67
|
required: ["request"] as const,
|
|
82
68
|
};
|
package/src/index.ts
CHANGED
|
@@ -59,7 +59,6 @@ export type {
|
|
|
59
59
|
CallAgentDescribeToolsRequest,
|
|
60
60
|
CallAgentDescribeToolsResponse,
|
|
61
61
|
CallAgentErrorResponse,
|
|
62
|
-
CallAgentCallbackResponse,
|
|
63
62
|
CallAgentExecuteToolRequest,
|
|
64
63
|
CallAgentExecuteToolResponse,
|
|
65
64
|
CallAgentInvokeRequest,
|
|
@@ -342,23 +341,6 @@ export type {
|
|
|
342
341
|
export { introspectMcp } from "./introspect.js";
|
|
343
342
|
export type { IntrospectOptions } from "./introspect.js";
|
|
344
343
|
|
|
345
|
-
// ============================================
|
|
346
|
-
// Agent Callbacks (deferred call_agent commands)
|
|
347
|
-
// ============================================
|
|
348
|
-
|
|
349
|
-
export {
|
|
350
|
-
resolveCallbackTemplates,
|
|
351
|
-
validateCallbackTemplates,
|
|
352
|
-
} from "./callback/index.js";
|
|
353
|
-
export type {
|
|
354
|
-
AgentCallbackTrigger,
|
|
355
|
-
AgentCallbackStatus,
|
|
356
|
-
AgentCallbackEntry,
|
|
357
|
-
AgentCallbackStore,
|
|
358
|
-
CreateAgentCallbackOptions,
|
|
359
|
-
ResolveAgentCallbackOptions,
|
|
360
|
-
} from "./callback/index.js";
|
|
361
|
-
|
|
362
344
|
// ============================================
|
|
363
345
|
// call_agent Schema (shared source of truth)
|
|
364
346
|
// ============================================
|
|
@@ -379,3 +361,16 @@ export {
|
|
|
379
361
|
assertValidDefinition,
|
|
380
362
|
} from "./validate.js";
|
|
381
363
|
export type { ValidationResult } from "./validate.js";
|
|
364
|
+
|
|
365
|
+
// ============================================
|
|
366
|
+
// BM25 Search
|
|
367
|
+
// ============================================
|
|
368
|
+
|
|
369
|
+
export {
|
|
370
|
+
createBM25Index,
|
|
371
|
+
} from "./bm25.js";
|
|
372
|
+
export type {
|
|
373
|
+
BM25Options,
|
|
374
|
+
BM25Document,
|
|
375
|
+
BM25Result,
|
|
376
|
+
} from "./bm25.js";
|
package/src/registry.ts
CHANGED
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
import { dirname, resolve } from "node:path";
|
|
8
8
|
import type { AgentEvent, EventCallback, EventType } from "./events.js";
|
|
9
9
|
import { createEventBus } from "./events.js";
|
|
10
|
-
import type {
|
|
11
|
-
AgentCallbackStore,
|
|
12
|
-
} from "./callback/index.js";
|
|
13
10
|
import type { SerializedAgentDefinition } from "./serialized.js";
|
|
14
11
|
import type {
|
|
15
12
|
AgentAction,
|
|
@@ -70,8 +67,7 @@ export interface AgentRegistryOptions {
|
|
|
70
67
|
contextFactory?: ContextFactory;
|
|
71
68
|
/** Lifecycle middleware hooks */
|
|
72
69
|
middleware?: RegistryMiddleware;
|
|
73
|
-
|
|
74
|
-
callbackStore?: AgentCallbackStore;
|
|
70
|
+
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
/**
|
|
@@ -478,26 +474,6 @@ export function createAgentRegistry(
|
|
|
478
474
|
},
|
|
479
475
|
|
|
480
476
|
async call(request: CallAgentRequest): Promise<CallAgentResponse> {
|
|
481
|
-
// Deferred execution: if trigger is present and callback store is
|
|
482
|
-
// configured, store the call_agent command as a callback instead
|
|
483
|
-
// of executing it immediately.
|
|
484
|
-
if (request.trigger && options.callbackStore) {
|
|
485
|
-
// The trigger stays as part of the callback — cockroach stores it in the
|
|
486
|
-
// callback JSON column. Attributes are first-class key-value metadata.
|
|
487
|
-
const callbackId = await options.callbackStore.create({
|
|
488
|
-
callback: request as unknown as Record<string, unknown>,
|
|
489
|
-
attributes: {
|
|
490
|
-
...(request.callerId && { creatorId: request.callerId }),
|
|
491
|
-
...(request.callerType && { creatorType: request.callerType }),
|
|
492
|
-
},
|
|
493
|
-
});
|
|
494
|
-
return {
|
|
495
|
-
success: true,
|
|
496
|
-
callbackId,
|
|
497
|
-
message: "Callback created. It will execute when the trigger fires.",
|
|
498
|
-
} as CallAgentResponse;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
477
|
const agent = agents.get(request.path);
|
|
502
478
|
|
|
503
479
|
if (!agent) {
|
package/src/server.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Minimal JSON-RPC server implementing the MCP protocol for agent interaction.
|
|
5
5
|
* Handles only core SDK concerns:
|
|
6
6
|
* - MCP protocol (initialize, tools/list, tools/call)
|
|
7
|
-
* - Agent registry routing (call_agent, list_agents)
|
|
7
|
+
* - Agent registry routing (call_agent, list_agents, search_agent_tools)
|
|
8
8
|
* - Auth resolution (Bearer tokens, root key, JWT)
|
|
9
9
|
* - OAuth2 token exchange (client_credentials)
|
|
10
10
|
* - Health check
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
type SecretStore,
|
|
31
31
|
processSecretParams,
|
|
32
32
|
} from "./agent-definitions/secrets.js";
|
|
33
|
+
import { type BM25Document, createBM25Index } from "./bm25.js";
|
|
33
34
|
import { verifyJwt } from "./jwt.js";
|
|
34
35
|
import type { SigningKey } from "./jwt.js";
|
|
35
36
|
import {
|
|
@@ -45,10 +46,6 @@ import { type OIDCProviderConfig, createOIDCSignIn } from "./oidc-signin.js";
|
|
|
45
46
|
import type { AgentRegistry } from "./registry.js";
|
|
46
47
|
import type { AgentDefinition, CallAgentRequest, Visibility } from "./types.js";
|
|
47
48
|
|
|
48
|
-
import type {
|
|
49
|
-
AgentCallbackTrigger,
|
|
50
|
-
} from "./callback/index.js";
|
|
51
|
-
|
|
52
49
|
import { callAgentInputSchema } from "./call-agent-schema.js";
|
|
53
50
|
|
|
54
51
|
// ============================================
|
|
@@ -446,6 +443,32 @@ function getToolDefinitions() {
|
|
|
446
443
|
properties: {},
|
|
447
444
|
},
|
|
448
445
|
},
|
|
446
|
+
{
|
|
447
|
+
name: "search_agent_tools",
|
|
448
|
+
description:
|
|
449
|
+
"Search across all registered agent tools using natural language. Returns tools ranked by relevance using BM25 scoring.",
|
|
450
|
+
inputSchema: {
|
|
451
|
+
type: "object",
|
|
452
|
+
properties: {
|
|
453
|
+
query: {
|
|
454
|
+
type: "string",
|
|
455
|
+
description:
|
|
456
|
+
"Natural language search query (e.g. 'send a message', 'database query')",
|
|
457
|
+
},
|
|
458
|
+
agents: {
|
|
459
|
+
type: "array",
|
|
460
|
+
items: { type: "string" },
|
|
461
|
+
description:
|
|
462
|
+
"Optional list of agent paths to search within (e.g. ['@notifications', '@db']). Searches all agents if omitted.",
|
|
463
|
+
},
|
|
464
|
+
limit: {
|
|
465
|
+
type: "number",
|
|
466
|
+
description: "Maximum number of results to return (default: 10)",
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
required: ["query"],
|
|
470
|
+
},
|
|
471
|
+
},
|
|
449
472
|
];
|
|
450
473
|
}
|
|
451
474
|
|
|
@@ -548,7 +571,6 @@ export function createAgentServer(
|
|
|
548
571
|
) {
|
|
549
572
|
switch (toolName) {
|
|
550
573
|
case "call_agent": {
|
|
551
|
-
const trigger = args.trigger as AgentCallbackTrigger | undefined;
|
|
552
574
|
const req = (args.request ?? args) as CallAgentRequest;
|
|
553
575
|
|
|
554
576
|
// Inject auth context
|
|
@@ -564,12 +586,6 @@ export function createAgentServer(
|
|
|
564
586
|
req.callerType = "system";
|
|
565
587
|
}
|
|
566
588
|
|
|
567
|
-
// Pass trigger through to registry.call() which handles
|
|
568
|
-
// deferred execution via callbackStore if configured.
|
|
569
|
-
if (trigger) {
|
|
570
|
-
req.trigger = trigger;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
589
|
// Process secret params: resolve refs, store raw secrets
|
|
574
590
|
if ((req as any).params && secretStore) {
|
|
575
591
|
const ownerId = auth?.callerId ?? "anonymous";
|
|
@@ -620,6 +636,104 @@ export function createAgentServer(
|
|
|
620
636
|
});
|
|
621
637
|
}
|
|
622
638
|
|
|
639
|
+
case "search_agent_tools": {
|
|
640
|
+
const { query, agents: agentFilter, limit: resultLimit } = args as {
|
|
641
|
+
query: string;
|
|
642
|
+
agents?: string[];
|
|
643
|
+
limit?: number;
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
const agents = registry.list();
|
|
647
|
+
const visible = agents.filter((agent) => {
|
|
648
|
+
if (!canSeeAgent(agent, auth)) return false;
|
|
649
|
+
if (agentFilter && agentFilter.length > 0) {
|
|
650
|
+
return agentFilter.includes(agent.path);
|
|
651
|
+
}
|
|
652
|
+
return true;
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
// Build search documents from all visible tools
|
|
656
|
+
const documents: (BM25Document & {
|
|
657
|
+
agentPath: string;
|
|
658
|
+
toolName: string;
|
|
659
|
+
description: string;
|
|
660
|
+
agentName?: string;
|
|
661
|
+
agentDescription?: string;
|
|
662
|
+
})[] = [];
|
|
663
|
+
|
|
664
|
+
for (const agent of visible) {
|
|
665
|
+
const visibleTools = agent.tools.filter((t) => {
|
|
666
|
+
const tv = t.visibility ?? "internal";
|
|
667
|
+
if (auth?.isRoot) return true;
|
|
668
|
+
if (tv === "public") return true;
|
|
669
|
+
if (
|
|
670
|
+
tv === "authenticated" &&
|
|
671
|
+
auth?.callerId &&
|
|
672
|
+
auth.callerId !== "anonymous"
|
|
673
|
+
)
|
|
674
|
+
return true;
|
|
675
|
+
if (tv === "internal" && auth) return true;
|
|
676
|
+
return false;
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
for (const tool of visibleTools) {
|
|
680
|
+
// Build searchable text from tool name, description, agent context, and schema
|
|
681
|
+
const parts = [
|
|
682
|
+
tool.name,
|
|
683
|
+
tool.description,
|
|
684
|
+
agent.config?.name ?? "",
|
|
685
|
+
agent.config?.description ?? "",
|
|
686
|
+
agent.path,
|
|
687
|
+
];
|
|
688
|
+
|
|
689
|
+
// Include property names and descriptions from input schema
|
|
690
|
+
const schema = tool.inputSchema as any;
|
|
691
|
+
if (schema?.properties) {
|
|
692
|
+
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
693
|
+
parts.push(key);
|
|
694
|
+
if ((prop as any)?.description) {
|
|
695
|
+
parts.push((prop as any).description);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
documents.push({
|
|
701
|
+
id: `${agent.path}/${tool.name}`,
|
|
702
|
+
text: parts.join(" "),
|
|
703
|
+
agentPath: agent.path,
|
|
704
|
+
toolName: tool.name,
|
|
705
|
+
description: tool.description,
|
|
706
|
+
agentName: agent.config?.name,
|
|
707
|
+
agentDescription: agent.config?.description,
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
const index = createBM25Index(documents);
|
|
713
|
+
const results = index.search(query, resultLimit ?? 10);
|
|
714
|
+
|
|
715
|
+
// Map results back to tool details
|
|
716
|
+
const docMap = new Map(documents.map((d) => [d.id, d]));
|
|
717
|
+
const matches = results.map((r) => {
|
|
718
|
+
const doc = docMap.get(r.id)!;
|
|
719
|
+
return {
|
|
720
|
+
agentPath: doc.agentPath,
|
|
721
|
+
tool: doc.toolName,
|
|
722
|
+
description: doc.description,
|
|
723
|
+
agentName: doc.agentName,
|
|
724
|
+
agentDescription: doc.agentDescription,
|
|
725
|
+
score: r.score,
|
|
726
|
+
};
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
return mcpResult({
|
|
730
|
+
success: true,
|
|
731
|
+
query,
|
|
732
|
+
results: matches,
|
|
733
|
+
total: matches.length,
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
|
|
623
737
|
default:
|
|
624
738
|
throw new Error(`Unknown tool: ${toolName}`);
|
|
625
739
|
}
|
package/src/types.ts
CHANGED
|
@@ -702,8 +702,6 @@ export interface AgentDefinition<TContext extends ToolContext = ToolContext> {
|
|
|
702
702
|
// CallAgent Request Types
|
|
703
703
|
// ============================================
|
|
704
704
|
|
|
705
|
-
import type { AgentCallbackTrigger } from "./callback/index.js";
|
|
706
|
-
|
|
707
705
|
/** Base request fields */
|
|
708
706
|
interface CallAgentBaseRequest {
|
|
709
707
|
/** Target agent path */
|
|
@@ -714,9 +712,6 @@ interface CallAgentBaseRequest {
|
|
|
714
712
|
callerType?: CallerType;
|
|
715
713
|
/** Additional metadata */
|
|
716
714
|
metadata?: Record<string, unknown>;
|
|
717
|
-
/** When present, the call is deferred and stored as a callback.
|
|
718
|
-
* The call executes when the trigger fires with the required values. */
|
|
719
|
-
trigger?: AgentCallbackTrigger;
|
|
720
715
|
}
|
|
721
716
|
|
|
722
717
|
/** Invoke: fire-and-forget */
|
|
@@ -835,13 +830,6 @@ export interface CallAgentErrorResponse {
|
|
|
835
830
|
code?: string;
|
|
836
831
|
}
|
|
837
832
|
|
|
838
|
-
/** Success response for deferred callback creation */
|
|
839
|
-
export interface CallAgentCallbackResponse {
|
|
840
|
-
success: true;
|
|
841
|
-
callbackId: string;
|
|
842
|
-
message: string;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
833
|
/** Union of all response types */
|
|
846
834
|
export type CallAgentResponse =
|
|
847
835
|
| CallAgentInvokeResponse
|
|
@@ -850,5 +838,4 @@ export type CallAgentResponse =
|
|
|
850
838
|
| CallAgentDescribeToolsResponse
|
|
851
839
|
| CallAgentLoadResponse
|
|
852
840
|
| CallAgentLearnResponse
|
|
853
|
-
| CallAgentCallbackResponse
|
|
854
841
|
| CallAgentErrorResponse;
|
package/dist/callback/index.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Callback — Deferred call_agent execution with triggers.
|
|
3
|
-
*
|
|
4
|
-
* An agent_callback is a call_agent command with an optional trigger.
|
|
5
|
-
* When the trigger fires (e.g., user submits a form), template references
|
|
6
|
-
* like {{trigger.variable_name}} are resolved with the trigger's values
|
|
7
|
-
* and the call_agent command is executed.
|
|
8
|
-
*
|
|
9
|
-
* This module provides the unopinionated contract:
|
|
10
|
-
* - Trigger schema (extensible discriminated union)
|
|
11
|
-
* - Template resolution
|
|
12
|
-
* - Store interface
|
|
13
|
-
* - Validation utilities
|
|
14
|
-
*
|
|
15
|
-
* No platform-specific code (no Slack, no CockroachDB, no Atlas).
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Base trigger type. Implementations extend this with specific trigger sources
|
|
19
|
-
* (e.g., slack_block_kit, webhook, timer).
|
|
20
|
-
*
|
|
21
|
-
* The `type` field discriminates between trigger sources.
|
|
22
|
-
* Additional fields are trigger-specific.
|
|
23
|
-
*/
|
|
24
|
-
export interface AgentCallbackTrigger {
|
|
25
|
-
type: string;
|
|
26
|
-
[key: string]: unknown;
|
|
27
|
-
}
|
|
28
|
-
export type AgentCallbackStatus = 'pending' | 'completed' | 'expired' | 'cancelled';
|
|
29
|
-
/**
|
|
30
|
-
* A stored agent_callback — a call_agent command waiting for its trigger to fire.
|
|
31
|
-
*/
|
|
32
|
-
export interface AgentCallbackEntry {
|
|
33
|
-
id: string;
|
|
34
|
-
status: AgentCallbackStatus;
|
|
35
|
-
/** The call_agent command (includes trigger). Params may contain {{trigger.x}} templates. */
|
|
36
|
-
callback: Record<string, unknown>;
|
|
37
|
-
/** Key-value attributes for this callback (e.g., creator info, trigger metadata). */
|
|
38
|
-
attributes: Record<string, string>;
|
|
39
|
-
createdAt: Date;
|
|
40
|
-
completedAt?: Date;
|
|
41
|
-
}
|
|
42
|
-
export interface CreateAgentCallbackOptions {
|
|
43
|
-
/** The call_agent command (includes trigger). May contain {{trigger.x}} template references in params. */
|
|
44
|
-
callback: Record<string, unknown>;
|
|
45
|
-
/** Initial attributes to set on creation. */
|
|
46
|
-
attributes?: Record<string, string>;
|
|
47
|
-
}
|
|
48
|
-
export interface ResolveAgentCallbackOptions {
|
|
49
|
-
/** The callback ID to resolve. */
|
|
50
|
-
id: string;
|
|
51
|
-
/** Values from the trigger source, keyed by variable name. */
|
|
52
|
-
values: Record<string, string>;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Agent Callback Store — persistence layer for deferred call_agent commands.
|
|
56
|
-
* Implementations can use any backing store (CockroachDB, SQLite, in-memory, etc.).
|
|
57
|
-
*/
|
|
58
|
-
export interface AgentCallbackStore {
|
|
59
|
-
create(options: CreateAgentCallbackOptions): Promise<string>;
|
|
60
|
-
get(id: string): Promise<AgentCallbackEntry | null>;
|
|
61
|
-
resolve(options: ResolveAgentCallbackOptions): Promise<AgentCallbackEntry>;
|
|
62
|
-
cancel(id: string): Promise<boolean>;
|
|
63
|
-
listPending(limit?: number): Promise<AgentCallbackEntry[]>;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Resolve {{trigger.variable}} references in an object tree.
|
|
67
|
-
* Scans all string values and replaces {{trigger.x}} with the
|
|
68
|
-
* corresponding value from triggerValues.
|
|
69
|
-
*
|
|
70
|
-
* Unresolved references are left as-is.
|
|
71
|
-
*/
|
|
72
|
-
export declare function resolveCallbackTemplates<T>(obj: T, triggerValues: Record<string, string>): T;
|
|
73
|
-
/**
|
|
74
|
-
* Validate that all {{trigger.x}} references in a callback have
|
|
75
|
-
* corresponding variables in the provided set.
|
|
76
|
-
* Returns array of unresolved variable names, or empty if valid.
|
|
77
|
-
*/
|
|
78
|
-
export declare function validateCallbackTemplates(callback: Record<string, unknown>, knownVariables: string[]): string[];
|
|
79
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot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,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;CAC5D;AAMD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,GAAG,EAAE,CAAC,EACN,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,CAAC,CAiBH;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,cAAc,EAAE,MAAM,EAAE,GACvB,MAAM,EAAE,CAoBV"}
|
package/dist/callback/index.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Callback — Deferred call_agent execution with triggers.
|
|
3
|
-
*
|
|
4
|
-
* An agent_callback is a call_agent command with an optional trigger.
|
|
5
|
-
* When the trigger fires (e.g., user submits a form), template references
|
|
6
|
-
* like {{trigger.variable_name}} are resolved with the trigger's values
|
|
7
|
-
* and the call_agent command is executed.
|
|
8
|
-
*
|
|
9
|
-
* This module provides the unopinionated contract:
|
|
10
|
-
* - Trigger schema (extensible discriminated union)
|
|
11
|
-
* - Template resolution
|
|
12
|
-
* - Store interface
|
|
13
|
-
* - Validation utilities
|
|
14
|
-
*
|
|
15
|
-
* No platform-specific code (no Slack, no CockroachDB, no Atlas).
|
|
16
|
-
*/
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
// Template Resolution
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
/**
|
|
21
|
-
* Resolve {{trigger.variable}} references in an object tree.
|
|
22
|
-
* Scans all string values and replaces {{trigger.x}} with the
|
|
23
|
-
* corresponding value from triggerValues.
|
|
24
|
-
*
|
|
25
|
-
* Unresolved references are left as-is.
|
|
26
|
-
*/
|
|
27
|
-
export function resolveCallbackTemplates(obj, triggerValues) {
|
|
28
|
-
if (typeof obj === 'string') {
|
|
29
|
-
return obj.replace(/\{\{trigger\.(\w+)\}\}/g, (_match, varName) => {
|
|
30
|
-
return triggerValues[varName] ?? `{{trigger.${varName}}}`;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
if (Array.isArray(obj)) {
|
|
34
|
-
return obj.map((item) => resolveCallbackTemplates(item, triggerValues));
|
|
35
|
-
}
|
|
36
|
-
if (obj !== null && typeof obj === 'object') {
|
|
37
|
-
const result = {};
|
|
38
|
-
for (const [key, val] of Object.entries(obj)) {
|
|
39
|
-
result[key] = resolveCallbackTemplates(val, triggerValues);
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
return obj;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Validate that all {{trigger.x}} references in a callback have
|
|
47
|
-
* corresponding variables in the provided set.
|
|
48
|
-
* Returns array of unresolved variable names, or empty if valid.
|
|
49
|
-
*/
|
|
50
|
-
export function validateCallbackTemplates(callback, knownVariables) {
|
|
51
|
-
const definedVars = new Set(knownVariables);
|
|
52
|
-
const referencedVars = [];
|
|
53
|
-
const scanForRefs = (obj) => {
|
|
54
|
-
if (typeof obj === 'string') {
|
|
55
|
-
const matches = obj.matchAll(/\{\{trigger\.(\w+)\}\}/g);
|
|
56
|
-
for (const match of matches) {
|
|
57
|
-
referencedVars.push(match[1]);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else if (Array.isArray(obj)) {
|
|
61
|
-
obj.forEach(scanForRefs);
|
|
62
|
-
}
|
|
63
|
-
else if (obj !== null && typeof obj === 'object') {
|
|
64
|
-
Object.values(obj).forEach(scanForRefs);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
scanForRefs(callback);
|
|
68
|
-
return referencedVars.filter((v) => !definedVars.has(v));
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|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EAAE;QACzC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC;YACxD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC5B,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC3B,CAAC;aAAM,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACnD,MAAM,CAAC,MAAM,CAAC,GAA8B,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC;IAEF,WAAW,CAAC,QAAQ,CAAC,CAAC;IAEtB,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Agent Callback — Deferred call_agent execution with triggers.
|
|
4
|
-
*
|
|
5
|
-
* An agent_callback is a call_agent command with an optional trigger.
|
|
6
|
-
* When the trigger fires (e.g., user submits a form), template references
|
|
7
|
-
* like {{trigger.variable_name}} are resolved with the trigger's values
|
|
8
|
-
* and the call_agent command is executed.
|
|
9
|
-
*
|
|
10
|
-
* This module provides the unopinionated contract:
|
|
11
|
-
* - Trigger schema (extensible discriminated union)
|
|
12
|
-
* - Template resolution
|
|
13
|
-
* - Store interface
|
|
14
|
-
* - Validation utilities
|
|
15
|
-
*
|
|
16
|
-
* No platform-specific code (no Slack, no CockroachDB, no Atlas).
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.resolveCallbackTemplates = resolveCallbackTemplates;
|
|
20
|
-
exports.validateCallbackTemplates = validateCallbackTemplates;
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Template Resolution
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
/**
|
|
25
|
-
* Resolve {{trigger.variable}} references in an object tree.
|
|
26
|
-
* Scans all string values and replaces {{trigger.x}} with the
|
|
27
|
-
* corresponding value from triggerValues.
|
|
28
|
-
*
|
|
29
|
-
* Unresolved references are left as-is.
|
|
30
|
-
*/
|
|
31
|
-
function resolveCallbackTemplates(obj, triggerValues) {
|
|
32
|
-
if (typeof obj === 'string') {
|
|
33
|
-
return obj.replace(/\{\{trigger\.(\w+)\}\}/g, (_match, varName) => {
|
|
34
|
-
return triggerValues[varName] ?? `{{trigger.${varName}}}`;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (Array.isArray(obj)) {
|
|
38
|
-
return obj.map((item) => resolveCallbackTemplates(item, triggerValues));
|
|
39
|
-
}
|
|
40
|
-
if (obj !== null && typeof obj === 'object') {
|
|
41
|
-
const result = {};
|
|
42
|
-
for (const [key, val] of Object.entries(obj)) {
|
|
43
|
-
result[key] = resolveCallbackTemplates(val, triggerValues);
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
return obj;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Validate that all {{trigger.x}} references in a callback have
|
|
51
|
-
* corresponding variables in the provided set.
|
|
52
|
-
* Returns array of unresolved variable names, or empty if valid.
|
|
53
|
-
*/
|
|
54
|
-
function validateCallbackTemplates(callback, knownVariables) {
|
|
55
|
-
const definedVars = new Set(knownVariables);
|
|
56
|
-
const referencedVars = [];
|
|
57
|
-
const scanForRefs = (obj) => {
|
|
58
|
-
if (typeof obj === 'string') {
|
|
59
|
-
const matches = obj.matchAll(/\{\{trigger\.(\w+)\}\}/g);
|
|
60
|
-
for (const match of matches) {
|
|
61
|
-
referencedVars.push(match[1]);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (Array.isArray(obj)) {
|
|
65
|
-
obj.forEach(scanForRefs);
|
|
66
|
-
}
|
|
67
|
-
else if (obj !== null && typeof obj === 'object') {
|
|
68
|
-
Object.values(obj).forEach(scanForRefs);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
scanForRefs(callback);
|
|
72
|
-
return referencedVars.filter((v) => !definedVars.has(v));
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/callback/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AA+FH,4DAoBC;AAOD,8DAuBC;AA7DD,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,GAAM,EACN,aAAqC;IAErC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC,OAAO,CAAC,yBAAyB,EAAE,CAAC,MAAM,EAAE,OAAe,EAAE,EAAE;YACxE,OAAO,aAAa,CAAC,OAAO,CAAC,IAAI,aAAa,OAAO,IAAI,CAAC;QAC5D,CAAC,CAAM,CAAC;IACV,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,wBAAwB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAM,CAAC;IAC/E,CAAC;IACD,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5C,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,KAAK,MAAM,CAAC,GAA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