@finalai/agent-definition 0.4.3 → 0.5.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/compiler-assets/{chunk-JFNLGXQM.ts → chunk-JRKGCYWA.ts} +10 -10
- package/dist/compiler-assets/{chunk-BLF6KTBB.ts → chunk-KMBQVNAJ.ts} +2 -2
- package/dist/compiler-assets/{chunk-6MVG5NYI.ts → chunk-OVAUXBQU.ts} +2 -2
- package/dist/compiler-assets/src/authoring/channels.ts +1 -1
- package/dist/compiler-assets/src/authoring/hooks.ts +1 -1
- package/dist/compiler-assets/src/authoring/index.ts +2 -2
- package/dist/compiler-assets/src/index.ts +2 -2
- package/dist/compiler-assets/src/runtime/bundle.ts +3 -3
- package/dist/compiler-assets/src/runtime/isolate.ts +3 -3
- package/dist/modules/authoring/channels.d.mts +6 -6
- package/dist/modules/authoring/channels.mjs.map +1 -1
- package/dist/modules/authoring/hooks.d.mts +6 -6
- package/dist/modules/authoring/hooks.mjs +2 -2
- package/dist/modules/authoring/hooks.mjs.map +2 -2
- package/package.json +3 -3
|
@@ -58,19 +58,19 @@ var channelMessageInputSchema = object({
|
|
|
58
58
|
quotedMessageIds: array(string().min(1)).default([]),
|
|
59
59
|
mentionedParticipantIds: array(string().min(1)).default([])
|
|
60
60
|
});
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
})(
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
kind: nativeEnum(
|
|
61
|
+
var DecisionKind = /* @__PURE__ */ ((DecisionKind2) => {
|
|
62
|
+
DecisionKind2["Permission"] = "permission";
|
|
63
|
+
DecisionKind2["Elicitation"] = "elicitation";
|
|
64
|
+
return DecisionKind2;
|
|
65
|
+
})(DecisionKind || {});
|
|
66
|
+
var decisionCreatedDataSchema = object({
|
|
67
|
+
decisionId: string().min(1),
|
|
68
|
+
kind: nativeEnum(DecisionKind),
|
|
69
69
|
audienceParticipantIds: array(string()),
|
|
70
70
|
request: jsonValueSchema
|
|
71
71
|
});
|
|
72
|
-
var
|
|
73
|
-
|
|
72
|
+
var decisionResolvedDataSchema = object({
|
|
73
|
+
decisionId: string().min(1),
|
|
74
74
|
outcome: jsonValueSchema,
|
|
75
75
|
respondedBy: channelAuthSchema.nullable().default(null)
|
|
76
76
|
});
|
|
@@ -22,8 +22,8 @@ var HookEvent = /* @__PURE__ */ ((HookEvent2) => {
|
|
|
22
22
|
HookEvent2["ToolCallUpdate"] = "tool_call_update";
|
|
23
23
|
HookEvent2["ToolCallContentChunk"] = "tool_call_content_chunk";
|
|
24
24
|
HookEvent2["Plan"] = "plan";
|
|
25
|
-
HookEvent2["
|
|
26
|
-
HookEvent2["
|
|
25
|
+
HookEvent2["DecisionCreated"] = "decision.created";
|
|
26
|
+
HookEvent2["DecisionResolved"] = "decision.resolved";
|
|
27
27
|
HookEvent2["StateUpdate"] = "state_update";
|
|
28
28
|
HookEvent2["SessionFailed"] = "session.failed";
|
|
29
29
|
HookEvent2["SessionClosed"] = "session.closed";
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "./chunk-NMYHO2QN.ts";
|
|
15
15
|
import {
|
|
16
16
|
hookHandlersFor
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-KMBQVNAJ.ts";
|
|
18
18
|
import {
|
|
19
19
|
unopenedRequestOf
|
|
20
20
|
} from "./chunk-KNFPKVUS.ts";
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
import {
|
|
29
29
|
ConversationKind,
|
|
30
30
|
ParticipantKind
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-JRKGCYWA.ts";
|
|
32
32
|
import {
|
|
33
33
|
mcpServerBindingSchema,
|
|
34
34
|
providerRefSchema
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
defineProviderChannel,
|
|
10
10
|
disableChannel
|
|
11
11
|
} from "../../chunk-ISYIPH2T.ts";
|
|
12
|
-
import "../../chunk-
|
|
12
|
+
import "../../chunk-JRKGCYWA.ts";
|
|
13
13
|
import "../../chunk-FU5VHNO4.ts";
|
|
14
14
|
import "../../chunk-KTBNDKGJ.ts";
|
|
15
15
|
import "../../chunk-OX46N5EP.ts";
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
HookEvent,
|
|
8
8
|
defineHook
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-KMBQVNAJ.ts";
|
|
10
10
|
import {
|
|
11
11
|
defineInstructions
|
|
12
12
|
} from "../../chunk-WJPAUIVM.ts";
|
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
defineProviderChannel,
|
|
49
49
|
disableChannel
|
|
50
50
|
} from "../../chunk-ISYIPH2T.ts";
|
|
51
|
-
import "../../chunk-
|
|
51
|
+
import "../../chunk-JRKGCYWA.ts";
|
|
52
52
|
import {
|
|
53
53
|
defineHostedConnection,
|
|
54
54
|
defineMcpClientConnection
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
HookEvent,
|
|
21
21
|
defineHook
|
|
22
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-KMBQVNAJ.ts";
|
|
23
23
|
import {
|
|
24
24
|
defineInstructions
|
|
25
25
|
} from "../chunk-WJPAUIVM.ts";
|
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
defineProviderChannel,
|
|
62
62
|
disableChannel
|
|
63
63
|
} from "../chunk-ISYIPH2T.ts";
|
|
64
|
-
import "../chunk-
|
|
64
|
+
import "../chunk-JRKGCYWA.ts";
|
|
65
65
|
import {
|
|
66
66
|
defineHostedConnection,
|
|
67
67
|
defineMcpClientConnection
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
combineMcpServers,
|
|
3
3
|
createIsolateRuntime
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-OVAUXBQU.ts";
|
|
5
5
|
import {
|
|
6
6
|
describeBundle,
|
|
7
7
|
needsCombinedMcpServers,
|
|
@@ -12,13 +12,13 @@ import {
|
|
|
12
12
|
COMBINED_MCP_SERVERS_EXPORT,
|
|
13
13
|
namedExportName
|
|
14
14
|
} from "../../chunk-NMYHO2QN.ts";
|
|
15
|
-
import "../../chunk-
|
|
15
|
+
import "../../chunk-KMBQVNAJ.ts";
|
|
16
16
|
import "../../chunk-KNFPKVUS.ts";
|
|
17
17
|
import {
|
|
18
18
|
registerToolName
|
|
19
19
|
} from "../../chunk-4ERFBLH7.ts";
|
|
20
20
|
import "../../chunk-TFPXCL5W.ts";
|
|
21
|
-
import "../../chunk-
|
|
21
|
+
import "../../chunk-JRKGCYWA.ts";
|
|
22
22
|
import "../../chunk-VI5WBWUX.ts";
|
|
23
23
|
import "../../chunk-GOIK7WNT.ts";
|
|
24
24
|
import "../../chunk-RWUIMTBI.ts";
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
combineMcpServers,
|
|
3
3
|
createIsolateRuntime,
|
|
4
4
|
lowerResolvedValue
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-OVAUXBQU.ts";
|
|
6
6
|
import "../../chunk-ZICJVGG7.ts";
|
|
7
7
|
import "../../chunk-NMYHO2QN.ts";
|
|
8
|
-
import "../../chunk-
|
|
8
|
+
import "../../chunk-KMBQVNAJ.ts";
|
|
9
9
|
import "../../chunk-KNFPKVUS.ts";
|
|
10
10
|
import "../../chunk-4ERFBLH7.ts";
|
|
11
11
|
import "../../chunk-TFPXCL5W.ts";
|
|
12
|
-
import "../../chunk-
|
|
12
|
+
import "../../chunk-JRKGCYWA.ts";
|
|
13
13
|
import "../../chunk-VI5WBWUX.ts";
|
|
14
14
|
import "../../chunk-GOIK7WNT.ts";
|
|
15
15
|
import "../../chunk-RWUIMTBI.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AcpUpdateKind, KnownAcpUpdateKind, ChannelAddressContextIface, ChannelDefinitionIface, ChannelEventHandler, ChannelReceiveContextIface, ChannelReceiveResult, ChannelSemanticDataByKindIface, HttpChannelRouteDefinitionIface, JsonObject, JsonValue,
|
|
1
|
+
import type { AcpUpdateKind, KnownAcpUpdateKind, ChannelAddressContextIface, ChannelDefinitionIface, ChannelEventHandler, ChannelReceiveContextIface, ChannelReceiveResult, ChannelSemanticDataByKindIface, HttpChannelRouteDefinitionIface, JsonObject, JsonValue, DecisionEventKind, ProjectionContextIface, TurnPolicy, WebSocketChannelRouteDefinitionIface } from '@finalai/agent-provider';
|
|
2
2
|
export { channelAccessors } from '@finalai/agent-provider';
|
|
3
3
|
export type RouteHandler = HttpChannelRouteDefinitionIface['handler'];
|
|
4
4
|
export type RouteHandlerArgsIface = Parameters<RouteHandler>[0];
|
|
@@ -24,7 +24,7 @@ export type AuthoredSemanticEventsIface = {
|
|
|
24
24
|
};
|
|
25
25
|
type AuthoredSemanticHandlerIface = NonNullable<AuthoredSemanticEventsIface[keyof AuthoredSemanticEventsIface]>;
|
|
26
26
|
export type AuthoredChannelEventsIface = AuthoredSemanticEventsIface & {
|
|
27
|
-
[Kind in `${
|
|
27
|
+
[Kind in `${DecisionEventKind}` | KnownAcpUpdateKind]?: ChannelEventHandler;
|
|
28
28
|
} & {
|
|
29
29
|
[kind: AcpUpdateKind]: ChannelEventHandler | AuthoredSemanticHandlerIface | undefined;
|
|
30
30
|
};
|
|
@@ -55,8 +55,8 @@ export declare const defineChannel: <TChannel extends AuthoredChannelDefinitionI
|
|
|
55
55
|
subagent_update?: ChannelEventHandler | undefined;
|
|
56
56
|
session_message?: ChannelEventHandler | undefined;
|
|
57
57
|
session_message_chunk?: ChannelEventHandler | undefined;
|
|
58
|
-
"
|
|
59
|
-
"
|
|
58
|
+
"decision.created"?: ChannelEventHandler | undefined;
|
|
59
|
+
"decision.resolved"?: ChannelEventHandler | undefined;
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
62
|
export declare const disableChannel: () => Omit<{
|
|
@@ -88,8 +88,8 @@ export declare const disableChannel: () => Omit<{
|
|
|
88
88
|
subagent_update?: ChannelEventHandler | undefined;
|
|
89
89
|
session_message?: ChannelEventHandler | undefined;
|
|
90
90
|
session_message_chunk?: ChannelEventHandler | undefined;
|
|
91
|
-
"
|
|
92
|
-
"
|
|
91
|
+
"decision.created"?: ChannelEventHandler | undefined;
|
|
92
|
+
"decision.resolved"?: ChannelEventHandler | undefined;
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
95
|
export declare const GET: (path: string, handler: RouteHandler) => HttpChannelRouteDefinitionIface;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/authoring/channels.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n AcpUpdateKind,\n KnownAcpUpdateKind,\n ChannelAddressContextIface,\n ChannelDefinitionIface,\n ChannelEventHandler,\n ChannelReceiveContextIface,\n ChannelReceiveResult,\n ChannelSemanticDataByKindIface,\n HttpChannelRouteDefinitionIface,\n JsonObject,\n JsonValue,\n
|
|
4
|
+
"sourcesContent": ["import type {\n AcpUpdateKind,\n KnownAcpUpdateKind,\n ChannelAddressContextIface,\n ChannelDefinitionIface,\n ChannelEventHandler,\n ChannelReceiveContextIface,\n ChannelReceiveResult,\n ChannelSemanticDataByKindIface,\n HttpChannelRouteDefinitionIface,\n JsonObject,\n JsonValue,\n DecisionEventKind,\n ProjectionContextIface,\n TurnPolicy,\n WebSocketChannelRouteDefinitionIface,\n} from '@finalai/agent-provider';\nimport {\n channelAccessors,\n channelMessageCompletedSchema,\n jsonObjectSchema,\n} from '@finalai/agent-provider';\n\n// Session handles over a projection context's platform (`attachSession(ctx.sessionId)`)\n// for raw event handlers (`decision.created`, ACP updates).\nexport { channelAccessors } from '@finalai/agent-provider';\nimport * as z from 'zod';\nimport { AuthoredKind, stamp } from \"./brand.mjs\";\n\n// A custom channel in channels/<stem>.ts. Its routes run\n// in the agent's Worker isolate and are mounted by the session service's\n// front door at /<org>/<agent>/<stem><path> (and /b/<bindingId><path>);\n// the members it authors (receive, route, project, events) run there too,\n// driven by the session service exactly like a built-in channel's. What it\n// leaves out is the platform default: receive takes `{ target, content }`,\n// route follows the default routing rules, and the conversation's own channel projects.\n//\n// A bundle channel sees wire ids everywhere (conversations `conv_\u2026`,\n// participants `cpart_\u2026`, messages `cnmsg_\u2026`, users `usr_\u2026`, its binding\n// `chbind_\u2026`, turns `atrn_\u2026`, decisions `adec_\u2026`), the same strings the\n// public API returns, and must pass wire ids back to `ctx.platform`, `receive`\n// results and route decisions; raw UUIDs are refused.\n\nexport type RouteHandler = HttpChannelRouteDefinitionIface['handler'];\nexport type RouteHandlerArgsIface = Parameters<RouteHandler>[0];\n\nexport type AuthoredChannelDefinitionIface = Partial<\n Omit<ChannelDefinitionIface<JsonValue, JsonValue>, 'turnPolicy' | 'events' | 'receive'>\n> & {\n receive?: (\n input: JsonValue,\n ctx: ChannelReceiveContextIface & ChannelAddressContextIface,\n ) => Promise<ChannelReceiveResult>;\n events?: AuthoredChannelEventsIface;\n readonly turnPolicy?: TurnPolicy | `${TurnPolicy}`;\n // Static binding config recorded in the manifest.\n readonly config?: JsonObject;\n readonly disabled?: boolean;\n};\n\nexport interface AuthoredChannelContextIface extends ChannelAddressContextIface {\n platform: ProjectionContextIface['platform'];\n}\nexport interface AuthoredSessionContextIface {\n sessionId: string | null;\n turnId: string;\n state: ProjectionContextIface['state'];\n // The binding's config and the agent's secrets: what a channel needs to post\n // its replies back to its own service.\n config: JsonObject;\n secrets: ProjectionContextIface['secrets'];\n}\nexport type AuthoredSemanticEventsIface = {\n [Kind in keyof ChannelSemanticDataByKindIface]?: (\n data: ChannelSemanticDataByKindIface[Kind],\n channel: AuthoredChannelContextIface,\n ctx: AuthoredSessionContextIface,\n ) => void | Promise<void>;\n};\n\ntype AuthoredSemanticHandlerIface = NonNullable<\n AuthoredSemanticEventsIface[keyof AuthoredSemanticEventsIface]\n>;\n\n// Semantic events (`message.delta`, \u2026) take `(data, channel, ctx)`; decision\n// events and ACP update kinds (`tool_call`, `plan`, \u2026) the raw `(event, ctx)`.\n// Named kinds keep a single handler type, so their parameters are typed from\n// context; ACP kinds the SDK does not name share the open index signature and\n// need annotated parameters.\nexport type AuthoredChannelEventsIface = AuthoredSemanticEventsIface & {\n [Kind in `${DecisionEventKind}` | KnownAcpUpdateKind]?: ChannelEventHandler;\n} & {\n [kind: AcpUpdateKind]: ChannelEventHandler | AuthoredSemanticHandlerIface | undefined;\n};\n\nexport const defineChannel = <TChannel extends AuthoredChannelDefinitionIface>(\n definition: TChannel,\n) => {\n const {\n 'message.delta': delta,\n 'message.completed': completed,\n 'turn.started': started,\n 'turn.completed': ended,\n ...raw\n } = definition.events ?? {};\n const events = { ...raw };\n const wrap = <Data>(\n schema: z.ZodType<Data>,\n handler:\n | ((\n data: Data,\n channel: AuthoredChannelContextIface,\n ctx: AuthoredSessionContextIface,\n ) => void | Promise<void>)\n | undefined,\n ): ChannelEventHandler | undefined =>\n handler == null\n ? undefined\n : async (event, ctx) =>\n handler(\n schema.parse(event.data),\n { ...channelAccessors(ctx.platform), platform: ctx.platform },\n {\n sessionId: ctx.sessionId ?? null,\n turnId: ctx.turn.id,\n state: ctx.state,\n config: ctx.config,\n secrets: ctx.secrets,\n },\n );\n const semantic = {\n 'message.delta': wrap(z.object({ messageId: z.string(), delta: jsonObjectSchema }), delta),\n 'message.completed': wrap(channelMessageCompletedSchema, completed),\n 'turn.started': wrap(z.object({ turnId: z.string() }), started),\n 'turn.completed': wrap(\n z.object({ turnId: z.string(), stopReason: z.string().nullable() }),\n ended,\n ),\n };\n for (const [kind, handler] of Object.entries(semantic))\n if (handler != null) events[kind] = handler;\n const { installed, configure, ...authored } = definition;\n return stamp(\n { ...authored, configure: installed == null ? configure : undefined, events },\n AuthoredKind.Channel,\n );\n};\n\nexport const disableChannel = () => defineChannel({ disabled: true });\n\nconst route =\n (method: HttpChannelRouteDefinitionIface['method']) =>\n (path: string, handler: RouteHandler): HttpChannelRouteDefinitionIface => ({\n method,\n path,\n handler,\n });\n\nexport const GET = route('GET');\nexport const POST = route('POST');\nexport const PUT = route('PUT');\nexport const DELETE = route('DELETE');\n\nexport const WS = (\n path: string,\n handler: WebSocketChannelRouteDefinitionIface['handler'],\n): WebSocketChannelRouteDefinitionIface => ({ method: 'WS', path, handler });\n\n// Provider factories already own their installed reference and runtime handlers.\nexport const defineProviderChannel = <T extends ChannelDefinitionIface<JsonValue, JsonValue>>(\n definition: T,\n): T => stamp(definition, AuthoredKind.Channel);\n"],
|
|
5
5
|
"mappings": "AAiBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,SAAS,oBAAAA,yBAAwB;AACjC,YAAY,OAAO;AACnB,SAAS,cAAc,aAAa;AAoE7B,MAAM,gBAAgB,CAC3B,eACG;AACH,QAAM;AAAA,IACJ,iBAAiB;AAAA,IACjB,qBAAqB;AAAA,IACrB,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,GAAG;AAAA,EACL,IAAI,WAAW,UAAU,CAAC;AAC1B,QAAM,SAAS,EAAE,GAAG,IAAI;AACxB,QAAM,OAAO,CACX,QACA,YAQA,WAAW,OACP,SACA,OAAO,OAAO,QACZ;AAAA,IACE,OAAO,MAAM,MAAM,IAAI;AAAA,IACvB,EAAE,GAAG,iBAAiB,IAAI,QAAQ,GAAG,UAAU,IAAI,SAAS;AAAA,IAC5D;AAAA,MACE,WAAW,IAAI,aAAa;AAAA,MAC5B,QAAQ,IAAI,KAAK;AAAA,MACjB,OAAO,IAAI;AAAA,MACX,QAAQ,IAAI;AAAA,MACZ,SAAS,IAAI;AAAA,IACf;AAAA,EACF;AACR,QAAM,WAAW;AAAA,IACf,iBAAiB,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,iBAAiB,CAAC,GAAG,KAAK;AAAA,IACzF,qBAAqB,KAAK,+BAA+B,SAAS;AAAA,IAClE,gBAAgB,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO;AAAA,IAC9D,kBAAkB;AAAA,MAChB,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAAA,MAClE;AAAA,IACF;AAAA,EACF;AACA,aAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,QAAQ;AACnD,QAAI,WAAW,KAAM,QAAO,IAAI,IAAI;AACtC,QAAM,EAAE,WAAW,WAAW,GAAG,SAAS,IAAI;AAC9C,SAAO;AAAA,IACL,EAAE,GAAG,UAAU,WAAW,aAAa,OAAO,YAAY,QAAW,OAAO;AAAA,IAC5E,aAAa;AAAA,EACf;AACF;AAEO,MAAM,iBAAiB,MAAM,cAAc,EAAE,UAAU,KAAK,CAAC;AAEpE,MAAM,QACJ,CAAC,WACD,CAAC,MAAc,aAA4D;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AACF;AAEK,MAAM,MAAM,MAAM,KAAK;AACvB,MAAM,OAAO,MAAM,MAAM;AACzB,MAAM,MAAM,MAAM,KAAK;AACvB,MAAM,SAAS,MAAM,QAAQ;AAE7B,MAAM,KAAK,CAChB,MACA,aAC0C,EAAE,QAAQ,MAAM,MAAM,QAAQ;AAGnE,MAAM,wBAAwB,CACnC,eACM,MAAM,YAAY,aAAa,OAAO;",
|
|
6
6
|
"names": ["channelAccessors"]
|
|
7
7
|
}
|
|
@@ -15,8 +15,8 @@ export declare enum HookEvent {
|
|
|
15
15
|
ToolCallUpdate = "tool_call_update",
|
|
16
16
|
ToolCallContentChunk = "tool_call_content_chunk",
|
|
17
17
|
Plan = "plan",
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
DecisionCreated = "decision.created",
|
|
19
|
+
DecisionResolved = "decision.resolved",
|
|
20
20
|
StateUpdate = "state_update",
|
|
21
21
|
SessionFailed = "session.failed",
|
|
22
22
|
SessionClosed = "session.closed",
|
|
@@ -66,13 +66,13 @@ export interface HookEventDataMapIface {
|
|
|
66
66
|
tool_call: ToolCallEventDataIface;
|
|
67
67
|
tool_call_update: ToolCallEventDataIface;
|
|
68
68
|
tool_call_content_chunk: ToolCallEventDataIface;
|
|
69
|
-
'
|
|
70
|
-
|
|
69
|
+
'decision.created': {
|
|
70
|
+
decisionId: string;
|
|
71
71
|
kind: 'permission' | 'elicitation' | 'authorization';
|
|
72
72
|
request: JsonValue;
|
|
73
73
|
};
|
|
74
|
-
'
|
|
75
|
-
|
|
74
|
+
'decision.resolved': {
|
|
75
|
+
decisionId: string;
|
|
76
76
|
outcome: JsonValue;
|
|
77
77
|
};
|
|
78
78
|
'session.failed': {
|
|
@@ -14,8 +14,8 @@ var HookEvent = /* @__PURE__ */ ((HookEvent2) => {
|
|
|
14
14
|
HookEvent2["ToolCallUpdate"] = "tool_call_update";
|
|
15
15
|
HookEvent2["ToolCallContentChunk"] = "tool_call_content_chunk";
|
|
16
16
|
HookEvent2["Plan"] = "plan";
|
|
17
|
-
HookEvent2["
|
|
18
|
-
HookEvent2["
|
|
17
|
+
HookEvent2["DecisionCreated"] = "decision.created";
|
|
18
|
+
HookEvent2["DecisionResolved"] = "decision.resolved";
|
|
19
19
|
HookEvent2["StateUpdate"] = "state_update";
|
|
20
20
|
HookEvent2["SessionFailed"] = "session.failed";
|
|
21
21
|
HookEvent2["SessionClosed"] = "session.closed";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/authoring/hooks.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n HostedBindingsIface,\n JsonValue,\n NetworkSandboxSessionIface,\n} from '@finalai/agent-provider';\nimport * as z from 'zod';\nimport { authoredRecordSchema, isCallable, type AuthoredValue } from \"../runtime/values.mjs\";\nimport { AuthoredKind, stamp } from \"./brand.mjs\";\nimport type {\n AgentSessionInfoIface,\n FinalPlatformClientIface,\n SecretsIface,\n TranscriptMessageIface,\n} from \"./context.mjs\";\nimport type { ToolCallEventDataIface } from \"./tools.mjs\";\n\nexport { toolResultFrom } from \"./tools.mjs\";\n\n// Observe-only subscribers to the session's ACP log. Event\n// names are ACP update kinds and request methods plus a few session-service\n// lifecycle events. Only these canonical names are accepted.\n\nexport enum HookEvent {\n SessionOpened = 'session.opened',\n TurnStarted = 'turn.started',\n TurnEnded = 'turn.ended',\n UserMessageChunk = 'user_message_chunk',\n AgentMessageChunk = 'agent_message_chunk',\n AgentMessage = 'agent_message',\n AgentThoughtChunk = 'agent_thought_chunk',\n ToolCall = 'tool_call',\n ToolCallUpdate = 'tool_call_update',\n ToolCallContentChunk = 'tool_call_content_chunk',\n Plan = 'plan',\n
|
|
5
|
-
"mappings": "AAKA,YAAY,OAAO;AACnB,SAAS,sBAAsB,kBAAsC;AACrE,SAAS,cAAc,aAAa;AASpC,SAAS,sBAAsB;AAMxB,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,mBAAgB;AAChB,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,eAAY;AACZ,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,kBAAe;AACf,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,UAAO;AACP,EAAAA,WAAA,
|
|
4
|
+
"sourcesContent": ["import type {\n HostedBindingsIface,\n JsonValue,\n NetworkSandboxSessionIface,\n} from '@finalai/agent-provider';\nimport * as z from 'zod';\nimport { authoredRecordSchema, isCallable, type AuthoredValue } from \"../runtime/values.mjs\";\nimport { AuthoredKind, stamp } from \"./brand.mjs\";\nimport type {\n AgentSessionInfoIface,\n FinalPlatformClientIface,\n SecretsIface,\n TranscriptMessageIface,\n} from \"./context.mjs\";\nimport type { ToolCallEventDataIface } from \"./tools.mjs\";\n\nexport { toolResultFrom } from \"./tools.mjs\";\n\n// Observe-only subscribers to the session's ACP log. Event\n// names are ACP update kinds and request methods plus a few session-service\n// lifecycle events. Only these canonical names are accepted.\n\nexport enum HookEvent {\n SessionOpened = 'session.opened',\n TurnStarted = 'turn.started',\n TurnEnded = 'turn.ended',\n UserMessageChunk = 'user_message_chunk',\n AgentMessageChunk = 'agent_message_chunk',\n AgentMessage = 'agent_message',\n AgentThoughtChunk = 'agent_thought_chunk',\n ToolCall = 'tool_call',\n ToolCallUpdate = 'tool_call_update',\n ToolCallContentChunk = 'tool_call_content_chunk',\n Plan = 'plan',\n DecisionCreated = 'decision.created',\n DecisionResolved = 'decision.resolved',\n StateUpdate = 'state_update',\n SessionFailed = 'session.failed',\n SessionClosed = 'session.closed',\n CompactionUpdate = 'compaction_update',\n UsageUpdate = 'usage_update',\n AvailableCommandsUpdate = 'available_commands_update',\n CurrentModeUpdate = 'current_mode_update',\n ConfigOptionUpdate = 'config_option_update',\n SessionInfoUpdate = 'session_info_update',\n Notice = 'notice',\n}\n\nexport const HOOK_WILDCARD = '*';\n\nconst CANONICAL_EVENTS: ReadonlySet<string> = new Set(Object.values(HookEvent));\n\nexport enum HookEventKeyKind {\n Canonical = 'canonical',\n Wildcard = 'wildcard',\n Unknown = 'unknown',\n}\n\nexport interface NormalizedHookKeyIface {\n key: string;\n kind: HookEventKeyKind;\n // Canonical event names this key subscribes to ('*' for the wildcard).\n events: string[];\n}\n\nexport const normalizeHookKey = (key: string): NormalizedHookKeyIface => {\n if (key === HOOK_WILDCARD)\n return { key, kind: HookEventKeyKind.Wildcard, events: [HOOK_WILDCARD] };\n if (CANONICAL_EVENTS.has(key) || key.startsWith('_final/')) {\n return { key, kind: HookEventKeyKind.Canonical, events: [key] };\n }\n return { key, kind: HookEventKeyKind.Unknown, events: [] };\n};\n\nexport interface HookEventMetaIface {\n // '<sessionId>:<seq>' with the session's wire id (`ases_\u2026:12`): sortable\n // within a session and stable across redelivery.\n id: string;\n at: string;\n seq: number;\n}\n\nexport interface HookEventIface<TType extends string = string, TData = AuthoredValue> {\n type: TType;\n data: TData;\n meta: HookEventMetaIface;\n}\n\n// Lifecycle event data names platform objects by their wire ids, as the public\n// API does: sessions `ases_\u2026`, turns `atrn_\u2026`, participants `cpart_\u2026`,\n// decisions `adec_\u2026`. `promptMessageId` is the harness's ACP message id. ACP\n// update events (tool_call, agent_message_chunk, \u2026) carry the ACP payload as is.\nexport interface HookEventDataMapIface {\n 'session.opened': { sessionId: string };\n 'turn.started': {\n turnId: string;\n promptMessageId: string | null;\n authorParticipantId: string | null;\n };\n 'turn.ended': { turnId: string; stopReason: string | null };\n tool_call: ToolCallEventDataIface;\n tool_call_update: ToolCallEventDataIface;\n tool_call_content_chunk: ToolCallEventDataIface;\n 'decision.created': {\n decisionId: string;\n kind: 'permission' | 'elicitation' | 'authorization';\n request: JsonValue;\n };\n 'decision.resolved': { decisionId: string; outcome: JsonValue };\n 'session.failed': { reason: string | null };\n 'session.closed': { reason: string | null };\n}\n\ntype CanonicalData<TKey extends string> = TKey extends keyof HookEventDataMapIface\n ? HookEventDataMapIface[TKey]\n : Record<string, JsonValue>;\n\nexport type HookEventKey = `${HookEvent}` | typeof HOOK_WILDCARD | `_final/${string}`;\n\nexport type HookEventFor<TKey extends string> = TKey extends typeof HOOK_WILDCARD\n ? HookEventIface\n : HookEventIface<TKey, CanonicalData<TKey>>;\n\nexport interface HookSessionInfoIface extends AgentSessionInfoIface {\n readonly messages: readonly TranscriptMessageIface[];\n}\n\nexport interface HookContextIface {\n readonly session: HookSessionInfoIface;\n readonly agent: {\n readonly definitionId: string;\n readonly name: string;\n readonly revisionId: string;\n };\n readonly channel: { readonly kind: string | null };\n getSandbox(target?: string): Promise<NetworkSandboxSessionIface>;\n // Sends session/cancel for the running turn.\n cancel(): void;\n readonly secrets: SecretsIface;\n readonly bindings?: HostedBindingsIface;\n readonly final: FinalPlatformClientIface;\n}\n\nexport type HookHandler<TKey extends string> = (\n event: HookEventFor<TKey>,\n ctx: HookContextIface,\n) => void | Promise<void>;\n\nexport type HookHandlersIface = { readonly [TKey in HookEventKey]?: HookHandler<TKey> };\n\nexport interface HookDefinitionIface {\n readonly events?: HookHandlersIface;\n}\n\nexport const defineHook = (definition: HookDefinitionIface): HookDefinitionIface =>\n stamp({ ...definition }, AuthoredKind.Hook);\n\nexport interface HookDispatchEventIface {\n type: string;\n data: AuthoredValue;\n meta: HookEventMetaIface;\n}\n\nconst keyMatches = (key: string, event: HookDispatchEventIface): boolean =>\n key === event.type && (CANONICAL_EVENTS.has(key) || key.startsWith('_final/'));\n\nexport type HookInvocable = (event: HookDispatchEventIface, ctx: HookContextIface) => AuthoredValue;\n\nconst hookEventsSchema = z.looseObject({ events: authoredRecordSchema });\n\n// Handlers for one event: typed handlers in declaration order, then the\n// wildcard.\nexport const hookHandlersFor = (\n hook: AuthoredValue,\n event: HookDispatchEventIface,\n): HookInvocable[] => {\n const parsed = hookEventsSchema.safeParse(hook);\n if (!parsed.success) return [];\n const typed: HookInvocable[] = [];\n let wildcard: HookInvocable | null = null;\n for (const [key, handler] of Object.entries(parsed.data.events)) {\n if (!isCallable(handler)) continue;\n const invoke: HookInvocable = (dispatched, ctx) => handler(dispatched, ctx);\n if (key === HOOK_WILDCARD) wildcard = invoke;\n else if (keyMatches(key, event)) typed.push(invoke);\n }\n return wildcard == null ? typed : [...typed, wildcard];\n};\n"],
|
|
5
|
+
"mappings": "AAKA,YAAY,OAAO;AACnB,SAAS,sBAAsB,kBAAsC;AACrE,SAAS,cAAc,aAAa;AASpC,SAAS,sBAAsB;AAMxB,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,mBAAgB;AAChB,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,eAAY;AACZ,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,kBAAe;AACf,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,cAAW;AACX,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,UAAO;AACP,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,mBAAgB;AAChB,EAAAA,WAAA,mBAAgB;AAChB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,6BAA0B;AAC1B,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,wBAAqB;AACrB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,YAAS;AAvBC,SAAAA;AAAA,GAAA;AA0BL,MAAM,gBAAgB;AAE7B,MAAM,mBAAwC,IAAI,IAAI,OAAO,OAAO,SAAS,CAAC;AAEvE,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,eAAY;AACZ,EAAAA,kBAAA,cAAW;AACX,EAAAA,kBAAA,aAAU;AAHA,SAAAA;AAAA,GAAA;AAaL,MAAM,mBAAmB,CAAC,QAAwC;AACvE,MAAI,QAAQ;AACV,WAAO,EAAE,KAAK,MAAM,2BAA2B,QAAQ,CAAC,aAAa,EAAE;AACzE,MAAI,iBAAiB,IAAI,GAAG,KAAK,IAAI,WAAW,SAAS,GAAG;AAC1D,WAAO,EAAE,KAAK,MAAM,6BAA4B,QAAQ,CAAC,GAAG,EAAE;AAAA,EAChE;AACA,SAAO,EAAE,KAAK,MAAM,yBAA0B,QAAQ,CAAC,EAAE;AAC3D;AAkFO,MAAM,aAAa,CAAC,eACzB,MAAM,EAAE,GAAG,WAAW,GAAG,aAAa,IAAI;AAQ5C,MAAM,aAAa,CAAC,KAAa,UAC/B,QAAQ,MAAM,SAAS,iBAAiB,IAAI,GAAG,KAAK,IAAI,WAAW,SAAS;AAI9E,MAAM,mBAAmB,EAAE,YAAY,EAAE,QAAQ,qBAAqB,CAAC;AAIhE,MAAM,kBAAkB,CAC7B,MACA,UACoB;AACpB,QAAM,SAAS,iBAAiB,UAAU,IAAI;AAC9C,MAAI,CAAC,OAAO,QAAS,QAAO,CAAC;AAC7B,QAAM,QAAyB,CAAC;AAChC,MAAI,WAAiC;AACrC,aAAW,CAAC,KAAK,OAAO,KAAK,OAAO,QAAQ,OAAO,KAAK,MAAM,GAAG;AAC/D,QAAI,CAAC,WAAW,OAAO,EAAG;AAC1B,UAAM,SAAwB,CAAC,YAAY,QAAQ,QAAQ,YAAY,GAAG;AAC1E,QAAI,QAAQ,cAAe,YAAW;AAAA,aAC7B,WAAW,KAAK,KAAK,EAAG,OAAM,KAAK,MAAM;AAAA,EACpD;AACA,SAAO,YAAY,OAAO,QAAQ,CAAC,GAAG,OAAO,QAAQ;AACvD;",
|
|
6
6
|
"names": ["HookEvent", "HookEventKeyKind"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finalai/agent-definition",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provider-independent agent authoring, manifest schemas, directory compiler, and harness compatibility reports.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"registry": "https://registry.npmjs.org/"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@finalai/agent-protocol": "0.
|
|
79
|
-
"@finalai/agent-provider": "0.
|
|
78
|
+
"@finalai/agent-protocol": "0.5.0",
|
|
79
|
+
"@finalai/agent-provider": "0.5.0",
|
|
80
80
|
"ajv": "^8.20.0",
|
|
81
81
|
"ajv-formats": "^3.0.1",
|
|
82
82
|
"croner": "^10.0.1",
|