@slashfi/agents-sdk 0.24.4 → 0.25.0
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/call-agent-schema.d.ts +56 -0
- package/dist/call-agent-schema.d.ts.map +1 -0
- package/dist/call-agent-schema.js +66 -0
- package/dist/call-agent-schema.js.map +1 -0
- package/dist/cjs/call-agent-schema.js +69 -0
- package/dist/cjs/call-agent-schema.js.map +1 -0
- package/dist/cjs/index.js +5 -5
- 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 +2 -37
- package/dist/cjs/server.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- 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.map +1 -1
- package/dist/server.js +2 -37
- 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/call-agent-schema.ts +68 -0
- package/src/index.ts +4 -13
- package/src/registry.ts +1 -25
- package/src/server.ts +2 -41
- 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/server.ts
CHANGED
|
@@ -45,9 +45,7 @@ import { type OIDCProviderConfig, createOIDCSignIn } from "./oidc-signin.js";
|
|
|
45
45
|
import type { AgentRegistry } from "./registry.js";
|
|
46
46
|
import type { AgentDefinition, CallAgentRequest, Visibility } from "./types.js";
|
|
47
47
|
|
|
48
|
-
import
|
|
49
|
-
AgentCallbackTrigger,
|
|
50
|
-
} from "./callback/index.js";
|
|
48
|
+
import { callAgentInputSchema } from "./call-agent-schema.js";
|
|
51
49
|
|
|
52
50
|
// ============================================
|
|
53
51
|
// Server Types
|
|
@@ -434,37 +432,7 @@ function getToolDefinitions() {
|
|
|
434
432
|
name: "call_agent",
|
|
435
433
|
description:
|
|
436
434
|
"Execute a tool on a registered agent. Provide the agent path and tool name.",
|
|
437
|
-
inputSchema:
|
|
438
|
-
type: "object",
|
|
439
|
-
properties: {
|
|
440
|
-
request: {
|
|
441
|
-
type: "object",
|
|
442
|
-
description: "The call request",
|
|
443
|
-
properties: {
|
|
444
|
-
action: {
|
|
445
|
-
type: "string",
|
|
446
|
-
enum: ["execute_tool", "describe_tools", "load"],
|
|
447
|
-
description: "Action to perform",
|
|
448
|
-
},
|
|
449
|
-
path: {
|
|
450
|
-
type: "string",
|
|
451
|
-
description: "Agent path (e.g., '@my-agent')",
|
|
452
|
-
},
|
|
453
|
-
tool: {
|
|
454
|
-
type: "string",
|
|
455
|
-
description: "Tool name to call",
|
|
456
|
-
},
|
|
457
|
-
params: {
|
|
458
|
-
type: "object",
|
|
459
|
-
description: "Parameters for the tool",
|
|
460
|
-
additionalProperties: true,
|
|
461
|
-
},
|
|
462
|
-
},
|
|
463
|
-
required: ["action", "path"],
|
|
464
|
-
},
|
|
465
|
-
},
|
|
466
|
-
required: ["request"],
|
|
467
|
-
},
|
|
435
|
+
inputSchema: callAgentInputSchema,
|
|
468
436
|
},
|
|
469
437
|
{
|
|
470
438
|
name: "list_agents",
|
|
@@ -576,7 +544,6 @@ export function createAgentServer(
|
|
|
576
544
|
) {
|
|
577
545
|
switch (toolName) {
|
|
578
546
|
case "call_agent": {
|
|
579
|
-
const trigger = args.trigger as AgentCallbackTrigger | undefined;
|
|
580
547
|
const req = (args.request ?? args) as CallAgentRequest;
|
|
581
548
|
|
|
582
549
|
// Inject auth context
|
|
@@ -592,12 +559,6 @@ export function createAgentServer(
|
|
|
592
559
|
req.callerType = "system";
|
|
593
560
|
}
|
|
594
561
|
|
|
595
|
-
// Pass trigger through to registry.call() which handles
|
|
596
|
-
// deferred execution via callbackStore if configured.
|
|
597
|
-
if (trigger) {
|
|
598
|
-
req.trigger = trigger;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
562
|
// Process secret params: resolve refs, store raw secrets
|
|
602
563
|
if ((req as any).params && secretStore) {
|
|
603
564
|
const ownerId = auth?.callerId ?? "anonymous";
|
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":"","sources":["../../src/callback/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAMD,MAAM,MAAM,mBAAmB,GAC3B,SAAS,GACT,WAAW,GACX,SAAS,GACT,WAAW,CAAC;AAMhB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,mBAAmB,CAAC;IAC5B,6FAA6F;IAC7F,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,qFAAqF;IACrF,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,IAAI,CAAC;CACpB;AAMD,MAAM,WAAW,0BAA0B;IACzC,0GAA0G;IAC1G,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAMD,MAAM,WAAW,2BAA2B;IAC1C,kCAAkC;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAMD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7D,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IACpD,OAAO,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC3E,MAAM,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 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/callback/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAoFH,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,UAAU,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,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAA8B,CAAC,EAAE,CAAC;YACxE,MAAM,CAAC,GAAG,CAAC,GAAG,wBAAwB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,MAAW,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAAiC,EACjC,cAAwB;IAExB,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAa,EAAE,CAAC;IAEpC,MAAM,WAAW,GAAG,CAAC,GAAY,EAAQ,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,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAA8B,CAAC,EAAE,CAAC;YACxE,MAAM,CAAC,GAAG,CAAC,GAAG,wBAAwB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,MAAW,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,SAAgB,yBAAyB,CACvC,QAAiC,EACjC,cAAwB;IAExB,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAa,EAAE,CAAC;IAEpC,MAAM,WAAW,GAAG,CAAC,GAAY,EAAQ,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"}
|
package/src/callback/index.ts
DELETED
|
@@ -1,161 +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
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
// Trigger Schema
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Base trigger type. Implementations extend this with specific trigger sources
|
|
24
|
-
* (e.g., slack_block_kit, webhook, timer).
|
|
25
|
-
*
|
|
26
|
-
* The `type` field discriminates between trigger sources.
|
|
27
|
-
* Additional fields are trigger-specific.
|
|
28
|
-
*/
|
|
29
|
-
export interface AgentCallbackTrigger {
|
|
30
|
-
type: string;
|
|
31
|
-
[key: string]: unknown;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
// Callback Status
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
export type AgentCallbackStatus =
|
|
39
|
-
| 'pending'
|
|
40
|
-
| 'completed'
|
|
41
|
-
| 'expired'
|
|
42
|
-
| 'cancelled';
|
|
43
|
-
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
// Callback Entry
|
|
46
|
-
// ---------------------------------------------------------------------------
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* A stored agent_callback — a call_agent command waiting for its trigger to fire.
|
|
50
|
-
*/
|
|
51
|
-
export interface AgentCallbackEntry {
|
|
52
|
-
id: string;
|
|
53
|
-
status: AgentCallbackStatus;
|
|
54
|
-
/** The call_agent command (includes trigger). Params may contain {{trigger.x}} templates. */
|
|
55
|
-
callback: Record<string, unknown>;
|
|
56
|
-
/** Key-value attributes for this callback (e.g., creator info, trigger metadata). */
|
|
57
|
-
attributes: Record<string, string>;
|
|
58
|
-
createdAt: Date;
|
|
59
|
-
completedAt?: Date;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
// Create Options
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
|
|
66
|
-
export interface CreateAgentCallbackOptions {
|
|
67
|
-
/** The call_agent command (includes trigger). May contain {{trigger.x}} template references in params. */
|
|
68
|
-
callback: Record<string, unknown>;
|
|
69
|
-
/** Initial attributes to set on creation. */
|
|
70
|
-
attributes?: Record<string, string>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ---------------------------------------------------------------------------
|
|
74
|
-
// Resolve Options
|
|
75
|
-
// ---------------------------------------------------------------------------
|
|
76
|
-
|
|
77
|
-
export interface ResolveAgentCallbackOptions {
|
|
78
|
-
/** The callback ID to resolve. */
|
|
79
|
-
id: string;
|
|
80
|
-
/** Values from the trigger source, keyed by variable name. */
|
|
81
|
-
values: Record<string, string>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
// Store Interface
|
|
86
|
-
// ---------------------------------------------------------------------------
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Agent Callback Store — persistence layer for deferred call_agent commands.
|
|
90
|
-
* Implementations can use any backing store (CockroachDB, SQLite, in-memory, etc.).
|
|
91
|
-
*/
|
|
92
|
-
export interface AgentCallbackStore {
|
|
93
|
-
create(options: CreateAgentCallbackOptions): Promise<string>;
|
|
94
|
-
get(id: string): Promise<AgentCallbackEntry | null>;
|
|
95
|
-
resolve(options: ResolveAgentCallbackOptions): Promise<AgentCallbackEntry>;
|
|
96
|
-
cancel(id: string): Promise<boolean>;
|
|
97
|
-
listPending(limit?: number): Promise<AgentCallbackEntry[]>;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
// Template Resolution
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Resolve {{trigger.variable}} references in an object tree.
|
|
106
|
-
* Scans all string values and replaces {{trigger.x}} with the
|
|
107
|
-
* corresponding value from triggerValues.
|
|
108
|
-
*
|
|
109
|
-
* Unresolved references are left as-is.
|
|
110
|
-
*/
|
|
111
|
-
export function resolveCallbackTemplates<T>(
|
|
112
|
-
obj: T,
|
|
113
|
-
triggerValues: Record<string, string>,
|
|
114
|
-
): T {
|
|
115
|
-
if (typeof obj === 'string') {
|
|
116
|
-
return obj.replace(/\{\{trigger\.(\w+)\}\}/g, (_match, varName: string) => {
|
|
117
|
-
return triggerValues[varName] ?? `{{trigger.${varName}}}`;
|
|
118
|
-
}) as T;
|
|
119
|
-
}
|
|
120
|
-
if (Array.isArray(obj)) {
|
|
121
|
-
return obj.map((item) => resolveCallbackTemplates(item, triggerValues)) as T;
|
|
122
|
-
}
|
|
123
|
-
if (obj !== null && typeof obj === 'object') {
|
|
124
|
-
const result: Record<string, unknown> = {};
|
|
125
|
-
for (const [key, val] of Object.entries(obj as Record<string, unknown>)) {
|
|
126
|
-
result[key] = resolveCallbackTemplates(val, triggerValues);
|
|
127
|
-
}
|
|
128
|
-
return result as T;
|
|
129
|
-
}
|
|
130
|
-
return obj;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Validate that all {{trigger.x}} references in a callback have
|
|
135
|
-
* corresponding variables in the provided set.
|
|
136
|
-
* Returns array of unresolved variable names, or empty if valid.
|
|
137
|
-
*/
|
|
138
|
-
export function validateCallbackTemplates(
|
|
139
|
-
callback: Record<string, unknown>,
|
|
140
|
-
knownVariables: string[],
|
|
141
|
-
): string[] {
|
|
142
|
-
const definedVars = new Set(knownVariables);
|
|
143
|
-
const referencedVars: string[] = [];
|
|
144
|
-
|
|
145
|
-
const scanForRefs = (obj: unknown): void => {
|
|
146
|
-
if (typeof obj === 'string') {
|
|
147
|
-
const matches = obj.matchAll(/\{\{trigger\.(\w+)\}\}/g);
|
|
148
|
-
for (const match of matches) {
|
|
149
|
-
referencedVars.push(match[1]);
|
|
150
|
-
}
|
|
151
|
-
} else if (Array.isArray(obj)) {
|
|
152
|
-
obj.forEach(scanForRefs);
|
|
153
|
-
} else if (obj !== null && typeof obj === 'object') {
|
|
154
|
-
Object.values(obj as Record<string, unknown>).forEach(scanForRefs);
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
scanForRefs(callback);
|
|
159
|
-
|
|
160
|
-
return referencedVars.filter((v) => !definedVars.has(v));
|
|
161
|
-
}
|