@finalai/agent-definition 0.1.5 → 0.1.8

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.
@@ -14,6 +14,19 @@ import {
14
14
  } from "./chunk-3K4C4SVG.ts";
15
15
 
16
16
  // ../agent-provider/src/channel.ts
17
+ var ChannelPrincipalType = /* @__PURE__ */ ((ChannelPrincipalType2) => {
18
+ ChannelPrincipalType2["User"] = "user";
19
+ ChannelPrincipalType2["Service"] = "service";
20
+ return ChannelPrincipalType2;
21
+ })(ChannelPrincipalType || {});
22
+ var channelAuthSchema = object({
23
+ principalId: string().min(1),
24
+ principalType: nativeEnum(ChannelPrincipalType),
25
+ authenticator: string().min(1),
26
+ // How the agent and the people reading its reply name the principal.
27
+ displayName: string().min(1).max(200).optional(),
28
+ attributes: jsonObjectSchema.default({})
29
+ });
17
30
  var ConversationKind = /* @__PURE__ */ ((ConversationKind2) => {
18
31
  ConversationKind2["Direct"] = "direct";
19
32
  ConversationKind2["Group"] = "group";
@@ -22,12 +35,10 @@ var ConversationKind = /* @__PURE__ */ ((ConversationKind2) => {
22
35
  var ParticipantKind = /* @__PURE__ */ ((ParticipantKind2) => {
23
36
  ParticipantKind2["User"] = "user";
24
37
  ParticipantKind2["Agent"] = "agent";
25
- ParticipantKind2["System"] = "system";
26
38
  return ParticipantKind2;
27
39
  })(ParticipantKind || {});
28
40
  var MessageKind = /* @__PURE__ */ ((MessageKind2) => {
29
41
  MessageKind2["Message"] = "message";
30
- MessageKind2["System"] = "system";
31
42
  MessageKind2["Card"] = "card";
32
43
  return MessageKind2;
33
44
  })(MessageKind || {});
@@ -60,7 +71,8 @@ var pendingCreatedDataSchema = object({
60
71
  });
61
72
  var pendingResolvedDataSchema = object({
62
73
  pendingRequestId: string().min(1),
63
- outcome: jsonValueSchema
74
+ outcome: jsonValueSchema,
75
+ respondedBy: channelAuthSchema.nullable().default(null)
64
76
  });
65
77
  var turnEndSchema = looseObject({
66
78
  sessionUpdate: literal("state_update"),
@@ -6,22 +6,18 @@ import {
6
6
  } from "./chunk-QJ26GEUM.ts";
7
7
  import {
8
8
  array,
9
- nativeEnum,
10
9
  object,
11
10
  string
12
11
  } from "./chunk-3K4C4SVG.ts";
13
12
 
14
13
  // ../agent-provider/src/channel-context.ts
15
- var ChannelPrincipalType = /* @__PURE__ */ ((ChannelPrincipalType2) => {
16
- ChannelPrincipalType2["User"] = "user";
17
- ChannelPrincipalType2["Service"] = "service";
18
- return ChannelPrincipalType2;
19
- })(ChannelPrincipalType || {});
20
- var channelAuthSchema = object({
21
- principalId: string().min(1),
22
- principalType: nativeEnum(ChannelPrincipalType),
23
- authenticator: string().min(1),
24
- attributes: jsonObjectSchema.default({})
14
+ var channelInputReceiptSchema = object({
15
+ inputId: string().min(1),
16
+ sessionId: string().min(1)
17
+ });
18
+ var channelHandoffReceiptSchema = object({
19
+ inputId: string().min(1).nullable(),
20
+ sessionId: string().min(1).nullable()
25
21
  });
26
22
  var channelAccessors = (platform) => {
27
23
  const operations = () => {
@@ -76,7 +72,9 @@ var defineChannel = (definition) => {
76
72
  {
77
73
  sessionId: ctx.sessionId ?? null,
78
74
  turnId: ctx.turn.id,
79
- state: ctx.state
75
+ state: ctx.state,
76
+ config: ctx.config,
77
+ secrets: ctx.secrets
80
78
  }
81
79
  );
82
80
  const semantic = {
@@ -110,6 +108,7 @@ var WS = (path, handler) => ({ method: "WS", path, handler });
110
108
  var defineProviderChannel = (definition) => stamp(definition, "channel" /* Channel */);
111
109
 
112
110
  export {
111
+ channelAccessors,
113
112
  defineChannel,
114
113
  disableChannel,
115
114
  GET,
@@ -7,7 +7,17 @@ import {
7
7
 
8
8
  // ../agent-provider/src/sandbox/types.ts
9
9
  var defineSandboxProvider = (definition) => ({
10
- definition,
10
+ // An implementation exists only once its options are given, so awaitRunning is
11
+ // checked as each environment is defined, before anything can start from it.
12
+ definition: {
13
+ ...definition,
14
+ environment: (options) => {
15
+ const implementation = definition.environment(options);
16
+ if (typeof implementation.awaitRunning !== "function")
17
+ throw new Error(`sandbox provider ${definition.name} does not implement awaitRunning`);
18
+ return implementation;
19
+ }
20
+ },
11
21
  name: definition.name,
12
22
  environment: (options) => ({
13
23
  providerName: definition.name,
@@ -28,7 +28,7 @@ import {
28
28
  import {
29
29
  ConversationKind,
30
30
  ParticipantKind
31
- } from "./chunk-IF6MR7JF.ts";
31
+ } from "./chunk-34O434BK.ts";
32
32
  import {
33
33
  mcpServerBindingSchema,
34
34
  providerRefSchema
@@ -4,11 +4,12 @@ import {
4
4
  POST,
5
5
  PUT,
6
6
  WS,
7
+ channelAccessors,
7
8
  defineChannel,
8
9
  defineProviderChannel,
9
10
  disableChannel
10
- } from "../../chunk-K7V4IMOB.ts";
11
- import "../../chunk-IF6MR7JF.ts";
11
+ } from "../../chunk-KGIUNNCX.ts";
12
+ import "../../chunk-34O434BK.ts";
12
13
  import "../../chunk-4X2DS5BR.ts";
13
14
  import "../../chunk-QJ26GEUM.ts";
14
15
  import "../../chunk-TM36NO3C.ts";
@@ -20,6 +21,7 @@ export {
20
21
  POST,
21
22
  PUT,
22
23
  WS,
24
+ channelAccessors,
23
25
  defineChannel,
24
26
  defineProviderChannel,
25
27
  disableChannel
@@ -15,7 +15,7 @@ import {
15
15
  defineSandbox,
16
16
  defineSandboxProvider,
17
17
  harnessHost
18
- } from "../../chunk-B5RJDCXZ.ts";
18
+ } from "../../chunk-OEXIS2VK.ts";
19
19
  import "../../chunk-4E5HECVD.ts";
20
20
  import {
21
21
  SandboxWire
@@ -47,8 +47,8 @@ import {
47
47
  defineChannel,
48
48
  defineProviderChannel,
49
49
  disableChannel
50
- } from "../../chunk-K7V4IMOB.ts";
51
- import "../../chunk-IF6MR7JF.ts";
50
+ } from "../../chunk-KGIUNNCX.ts";
51
+ import "../../chunk-34O434BK.ts";
52
52
  import {
53
53
  defineHostedConnection,
54
54
  defineMcpClientConnection
@@ -3,7 +3,7 @@ import {
3
3
  defineSandbox,
4
4
  defineSandboxProvider,
5
5
  harnessHost
6
- } from "../../chunk-B5RJDCXZ.ts";
6
+ } from "../../chunk-OEXIS2VK.ts";
7
7
  import "../../chunk-4E5HECVD.ts";
8
8
  import {
9
9
  SandboxWire
@@ -28,7 +28,7 @@ import {
28
28
  defineSandbox,
29
29
  defineSandboxProvider,
30
30
  harnessHost
31
- } from "../chunk-B5RJDCXZ.ts";
31
+ } from "../chunk-OEXIS2VK.ts";
32
32
  import "../chunk-4E5HECVD.ts";
33
33
  import {
34
34
  SandboxWire
@@ -60,8 +60,8 @@ import {
60
60
  defineChannel,
61
61
  defineProviderChannel,
62
62
  disableChannel
63
- } from "../chunk-K7V4IMOB.ts";
64
- import "../chunk-IF6MR7JF.ts";
63
+ } from "../chunk-KGIUNNCX.ts";
64
+ import "../chunk-34O434BK.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-YWFGIPHD.ts";
4
+ } from "../../chunk-Z2UDHIJK.ts";
5
5
  import {
6
6
  describeBundle,
7
7
  needsCombinedMcpServers,
@@ -18,7 +18,7 @@ import {
18
18
  registerToolName
19
19
  } from "../../chunk-2ZRYQO4Q.ts";
20
20
  import "../../chunk-4A66SVBJ.ts";
21
- import "../../chunk-IF6MR7JF.ts";
21
+ import "../../chunk-34O434BK.ts";
22
22
  import "../../chunk-CIWWFQHL.ts";
23
23
  import "../../chunk-APU2VKLW.ts";
24
24
  import "../../chunk-RWUIMTBI.ts";
@@ -2,14 +2,14 @@ import {
2
2
  combineMcpServers,
3
3
  createIsolateRuntime,
4
4
  lowerResolvedValue
5
- } from "../../chunk-YWFGIPHD.ts";
5
+ } from "../../chunk-Z2UDHIJK.ts";
6
6
  import "../../chunk-5NTKRRMC.ts";
7
7
  import "../../chunk-NMYHO2QN.ts";
8
8
  import "../../chunk-TJZS457N.ts";
9
9
  import "../../chunk-4E5HECVD.ts";
10
10
  import "../../chunk-2ZRYQO4Q.ts";
11
11
  import "../../chunk-4A66SVBJ.ts";
12
- import "../../chunk-IF6MR7JF.ts";
12
+ import "../../chunk-34O434BK.ts";
13
13
  import "../../chunk-CIWWFQHL.ts";
14
14
  import "../../chunk-APU2VKLW.ts";
15
15
  import "../../chunk-RWUIMTBI.ts";
@@ -1,9 +1,10 @@
1
- import type { AcpUpdateKind, ChannelAddressContextIface, ChannelDefinitionIface, ChannelEventHandler, ChannelReceiveContextIface, ChannelReceiveResult, ChannelSemanticDataByKindIface, HttpChannelRouteDefinitionIface, JsonObject, JsonValue, PendingEventKind, ProjectionContextIface, TurnPolicy, WebSocketChannelRouteDefinitionIface } from '@finalai/agent-provider';
1
+ import type { AcpUpdateKind, KnownAcpUpdateKind, ChannelAddressContextIface, ChannelDefinitionIface, ChannelEventHandler, ChannelReceiveContextIface, ChannelReceiveResult, ChannelSemanticDataByKindIface, HttpChannelRouteDefinitionIface, JsonObject, JsonValue, PendingEventKind, ProjectionContextIface, TurnPolicy, WebSocketChannelRouteDefinitionIface } from '@finalai/agent-provider';
2
+ export { channelAccessors } from '@finalai/agent-provider';
2
3
  export type RouteHandler = HttpChannelRouteDefinitionIface['handler'];
3
4
  export type RouteHandlerArgsIface = Parameters<RouteHandler>[0];
4
5
  export type AuthoredChannelDefinitionIface = Partial<Omit<ChannelDefinitionIface<JsonValue, JsonValue>, 'turnPolicy' | 'events' | 'receive'>> & {
5
6
  receive?: (input: JsonValue, ctx: ChannelReceiveContextIface & ChannelAddressContextIface) => Promise<ChannelReceiveResult>;
6
- events?: Partial<Record<AcpUpdateKind | `${PendingEventKind}`, ChannelEventHandler>> & AuthoredSemanticEventsIface;
7
+ events?: AuthoredChannelEventsIface;
7
8
  readonly turnPolicy?: TurnPolicy | `${TurnPolicy}`;
8
9
  readonly config?: JsonObject;
9
10
  readonly disabled?: boolean;
@@ -15,14 +16,47 @@ export interface AuthoredSessionContextIface {
15
16
  sessionId: string | null;
16
17
  turnId: string;
17
18
  state: ProjectionContextIface['state'];
19
+ config: JsonObject;
20
+ secrets: ProjectionContextIface['secrets'];
18
21
  }
19
22
  export type AuthoredSemanticEventsIface = {
20
23
  [Kind in keyof ChannelSemanticDataByKindIface]?: (data: ChannelSemanticDataByKindIface[Kind], channel: AuthoredChannelContextIface, ctx: AuthoredSessionContextIface) => void | Promise<void>;
21
24
  };
25
+ type AuthoredSemanticHandlerIface = NonNullable<AuthoredSemanticEventsIface[keyof AuthoredSemanticEventsIface]>;
26
+ export type AuthoredChannelEventsIface = AuthoredSemanticEventsIface & {
27
+ [Kind in `${PendingEventKind}` | KnownAcpUpdateKind]?: ChannelEventHandler;
28
+ } & {
29
+ [kind: AcpUpdateKind]: ChannelEventHandler | AuthoredSemanticHandlerIface | undefined;
30
+ };
22
31
  export declare const defineChannel: <TChannel extends AuthoredChannelDefinitionIface>(definition: TChannel) => Omit<TChannel, "installed" | "configure"> & {
23
32
  configure: ((config: JsonObject) => ChannelDefinitionIface<JsonValue, JsonValue>) | undefined;
24
33
  events: {
25
- [x: string]: ChannelEventHandler | undefined;
34
+ [kind: string]: AuthoredSemanticHandlerIface | ChannelEventHandler | undefined;
35
+ usage_update?: ChannelEventHandler | undefined;
36
+ user_message_chunk?: ChannelEventHandler | undefined;
37
+ user_message?: ChannelEventHandler | undefined;
38
+ agent_message_chunk?: ChannelEventHandler | undefined;
39
+ agent_message?: ChannelEventHandler | undefined;
40
+ agent_thought_chunk?: ChannelEventHandler | undefined;
41
+ agent_thought?: ChannelEventHandler | undefined;
42
+ state_update?: ChannelEventHandler | undefined;
43
+ tool_call_content_chunk?: ChannelEventHandler | undefined;
44
+ tool_call_update?: ChannelEventHandler | undefined;
45
+ terminal_update?: ChannelEventHandler | undefined;
46
+ terminal_output_chunk?: ChannelEventHandler | undefined;
47
+ plan_update?: ChannelEventHandler | undefined;
48
+ plan_removed?: ChannelEventHandler | undefined;
49
+ available_commands_update?: ChannelEventHandler | undefined;
50
+ config_option_update?: ChannelEventHandler | undefined;
51
+ session_info_update?: ChannelEventHandler | undefined;
52
+ notice?: ChannelEventHandler | undefined;
53
+ compaction_update?: ChannelEventHandler | undefined;
54
+ compaction_summary_chunk?: ChannelEventHandler | undefined;
55
+ subagent_update?: ChannelEventHandler | undefined;
56
+ session_message?: ChannelEventHandler | undefined;
57
+ session_message_chunk?: ChannelEventHandler | undefined;
58
+ "pending.created"?: ChannelEventHandler | undefined;
59
+ "pending.resolved"?: ChannelEventHandler | undefined;
26
60
  };
27
61
  };
28
62
  export declare const disableChannel: () => Omit<{
@@ -30,7 +64,32 @@ export declare const disableChannel: () => Omit<{
30
64
  }, "installed" | "configure"> & {
31
65
  configure: ((config: JsonObject) => ChannelDefinitionIface<JsonValue, JsonValue>) | undefined;
32
66
  events: {
33
- [x: string]: ChannelEventHandler | undefined;
67
+ [kind: string]: AuthoredSemanticHandlerIface | ChannelEventHandler | undefined;
68
+ usage_update?: ChannelEventHandler | undefined;
69
+ user_message_chunk?: ChannelEventHandler | undefined;
70
+ user_message?: ChannelEventHandler | undefined;
71
+ agent_message_chunk?: ChannelEventHandler | undefined;
72
+ agent_message?: ChannelEventHandler | undefined;
73
+ agent_thought_chunk?: ChannelEventHandler | undefined;
74
+ agent_thought?: ChannelEventHandler | undefined;
75
+ state_update?: ChannelEventHandler | undefined;
76
+ tool_call_content_chunk?: ChannelEventHandler | undefined;
77
+ tool_call_update?: ChannelEventHandler | undefined;
78
+ terminal_update?: ChannelEventHandler | undefined;
79
+ terminal_output_chunk?: ChannelEventHandler | undefined;
80
+ plan_update?: ChannelEventHandler | undefined;
81
+ plan_removed?: ChannelEventHandler | undefined;
82
+ available_commands_update?: ChannelEventHandler | undefined;
83
+ config_option_update?: ChannelEventHandler | undefined;
84
+ session_info_update?: ChannelEventHandler | undefined;
85
+ notice?: ChannelEventHandler | undefined;
86
+ compaction_update?: ChannelEventHandler | undefined;
87
+ compaction_summary_chunk?: ChannelEventHandler | undefined;
88
+ subagent_update?: ChannelEventHandler | undefined;
89
+ session_message?: ChannelEventHandler | undefined;
90
+ session_message_chunk?: ChannelEventHandler | undefined;
91
+ "pending.created"?: ChannelEventHandler | undefined;
92
+ "pending.resolved"?: ChannelEventHandler | undefined;
34
93
  };
35
94
  };
36
95
  export declare const GET: (path: string, handler: RouteHandler) => HttpChannelRouteDefinitionIface;
@@ -3,6 +3,7 @@ import {
3
3
  channelMessageCompletedSchema,
4
4
  jsonObjectSchema
5
5
  } from "@finalai/agent-provider";
6
+ import { channelAccessors as channelAccessors2 } from "@finalai/agent-provider";
6
7
  import * as z from "zod";
7
8
  import { AuthoredKind, stamp } from "./brand.mjs";
8
9
  const defineChannel = (definition) => {
@@ -20,7 +21,9 @@ const defineChannel = (definition) => {
20
21
  {
21
22
  sessionId: ctx.sessionId ?? null,
22
23
  turnId: ctx.turn.id,
23
- state: ctx.state
24
+ state: ctx.state,
25
+ config: ctx.config,
26
+ secrets: ctx.secrets
24
27
  }
25
28
  );
26
29
  const semantic = {
@@ -58,6 +61,7 @@ export {
58
61
  POST,
59
62
  PUT,
60
63
  WS,
64
+ channelAccessors2 as channelAccessors,
61
65
  defineChannel,
62
66
  defineProviderChannel,
63
67
  disableChannel
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/authoring/channels.ts"],
4
- "sourcesContent": ["import type {\n AcpUpdateKind,\n ChannelAddressContextIface,\n ChannelDefinitionIface,\n ChannelEventHandler,\n ChannelReceiveContextIface,\n ChannelReceiveResult,\n ChannelSemanticDataByKindIface,\n HttpChannelRouteDefinitionIface,\n JsonObject,\n JsonValue,\n PendingEventKind,\n ProjectionContextIface,\n TurnPolicy,\n WebSocketChannelRouteDefinitionIface,\n} from '@finalai/agent-provider';\nimport {\n channelAccessors,\n channelMessageCompletedSchema,\n jsonObjectSchema,\n} 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`, pending requests `apnd_\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?: Partial<Record<AcpUpdateKind | `${PendingEventKind}`, ChannelEventHandler>> &\n AuthoredSemanticEventsIface;\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}\nexport type AuthoredSemanticEventsIface = {\n [Kind in keyof ChannelSemanticDataByKindIface]?: (\n data: ChannelSemanticDataByKindIface[Kind],\n channel: AuthoredChannelContextIface,\n ctx: AuthoredSessionContextIface,\n ) => void | Promise<void>;\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 },\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
- "mappings": "AAgBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,YAAY,OAAO;AACnB,SAAS,cAAc,aAAa;AAkD7B,MAAM,gB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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
- "names": []
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 PendingEventKind,\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 (`pending.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`, pending requests `apnd_\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)`; pending\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 `${PendingEventKind}` | 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"],
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AI;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
+ "names": ["channelAccessors"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finalai/agent-definition",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
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.1.4",
79
- "@finalai/agent-provider": "0.1.6",
78
+ "@finalai/agent-protocol": "0.2.1",
79
+ "@finalai/agent-provider": "0.2.1",
80
80
  "ajv": "^8.20.0",
81
81
  "ajv-formats": "^3.0.1",
82
82
  "croner": "^10.0.1",