@finalai/agent-provider 0.1.7 → 0.2.2

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.
@@ -1,41 +1,49 @@
1
1
  import type { ContentBlock } from '@agentclientprotocol/sdk/experimental/v2';
2
2
  import * as z from 'zod';
3
- import { TurnPolicy, type ChannelPlatformIface } from "./channel.mjs";
3
+ import { type ChannelAuthIface, type ChannelPlatformIface, type TurnPolicy } from "./channel.mjs";
4
4
  import type { JsonObject, JsonValue } from "./json.mjs";
5
- export declare enum ChannelPrincipalType {
6
- User = "user",
7
- Service = "service"
5
+ export { ChannelPrincipalType, channelAuthSchema, type ChannelAuthIface } from "./channel.mjs";
6
+ export interface ChannelInputSourceIface {
7
+ label: string;
8
8
  }
9
- export interface ChannelAuthIface extends JsonObject {
10
- principalId: string;
11
- principalType: ChannelPrincipalType | `${ChannelPrincipalType}`;
12
- authenticator: string;
13
- attributes: JsonObject;
14
- }
15
- export declare const channelAuthSchema: z.ZodObject<{
16
- principalId: z.ZodString;
17
- principalType: z.ZodEnum<typeof ChannelPrincipalType>;
18
- authenticator: z.ZodString;
19
- attributes: z.ZodDefault<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
20
- }, z.core.$strip>;
21
- export declare const channelPrincipalMatches: (first: JsonObject | null, second: JsonObject | null) => boolean;
22
9
  export interface ChannelSendInputIface {
23
10
  content: ContentBlock[];
24
11
  idempotencyKey: string;
25
- auth: JsonObject | null;
12
+ auth: ChannelAuthIface;
26
13
  context?: string[];
27
14
  title?: string;
28
15
  turnPolicy?: TurnPolicy | `${TurnPolicy}`;
16
+ actingUserId?: string;
17
+ originTurnId?: string;
18
+ source?: ChannelInputSourceIface;
29
19
  }
30
20
  export interface ChannelResponseInputIface {
31
21
  pendingId: string;
32
22
  outcome: JsonValue;
33
- auth: JsonObject | null;
23
+ auth: ChannelAuthIface;
34
24
  }
35
25
  export interface ChannelSessionTargetIface {
36
26
  address?: string;
37
27
  sessionId?: string;
28
+ conversationId?: string;
29
+ participantId?: string;
30
+ }
31
+ export interface ChannelInputReceiptIface {
32
+ inputId: string;
33
+ sessionId: string;
38
34
  }
35
+ export declare const channelInputReceiptSchema: z.ZodObject<{
36
+ inputId: z.ZodString;
37
+ sessionId: z.ZodString;
38
+ }, z.core.$strip>;
39
+ export interface ChannelHandoffReceiptIface {
40
+ inputId: string | null;
41
+ sessionId: string | null;
42
+ }
43
+ export declare const channelHandoffReceiptSchema: z.ZodObject<{
44
+ inputId: z.ZodNullable<z.ZodString>;
45
+ sessionId: z.ZodNullable<z.ZodString>;
46
+ }, z.core.$strip>;
39
47
  export interface ChannelSessionSnapshotIface {
40
48
  sessionId: string;
41
49
  conversationId: string | null;
@@ -47,11 +55,7 @@ export interface ChannelCancelInputIface {
47
55
  export interface ChannelSessionOperationsIface {
48
56
  inspect(target: ChannelSessionTargetIface): Promise<ChannelSessionSnapshotIface | null>;
49
57
  resolve(target: ChannelSessionTargetIface): Promise<string | null>;
50
- send(target: ChannelSessionTargetIface, input: ChannelSendInputIface): Promise<{
51
- sessionId: string;
52
- turnId: string;
53
- messageId: string;
54
- }>;
58
+ send(target: ChannelSessionTargetIface, input: ChannelSendInputIface): Promise<ChannelInputReceiptIface>;
55
59
  respond(target: ChannelSessionTargetIface, input: ChannelResponseInputIface): Promise<{
56
60
  resolved: boolean;
57
61
  }>;
@@ -70,7 +74,7 @@ export interface ChannelSessionOperationsIface {
70
74
  park(target: ChannelSessionTargetIface): Promise<void>;
71
75
  getState(target: ChannelSessionTargetIface): Promise<JsonObject>;
72
76
  setState(target: ChannelSessionTargetIface, state: JsonObject): Promise<void>;
73
- handoff(channel: string, target: JsonValue, input: ChannelSendInputIface): Promise<void>;
77
+ handoff(channel: string, target: JsonValue, input: ChannelSendInputIface): Promise<ChannelHandoffReceiptIface>;
74
78
  }
75
79
  export interface ChannelSessionHandleIface {
76
80
  inspect(): Promise<ChannelSessionSnapshotIface | null>;
@@ -96,7 +100,7 @@ export interface ChannelAddressContextIface {
96
100
  resolveSession(address: string): Promise<string | null>;
97
101
  attachSession(id: string): ChannelSessionHandleIface;
98
102
  to(channel: string, target: JsonValue): {
99
- send(input: ChannelSendInputIface): Promise<void>;
103
+ send(input: ChannelSendInputIface): Promise<ChannelHandoffReceiptIface>;
100
104
  };
101
105
  }
102
106
  export declare const channelAccessors: (platform: Pick<ChannelPlatformIface, "channelSessions">) => ChannelAddressContextIface;
@@ -1,22 +1,14 @@
1
1
  import * as z from "zod";
2
- import { TurnPolicy } from "./channel.mjs";
3
- import { jsonObjectSchema } from "./json.mjs";
4
- var ChannelPrincipalType = /* @__PURE__ */ ((ChannelPrincipalType2) => {
5
- ChannelPrincipalType2["User"] = "user";
6
- ChannelPrincipalType2["Service"] = "service";
7
- return ChannelPrincipalType2;
8
- })(ChannelPrincipalType || {});
9
- const channelAuthSchema = z.object({
10
- principalId: z.string().min(1),
11
- principalType: z.nativeEnum(ChannelPrincipalType),
12
- authenticator: z.string().min(1),
13
- attributes: jsonObjectSchema.default({})
2
+ import {} from "./channel.mjs";
3
+ import { ChannelPrincipalType, channelAuthSchema } from "./channel.mjs";
4
+ const channelInputReceiptSchema = z.object({
5
+ inputId: z.string().min(1),
6
+ sessionId: z.string().min(1)
7
+ });
8
+ const channelHandoffReceiptSchema = z.object({
9
+ inputId: z.string().min(1).nullable(),
10
+ sessionId: z.string().min(1).nullable()
14
11
  });
15
- const channelPrincipalMatches = (first, second) => {
16
- if (first == null || second == null) return first == null && second == null;
17
- const a = channelAuthSchema.parse(first), b = channelAuthSchema.parse(second);
18
- return a.principalId === b.principalId && a.principalType === b.principalType && a.authenticator === b.authenticator;
19
- };
20
12
  const channelAccessors = (platform) => {
21
13
  const operations = () => {
22
14
  if (platform.channelSessions == null)
@@ -47,6 +39,7 @@ export {
47
39
  ChannelPrincipalType,
48
40
  channelAccessors,
49
41
  channelAuthSchema,
50
- channelPrincipalMatches
42
+ channelHandoffReceiptSchema,
43
+ channelInputReceiptSchema
51
44
  };
52
45
  //# sourceMappingURL=channel-context.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/channel-context.ts"],
4
- "sourcesContent": ["import type { ContentBlock } from '@agentclientprotocol/sdk/experimental/v2';\nimport * as z from 'zod';\nimport { TurnPolicy, type ChannelPlatformIface } from \"./channel.mjs\";\nimport type { JsonObject, JsonValue } from \"./json.mjs\";\nimport { jsonObjectSchema } from \"./json.mjs\";\n\nexport enum ChannelPrincipalType {\n User = 'user',\n Service = 'service',\n}\nexport interface ChannelAuthIface extends JsonObject {\n principalId: string;\n principalType: ChannelPrincipalType | `${ChannelPrincipalType}`;\n authenticator: string;\n attributes: JsonObject;\n}\nexport const channelAuthSchema = z.object({\n principalId: z.string().min(1),\n principalType: z.nativeEnum(ChannelPrincipalType),\n authenticator: z.string().min(1),\n attributes: jsonObjectSchema.default({}),\n});\nexport const channelPrincipalMatches = (\n first: JsonObject | null,\n second: JsonObject | null,\n): boolean => {\n if (first == null || second == null) return first == null && second == null;\n const a = channelAuthSchema.parse(first),\n b = channelAuthSchema.parse(second);\n return (\n a.principalId === b.principalId &&\n a.principalType === b.principalType &&\n a.authenticator === b.authenticator\n );\n};\n\nexport interface ChannelSendInputIface {\n content: ContentBlock[];\n idempotencyKey: string;\n auth: JsonObject | null;\n context?: string[];\n title?: string;\n turnPolicy?: TurnPolicy | `${TurnPolicy}`;\n}\n\nexport interface ChannelResponseInputIface {\n pendingId: string;\n outcome: JsonValue;\n auth: JsonObject | null;\n}\n\nexport interface ChannelSessionTargetIface {\n address?: string;\n sessionId?: string;\n}\n\nexport interface ChannelSessionSnapshotIface {\n sessionId: string;\n conversationId: string | null;\n}\n\nexport interface ChannelCancelInputIface {\n reason?: string;\n throughMessageSeq?: number;\n}\n\nexport interface ChannelSessionOperationsIface {\n inspect(target: ChannelSessionTargetIface): Promise<ChannelSessionSnapshotIface | null>;\n resolve(target: ChannelSessionTargetIface): Promise<string | null>;\n send(\n target: ChannelSessionTargetIface,\n input: ChannelSendInputIface,\n ): Promise<{ sessionId: string; turnId: string; messageId: string }>;\n respond(\n target: ChannelSessionTargetIface,\n input: ChannelResponseInputIface,\n ): Promise<{ resolved: boolean }>;\n cancel(\n target: ChannelSessionTargetIface,\n input?: ChannelCancelInputIface,\n ): Promise<{ accepted: boolean }>;\n close(target: ChannelSessionTargetIface): Promise<void>;\n observe(\n target: ChannelSessionTargetIface,\n input: { content: ContentBlock[]; idempotencyKey: string },\n ): Promise<void>;\n setConfigOption(\n target: ChannelSessionTargetIface,\n input: { configId: string; value: JsonValue },\n ): Promise<void>;\n park(target: ChannelSessionTargetIface): Promise<void>;\n getState(target: ChannelSessionTargetIface): Promise<JsonObject>;\n setState(target: ChannelSessionTargetIface, state: JsonObject): Promise<void>;\n handoff(channel: string, target: JsonValue, input: ChannelSendInputIface): Promise<void>;\n}\n\nexport interface ChannelSessionHandleIface {\n inspect(): Promise<ChannelSessionSnapshotIface | null>;\n resolveSession(): Promise<string | null>;\n send(input: ChannelSendInputIface): ReturnType<ChannelSessionOperationsIface['send']>;\n respond(input: ChannelResponseInputIface): ReturnType<ChannelSessionOperationsIface['respond']>;\n cancel(input?: ChannelCancelInputIface): ReturnType<ChannelSessionOperationsIface['cancel']>;\n close(): Promise<void>;\n observe(input: { content: ContentBlock[]; idempotencyKey: string }): Promise<void>;\n setConfigOption(input: { configId: string; value: JsonValue }): Promise<void>;\n park(): Promise<void>;\n getState(): Promise<JsonObject>;\n setState(state: JsonObject): Promise<void>;\n}\n\nexport interface ChannelAddressContextIface {\n from(address: string): ChannelSessionHandleIface;\n resolveSession(address: string): Promise<string | null>;\n attachSession(id: string): ChannelSessionHandleIface;\n to(channel: string, target: JsonValue): { send(input: ChannelSendInputIface): Promise<void> };\n}\n\n// Handles resolve at operation time. Only attachSession captures a session ID.\nexport const channelAccessors = (\n platform: Pick<ChannelPlatformIface, 'channelSessions'>,\n): ChannelAddressContextIface => {\n const operations = () => {\n if (platform.channelSessions == null)\n throw new Error('channel session operations are unavailable');\n return platform.channelSessions;\n };\n const handle = (target: ChannelSessionTargetIface): ChannelSessionHandleIface => ({\n inspect: () => operations().inspect(target),\n resolveSession: () => operations().resolve(target),\n send: (input) => operations().send(target, input),\n respond: (input) => operations().respond(target, input),\n cancel: (input) => operations().cancel(target, input),\n close: () => operations().close(target),\n observe: (input) => operations().observe(target, input),\n setConfigOption: (input) => operations().setConfigOption(target, input),\n park: () => operations().park(target),\n getState: () => operations().getState(target),\n setState: (state) => operations().setState(target, state),\n });\n return {\n from: (address) => handle({ address }),\n resolveSession: (address) => operations().resolve({ address }),\n attachSession: (sessionId) => handle({ sessionId }),\n to: (channel, target) => ({ send: (input) => operations().handoff(channel, target, input) }),\n };\n};\n"],
5
- "mappings": "AACA,YAAY,OAAO;AACnB,SAAS,kBAA6C;AAEtD,SAAS,wBAAwB;AAE1B,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;AAUL,MAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC7B,eAAe,EAAE,WAAW,oBAAoB;AAAA,EAChD,eAAe,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC/B,YAAY,iBAAiB,QAAQ,CAAC,CAAC;AACzC,CAAC;AACM,MAAM,0BAA0B,CACrC,OACA,WACY;AACZ,MAAI,SAAS,QAAQ,UAAU,KAAM,QAAO,SAAS,QAAQ,UAAU;AACvE,QAAM,IAAI,kBAAkB,MAAM,KAAK,GACrC,IAAI,kBAAkB,MAAM,MAAM;AACpC,SACE,EAAE,gBAAgB,EAAE,eACpB,EAAE,kBAAkB,EAAE,iBACtB,EAAE,kBAAkB,EAAE;AAE1B;AAoFO,MAAM,mBAAmB,CAC9B,aAC+B;AAC/B,QAAM,aAAa,MAAM;AACvB,QAAI,SAAS,mBAAmB;AAC9B,YAAM,IAAI,MAAM,4CAA4C;AAC9D,WAAO,SAAS;AAAA,EAClB;AACA,QAAM,SAAS,CAAC,YAAkE;AAAA,IAChF,SAAS,MAAM,WAAW,EAAE,QAAQ,MAAM;AAAA,IAC1C,gBAAgB,MAAM,WAAW,EAAE,QAAQ,MAAM;AAAA,IACjD,MAAM,CAAC,UAAU,WAAW,EAAE,KAAK,QAAQ,KAAK;AAAA,IAChD,SAAS,CAAC,UAAU,WAAW,EAAE,QAAQ,QAAQ,KAAK;AAAA,IACtD,QAAQ,CAAC,UAAU,WAAW,EAAE,OAAO,QAAQ,KAAK;AAAA,IACpD,OAAO,MAAM,WAAW,EAAE,MAAM,MAAM;AAAA,IACtC,SAAS,CAAC,UAAU,WAAW,EAAE,QAAQ,QAAQ,KAAK;AAAA,IACtD,iBAAiB,CAAC,UAAU,WAAW,EAAE,gBAAgB,QAAQ,KAAK;AAAA,IACtE,MAAM,MAAM,WAAW,EAAE,KAAK,MAAM;AAAA,IACpC,UAAU,MAAM,WAAW,EAAE,SAAS,MAAM;AAAA,IAC5C,UAAU,CAAC,UAAU,WAAW,EAAE,SAAS,QAAQ,KAAK;AAAA,EAC1D;AACA,SAAO;AAAA,IACL,MAAM,CAAC,YAAY,OAAO,EAAE,QAAQ,CAAC;AAAA,IACrC,gBAAgB,CAAC,YAAY,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAAA,IAC7D,eAAe,CAAC,cAAc,OAAO,EAAE,UAAU,CAAC;AAAA,IAClD,IAAI,CAAC,SAAS,YAAY,EAAE,MAAM,CAAC,UAAU,WAAW,EAAE,QAAQ,SAAS,QAAQ,KAAK,EAAE;AAAA,EAC5F;AACF;",
6
- "names": ["ChannelPrincipalType"]
4
+ "sourcesContent": ["import type { ContentBlock } from '@agentclientprotocol/sdk/experimental/v2';\nimport * as z from 'zod';\nimport { type ChannelAuthIface, type ChannelPlatformIface, type TurnPolicy } from \"./channel.mjs\";\nimport type { JsonObject, JsonValue } from \"./json.mjs\";\n\nexport { ChannelPrincipalType, channelAuthSchema, type ChannelAuthIface } from \"./channel.mjs\";\n\n// How a Final room captions the agent's reply to the input (\"After the 9:00\n// schedule\", \"From Dana in #support\"); the platform names the principal when absent.\nexport interface ChannelInputSourceIface {\n label: string;\n}\n\nexport interface ChannelSendInputIface {\n content: ContentBlock[];\n idempotencyKey: string;\n // Required: the platform records the principal of every input.\n auth: ChannelAuthIface;\n context?: string[];\n title?: string;\n turnPolicy?: TurnPolicy | `${TurnPolicy}`;\n // The person the input acts for when its principal is a service: who pays and answers.\n actingUserId?: string;\n // The turn whose work produced the input (a relay or handoff), for loop limits.\n originTurnId?: string;\n source?: ChannelInputSourceIface;\n}\n\nexport interface ChannelResponseInputIface {\n pendingId: string;\n outcome: JsonValue;\n // Who answered; the channel decides who may (its audience policy) before responding.\n auth: ChannelAuthIface;\n}\n\n// Exactly one of an address (the channel's own), an attached session, or a\n// Final room (`conversationId`, optionally one agent `participantId` in it).\nexport interface ChannelSessionTargetIface {\n address?: string;\n sessionId?: string;\n conversationId?: string;\n participantId?: string;\n}\n\n// `send` accepts the input before any agent runs: the prompt follows, retried\n// by the platform, and the reply arrives through the channel's events.\nexport interface ChannelInputReceiptIface {\n inputId: string;\n sessionId: string;\n}\n\nexport const channelInputReceiptSchema = z.object({\n inputId: z.string().min(1),\n sessionId: z.string().min(1),\n});\n\n// Where a handoff went: a Final room's input, or another channel's own receive\n// (which names a session or nothing).\nexport interface ChannelHandoffReceiptIface {\n inputId: string | null;\n sessionId: string | null;\n}\n\nexport const channelHandoffReceiptSchema = z.object({\n inputId: z.string().min(1).nullable(),\n sessionId: z.string().min(1).nullable(),\n});\n\nexport interface ChannelSessionSnapshotIface {\n sessionId: string;\n conversationId: string | null;\n}\n\nexport interface ChannelCancelInputIface {\n reason?: string;\n throughMessageSeq?: number;\n}\n\nexport interface ChannelSessionOperationsIface {\n inspect(target: ChannelSessionTargetIface): Promise<ChannelSessionSnapshotIface | null>;\n resolve(target: ChannelSessionTargetIface): Promise<string | null>;\n send(\n target: ChannelSessionTargetIface,\n input: ChannelSendInputIface,\n ): Promise<ChannelInputReceiptIface>;\n respond(\n target: ChannelSessionTargetIface,\n input: ChannelResponseInputIface,\n ): Promise<{ resolved: boolean }>;\n cancel(\n target: ChannelSessionTargetIface,\n input?: ChannelCancelInputIface,\n ): Promise<{ accepted: boolean }>;\n close(target: ChannelSessionTargetIface): Promise<void>;\n observe(\n target: ChannelSessionTargetIface,\n input: { content: ContentBlock[]; idempotencyKey: string },\n ): Promise<void>;\n setConfigOption(\n target: ChannelSessionTargetIface,\n input: { configId: string; value: JsonValue },\n ): Promise<void>;\n park(target: ChannelSessionTargetIface): Promise<void>;\n getState(target: ChannelSessionTargetIface): Promise<JsonObject>;\n setState(target: ChannelSessionTargetIface, state: JsonObject): Promise<void>;\n // Input for another of the agent's channels: `final` targets `{ conversationId, participantId? }`.\n handoff(\n channel: string,\n target: JsonValue,\n input: ChannelSendInputIface,\n ): Promise<ChannelHandoffReceiptIface>;\n}\n\nexport interface ChannelSessionHandleIface {\n inspect(): Promise<ChannelSessionSnapshotIface | null>;\n resolveSession(): Promise<string | null>;\n send(input: ChannelSendInputIface): ReturnType<ChannelSessionOperationsIface['send']>;\n respond(input: ChannelResponseInputIface): ReturnType<ChannelSessionOperationsIface['respond']>;\n cancel(input?: ChannelCancelInputIface): ReturnType<ChannelSessionOperationsIface['cancel']>;\n close(): Promise<void>;\n observe(input: { content: ContentBlock[]; idempotencyKey: string }): Promise<void>;\n setConfigOption(input: { configId: string; value: JsonValue }): Promise<void>;\n park(): Promise<void>;\n getState(): Promise<JsonObject>;\n setState(state: JsonObject): Promise<void>;\n}\n\nexport interface ChannelAddressContextIface {\n from(address: string): ChannelSessionHandleIface;\n resolveSession(address: string): Promise<string | null>;\n attachSession(id: string): ChannelSessionHandleIface;\n to(\n channel: string,\n target: JsonValue,\n ): { send(input: ChannelSendInputIface): Promise<ChannelHandoffReceiptIface> };\n}\n\n// Handles resolve at operation time. Only attachSession captures a session ID.\nexport const channelAccessors = (\n platform: Pick<ChannelPlatformIface, 'channelSessions'>,\n): ChannelAddressContextIface => {\n const operations = () => {\n if (platform.channelSessions == null)\n throw new Error('channel session operations are unavailable');\n return platform.channelSessions;\n };\n const handle = (target: ChannelSessionTargetIface): ChannelSessionHandleIface => ({\n inspect: () => operations().inspect(target),\n resolveSession: () => operations().resolve(target),\n send: (input) => operations().send(target, input),\n respond: (input) => operations().respond(target, input),\n cancel: (input) => operations().cancel(target, input),\n close: () => operations().close(target),\n observe: (input) => operations().observe(target, input),\n setConfigOption: (input) => operations().setConfigOption(target, input),\n park: () => operations().park(target),\n getState: () => operations().getState(target),\n setState: (state) => operations().setState(target, state),\n });\n return {\n from: (address) => handle({ address }),\n resolveSession: (address) => operations().resolve({ address }),\n attachSession: (sessionId) => handle({ sessionId }),\n to: (channel, target) => ({ send: (input) => operations().handoff(channel, target, input) }),\n };\n};\n"],
5
+ "mappings": "AACA,YAAY,OAAO;AACnB,eAAkF;AAGlF,SAAS,sBAAsB,yBAAgD;AA8CxE,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACzB,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC;AAC7B,CAAC;AASM,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EACpC,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AACxC,CAAC;AAwEM,MAAM,mBAAmB,CAC9B,aAC+B;AAC/B,QAAM,aAAa,MAAM;AACvB,QAAI,SAAS,mBAAmB;AAC9B,YAAM,IAAI,MAAM,4CAA4C;AAC9D,WAAO,SAAS;AAAA,EAClB;AACA,QAAM,SAAS,CAAC,YAAkE;AAAA,IAChF,SAAS,MAAM,WAAW,EAAE,QAAQ,MAAM;AAAA,IAC1C,gBAAgB,MAAM,WAAW,EAAE,QAAQ,MAAM;AAAA,IACjD,MAAM,CAAC,UAAU,WAAW,EAAE,KAAK,QAAQ,KAAK;AAAA,IAChD,SAAS,CAAC,UAAU,WAAW,EAAE,QAAQ,QAAQ,KAAK;AAAA,IACtD,QAAQ,CAAC,UAAU,WAAW,EAAE,OAAO,QAAQ,KAAK;AAAA,IACpD,OAAO,MAAM,WAAW,EAAE,MAAM,MAAM;AAAA,IACtC,SAAS,CAAC,UAAU,WAAW,EAAE,QAAQ,QAAQ,KAAK;AAAA,IACtD,iBAAiB,CAAC,UAAU,WAAW,EAAE,gBAAgB,QAAQ,KAAK;AAAA,IACtE,MAAM,MAAM,WAAW,EAAE,KAAK,MAAM;AAAA,IACpC,UAAU,MAAM,WAAW,EAAE,SAAS,MAAM;AAAA,IAC5C,UAAU,CAAC,UAAU,WAAW,EAAE,SAAS,QAAQ,KAAK;AAAA,EAC1D;AACA,SAAO;AAAA,IACL,MAAM,CAAC,YAAY,OAAO,EAAE,QAAQ,CAAC;AAAA,IACrC,gBAAgB,CAAC,YAAY,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAAA,IAC7D,eAAe,CAAC,cAAc,OAAO,EAAE,UAAU,CAAC;AAAA,IAClD,IAAI,CAAC,SAAS,YAAY,EAAE,MAAM,CAAC,UAAU,WAAW,EAAE,QAAQ,SAAS,QAAQ,KAAK,EAAE;AAAA,EAC5F;AACF;",
6
+ "names": []
7
7
  }
@@ -1,25 +1,36 @@
1
1
  import type { HostedBindingsIface } from "./hosted-bindings.mjs";
2
2
  import type { ContentBlock, SessionUpdate } from '@agentclientprotocol/sdk/experimental/v2';
3
+ import type { SessionUpdateKind } from '@finalai/acp-session';
3
4
  import * as z from 'zod';
4
5
  import type { ChannelSessionOperationsIface } from "./channel-context.mjs";
5
6
  import { type JsonObject, type JsonValue } from "./json.mjs";
6
7
  import type { ProviderRef } from "./provider-ref.mjs";
7
8
  import type { SemanticChannelEventKind } from "./semantic-events.mjs";
9
+ export declare enum ChannelPrincipalType {
10
+ User = "user",
11
+ Service = "service"
12
+ }
13
+ export interface ChannelAuthIface extends JsonObject {
14
+ principalId: string;
15
+ principalType: ChannelPrincipalType | `${ChannelPrincipalType}`;
16
+ authenticator: string;
17
+ attributes: JsonObject;
18
+ }
19
+ export declare const channelAuthSchema: z.ZodObject<{
20
+ principalId: z.ZodString;
21
+ principalType: z.ZodEnum<typeof ChannelPrincipalType>;
22
+ authenticator: z.ZodString;
23
+ displayName: z.ZodOptional<z.ZodString>;
24
+ attributes: z.ZodDefault<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
25
+ }, z.core.$strip>;
26
+ export declare const principalDisplayName: (auth: ChannelAuthIface) => string;
8
27
  export declare enum ConversationKind {
9
28
  Direct = "direct",
10
29
  Group = "group"
11
30
  }
12
31
  export declare enum ParticipantKind {
13
32
  User = "user",
14
- Agent = "agent",
15
- System = "system"
16
- }
17
- export declare enum SystemParticipantKind {
18
- Schedule = "schedule",
19
- Webhook = "webhook",
20
- Goal = "goal",
21
- Tool = "tool",
22
- ApiKey = "api-key"
33
+ Agent = "agent"
23
34
  }
24
35
  export declare enum RoutingMode {
25
36
  Mention = "mention",
@@ -36,7 +47,6 @@ export declare enum Delivery {
36
47
  }
37
48
  export declare enum MessageKind {
38
49
  Message = "message",
39
- System = "system",
40
50
  Card = "card"
41
51
  }
42
52
  export declare enum CardKind {
@@ -49,9 +59,7 @@ export interface ParticipantIface {
49
59
  kind: ParticipantKind;
50
60
  displayName: string;
51
61
  userId: string | null;
52
- servicePrincipalId?: string | null;
53
62
  definitionId: string | null;
54
- systemKind: SystemParticipantKind | null;
55
63
  routingMode: RoutingMode | null;
56
64
  sessionId: string | null;
57
65
  supportsObserve: boolean | null;
@@ -153,7 +161,7 @@ export interface PromptArgsIface {
153
161
  id: string;
154
162
  revisionId: string;
155
163
  };
156
- auth?: JsonObject | null;
164
+ auth?: ChannelAuthIface | null;
157
165
  title?: string;
158
166
  participantId: string;
159
167
  content: ContentBlock[];
@@ -161,6 +169,7 @@ export interface PromptArgsIface {
161
169
  replyExpected: boolean;
162
170
  idempotencyKey: string;
163
171
  authorParticipantId: string;
172
+ actingUserId?: string | null;
164
173
  audienceParticipantIds: string[];
165
174
  sourceMessageId: string;
166
175
  }
@@ -206,12 +215,6 @@ export interface ChannelPlatformIface {
206
215
  }): Promise<ConversationIface>;
207
216
  boundTo(bindingId: string): Promise<ConversationIface | null>;
208
217
  participants(conversationId: string): Promise<ParticipantIface[]>;
209
- systemParticipant(args: {
210
- conversationId: string;
211
- systemKind: SystemParticipantKind;
212
- displayName: string;
213
- sourceRef: string;
214
- }): Promise<ParticipantIface>;
215
218
  postMessage(args: PostMessageArgsIface): Promise<ConversationMessageIface>;
216
219
  updateMessage(args: {
217
220
  messageId: string;
@@ -257,13 +260,12 @@ export interface ChannelInputResponseIface {
257
260
  id: string;
258
261
  revisionId: string;
259
262
  };
260
- auth?: JsonObject | null;
263
+ auth?: ChannelAuthIface | null;
261
264
  participantId: string;
262
265
  pendingId: string;
263
266
  outcome: JsonValue;
264
267
  actorParticipantId: string;
265
268
  userId: string | null;
266
- apiKeyId: string | null;
267
269
  }
268
270
  export interface ChannelReceiveContextIface {
269
271
  bindings?: HostedBindingsIface;
@@ -323,6 +325,10 @@ export interface ProjectionContextIface<State = JsonValue> {
323
325
  bindings?: HostedBindingsIface;
324
326
  sessionId?: string;
325
327
  platform: ChannelPlatformIface;
328
+ config: JsonObject;
329
+ secrets: {
330
+ get(name: string): Promise<string | null>;
331
+ };
326
332
  conversation: ConversationIface | null;
327
333
  agentParticipant: ParticipantIface | null;
328
334
  turn: {
@@ -338,6 +344,7 @@ export declare enum PendingEventKind {
338
344
  Resolved = "pending.resolved"
339
345
  }
340
346
  export type AcpUpdateKind = SessionUpdate['sessionUpdate'];
347
+ export type KnownAcpUpdateKind = `${SessionUpdateKind}`;
341
348
  export type ChannelEventKind = AcpUpdateKind | `${PendingEventKind}` | `${SemanticChannelEventKind}`;
342
349
  export interface ChannelEventIface {
343
350
  type: string;
@@ -359,6 +366,13 @@ export type PendingCreatedDataIface = z.infer<typeof pendingCreatedDataSchema>;
359
366
  export declare const pendingResolvedDataSchema: z.ZodObject<{
360
367
  pendingRequestId: z.ZodString;
361
368
  outcome: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
369
+ respondedBy: z.ZodDefault<z.ZodNullable<z.ZodObject<{
370
+ principalId: z.ZodString;
371
+ principalType: z.ZodEnum<typeof ChannelPrincipalType>;
372
+ authenticator: z.ZodString;
373
+ displayName: z.ZodOptional<z.ZodString>;
374
+ attributes: z.ZodDefault<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
375
+ }, z.core.$strip>>>;
362
376
  }, z.core.$strip>;
363
377
  export type PendingResolvedDataIface = z.infer<typeof pendingResolvedDataSchema>;
364
378
  export declare const PROJECTED_UPDATE_KINDS: ReadonlySet<AcpUpdateKind>;
@@ -1,5 +1,22 @@
1
1
  import * as z from "zod";
2
2
  import { jsonObjectSchema, jsonValueSchema } from "./json.mjs";
3
+ var ChannelPrincipalType = /* @__PURE__ */ ((ChannelPrincipalType2) => {
4
+ ChannelPrincipalType2["User"] = "user";
5
+ ChannelPrincipalType2["Service"] = "service";
6
+ return ChannelPrincipalType2;
7
+ })(ChannelPrincipalType || {});
8
+ const channelAuthSchema = z.object({
9
+ principalId: z.string().min(1),
10
+ principalType: z.nativeEnum(ChannelPrincipalType),
11
+ authenticator: z.string().min(1),
12
+ // How the agent and the people reading its reply name the principal.
13
+ displayName: z.string().min(1).max(200).optional(),
14
+ attributes: jsonObjectSchema.default({})
15
+ });
16
+ const principalDisplayName = (auth) => {
17
+ const name = auth["displayName"];
18
+ return typeof name === "string" && name.length > 0 ? name : auth.principalId;
19
+ };
3
20
  var ConversationKind = /* @__PURE__ */ ((ConversationKind2) => {
4
21
  ConversationKind2["Direct"] = "direct";
5
22
  ConversationKind2["Group"] = "group";
@@ -8,17 +25,8 @@ var ConversationKind = /* @__PURE__ */ ((ConversationKind2) => {
8
25
  var ParticipantKind = /* @__PURE__ */ ((ParticipantKind2) => {
9
26
  ParticipantKind2["User"] = "user";
10
27
  ParticipantKind2["Agent"] = "agent";
11
- ParticipantKind2["System"] = "system";
12
28
  return ParticipantKind2;
13
29
  })(ParticipantKind || {});
14
- var SystemParticipantKind = /* @__PURE__ */ ((SystemParticipantKind2) => {
15
- SystemParticipantKind2["Schedule"] = "schedule";
16
- SystemParticipantKind2["Webhook"] = "webhook";
17
- SystemParticipantKind2["Goal"] = "goal";
18
- SystemParticipantKind2["Tool"] = "tool";
19
- SystemParticipantKind2["ApiKey"] = "api-key";
20
- return SystemParticipantKind2;
21
- })(SystemParticipantKind || {});
22
30
  var RoutingMode = /* @__PURE__ */ ((RoutingMode2) => {
23
31
  RoutingMode2["Mention"] = "mention";
24
32
  RoutingMode2["All"] = "all";
@@ -37,7 +45,6 @@ var Delivery = /* @__PURE__ */ ((Delivery2) => {
37
45
  })(Delivery || {});
38
46
  var MessageKind = /* @__PURE__ */ ((MessageKind2) => {
39
47
  MessageKind2["Message"] = "message";
40
- MessageKind2["System"] = "system";
41
48
  MessageKind2["Card"] = "card";
42
49
  return MessageKind2;
43
50
  })(MessageKind || {});
@@ -81,7 +88,8 @@ const pendingCreatedDataSchema = z.object({
81
88
  });
82
89
  const pendingResolvedDataSchema = z.object({
83
90
  pendingRequestId: z.string().min(1),
84
- outcome: jsonValueSchema
91
+ outcome: jsonValueSchema,
92
+ respondedBy: channelAuthSchema.nullable().default(null)
85
93
  });
86
94
  const PROJECTED_UPDATE_KINDS = /* @__PURE__ */ new Set([
87
95
  "agent_message_chunk",
@@ -125,6 +133,7 @@ const turnEndUpdate = (stopReason) => {
125
133
  const defineChannel = (definition) => definition;
126
134
  export {
127
135
  CardKind,
136
+ ChannelPrincipalType,
128
137
  ConversationKind,
129
138
  Delivery,
130
139
  MessageKind,
@@ -133,13 +142,14 @@ export {
133
142
  PendingEventKind,
134
143
  PendingKind,
135
144
  RoutingMode,
136
- SystemParticipantKind,
137
145
  TurnPolicy,
146
+ channelAuthSchema,
138
147
  channelMessageInputSchema,
139
148
  channelReceiveResultSchema,
140
149
  defineChannel,
141
150
  pendingCreatedDataSchema,
142
151
  pendingResolvedDataSchema,
152
+ principalDisplayName,
143
153
  turnEndOf,
144
154
  turnEndUpdate
145
155
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/channel.ts"],
4
- "sourcesContent": ["import type { HostedBindingsIface } from \"./hosted-bindings.mjs\";\nimport type { ContentBlock, SessionUpdate } from '@agentclientprotocol/sdk/experimental/v2';\nimport * as z from 'zod';\nimport type { ChannelSessionOperationsIface } from \"./channel-context.mjs\";\nimport { jsonObjectSchema, jsonValueSchema, type JsonObject, type JsonValue } from \"./json.mjs\";\nimport type { ProviderRef } from \"./provider-ref.mjs\";\nimport type { SemanticChannelEventKind } from \"./semantic-events.mjs\";\n\n// Channels. Messaging has no orchestrator: a channel\n// receives input, inserts it into the conversation, routes it to agent\n// participants as ACP prompt or observe, and projects ACP updates back into\n// visible messages and cards. The built-in messaging channels implement this\n// contract with no private hooks into the session service; the session\n// service hands every channel the same ChannelPlatformIface.\n\nexport enum ConversationKind {\n Direct = 'direct',\n Group = 'group',\n}\n\nexport enum ParticipantKind {\n User = 'user',\n Agent = 'agent',\n System = 'system',\n}\n\nexport enum SystemParticipantKind {\n Schedule = 'schedule',\n Webhook = 'webhook',\n Goal = 'goal',\n Tool = 'tool',\n ApiKey = 'api-key',\n}\n\nexport enum RoutingMode {\n Mention = 'mention',\n All = 'all',\n Default = 'default',\n}\n\nexport enum TurnPolicy {\n Steer = 'steer',\n Queue = 'queue',\n}\n\nexport enum Delivery {\n Prompt = 'prompt',\n Observe = 'observe',\n}\n\nexport enum MessageKind {\n Message = 'message',\n System = 'system',\n Card = 'card',\n}\n\nexport enum CardKind {\n Elicitation = 'elicitation',\n Permission = 'permission',\n Notice = 'notice',\n}\n\nexport interface ParticipantIface {\n id: string;\n kind: ParticipantKind;\n displayName: string;\n userId: string | null;\n servicePrincipalId?: string | null;\n definitionId: string | null;\n systemKind: SystemParticipantKind | null;\n routingMode: RoutingMode | null;\n sessionId: string | null;\n // Whether the agent's harness supports _final/session/observe and renders\n // _meta[\"final.ai\"].author; null for non-agents.\n supportsObserve: boolean | null;\n rendersAuthorMeta: boolean | null;\n left: boolean;\n}\n\nexport const channelReceiveResultSchema = z.union([\n z.object({ conversationId: z.string().min(1) }),\n z.object({ sessionId: z.string().min(1) }),\n z.null(),\n]);\nexport type ChannelReceiveResult = z.infer<typeof channelReceiveResultSchema>;\n\nexport interface ConversationRefIface {\n conversationId: string;\n}\n\nexport interface ConversationIface extends ConversationRefIface {\n organizationId: string;\n kind: ConversationKind;\n title: string | null;\n isHome: boolean;\n turnPolicy: TurnPolicy;\n}\n\nexport interface MessageRefIface {\n messageId: string;\n seq: number;\n}\n\nexport interface ConversationMessageIface extends MessageRefIface {\n conversationId: string;\n authorParticipantId: string;\n kind: MessageKind;\n body: string;\n content: ContentBlock[];\n replyToMessageId: string | null;\n threadRootId: string | null;\n // Earlier messages of the conversation the author quoted, in order.\n quotedMessageIds: string[];\n // Agent participant ids explicitly mentioned in the message.\n mentionedParticipantIds: string[];\n // Number of agent-authored hops that led to this message (0 for humans).\n hopDepth: number;\n // The originating agent for a tool-posted message, including linked conversations.\n agentAuthorDefinitionId?: string | null;\n createdAt: string;\n}\n\nexport interface RouteArgsIface {\n conversation: ConversationIface;\n message: ConversationMessageIface;\n participants: ParticipantIface[];\n agentParticipantId?: string;\n}\n\nexport interface RouteDecisionIface {\n participantId: string;\n delivery: Delivery;\n}\n\nexport interface PostMessageArgsIface {\n conversationId: string;\n authorParticipantId: string;\n kind?: MessageKind;\n content: ContentBlock[];\n replyToMessageId?: string | null;\n threadRootId?: string | null;\n quotedMessageIds?: string[];\n clientMessageId?: string | null;\n mentionedParticipantIds?: string[];\n attachmentIds?: string[];\n hopDepth?: number;\n // A tool or linked-conversation event carries the turn that produced it.\n originTurnId?: string | null;\n // Projection provenance for agent replies.\n source?: { turnId: string; fromSeq: number; toSeq: number } | null;\n}\n\nexport const channelMessageInputSchema = z.object({\n conversationId: z.string().min(1),\n authorParticipantId: z.string().min(1),\n kind: z.nativeEnum(MessageKind).default(MessageKind.Message),\n content: z.array(jsonObjectSchema).min(1),\n clientMessageId: z.string().min(1).nullish(),\n replyToMessageId: z.string().min(1).nullish(),\n threadRootId: z.string().min(1).nullish(),\n quotedMessageIds: z.array(z.string().min(1)).default([]),\n mentionedParticipantIds: z.array(z.string().min(1)).default([]),\n});\n\nexport interface CardArgsIface {\n conversationId: string;\n authorParticipantId: string;\n kind: CardKind;\n pendingRequestId: string | null;\n // Generic cards only: a title, body, options, and entity links (a Goal is an\n // entity link, not a card kind).\n state: JsonObject;\n entityLinks: {\n kind: string;\n id: string;\n title?: string;\n url?: string;\n description?: string;\n imageUrl?: string;\n }[];\n}\n\nexport interface PromptArgsIface {\n waitForAcceptance?: boolean;\n channelBinding?: { id: string; revisionId: string };\n auth?: JsonObject | null;\n title?: string;\n participantId: string;\n content: ContentBlock[];\n turnPolicy: TurnPolicy;\n replyExpected: boolean;\n idempotencyKey: string;\n // Who prompted (for payer resolution and pending-request audience).\n authorParticipantId: string;\n audienceParticipantIds: string[];\n sourceMessageId: string;\n}\n\nexport interface ObserveArgsIface {\n participantId: string;\n content: ContentBlock[];\n idempotencyKey: string;\n}\n\n// What the session service lets a channel do. Implemented once, handed to\n// built-in and custom channels alike.\nexport interface ChannelPlatformIface {\n channelSessions?: ChannelSessionOperationsIface;\n conversations: {\n get(conversationId: string): Promise<ConversationIface | null>;\n createAttachmentUpload?(args: {\n conversationId: string;\n name: string;\n contentType: string;\n sizeBytes: number;\n }): Promise<{\n attachmentId: string;\n uploadUrl: string;\n method: string;\n headers: Record<string, string>;\n expiresAt: string;\n }>;\n getAttachmentUrl?(args: {\n conversationId: string;\n attachmentId: string;\n }): Promise<{ attachmentId: string; url: string; expiresAt: string }>;\n // Dispatch a stored reply to each recipient's binding; each channel owns routing.\n dispatchMessage?(args: {\n conversationId: string;\n messageId: string;\n participantId?: string;\n requestedDelivery?: Delivery;\n }): Promise<void>;\n findOrCreateDirect(args: {\n organizationId: string;\n userId: string;\n definitionId: string;\n }): Promise<ConversationIface>;\n // The conversation a channel binding is attached to.\n boundTo(bindingId: string): Promise<ConversationIface | null>;\n participants(conversationId: string): Promise<ParticipantIface[]>;\n systemParticipant(args: {\n conversationId: string;\n systemKind: SystemParticipantKind;\n displayName: string;\n sourceRef: string;\n }): Promise<ParticipantIface>;\n postMessage(args: PostMessageArgsIface): Promise<ConversationMessageIface>;\n updateMessage(args: {\n messageId: string;\n content: ContentBlock[];\n final: boolean;\n }): Promise<void>;\n postCard(args: CardArgsIface): Promise<ConversationMessageIface>;\n updateCard(args: { messageId: string; state: JsonObject }): Promise<void>;\n recentMessages(args: {\n conversationId: string;\n limit: number;\n beforeSeq?: number;\n afterSeq?: number;\n }): Promise<ConversationMessageIface[]>;\n // Messages of the conversation by id, however old (reply, thread and quote\n // context outside the recent window); unknown and deleted ones are absent.\n getMessages(args: {\n conversationId: string;\n messageIds: string[];\n }): Promise<ConversationMessageIface[]>;\n };\n sessions: {\n prompt(\n args: PromptArgsIface,\n ): Promise<{ messageId: string; sessionId?: string; turnId?: string }>;\n observe(args: ObserveArgsIface): Promise<void>;\n cancel(args: {\n participantId: string;\n reason?: string;\n throughMessageSeq?: number;\n }): Promise<void>;\n respond?(args: ChannelInputResponseIface): Promise<{ resolved: boolean }>;\n };\n log(message: string, details?: Record<string, JsonValue>): void;\n}\n\nexport interface ChannelInputResponseIface {\n channelBinding?: { id: string; revisionId: string };\n auth?: JsonObject | null;\n participantId: string;\n pendingId: string;\n outcome: JsonValue;\n actorParticipantId: string;\n userId: string | null;\n apiKeyId: string | null;\n}\n\nexport interface ChannelReceiveContextIface {\n bindings?: HostedBindingsIface;\n platform: ChannelPlatformIface;\n organizationId: string;\n definitionId: string | null;\n bindingId: string | null;\n config: JsonObject;\n secrets: { get(name: string): Promise<string | null> };\n // A stored, authenticated delivery to one agent in a shared conversation.\n agentParticipantId?: string;\n message?: ConversationMessageIface;\n conversation?: ConversationIface;\n participants?: readonly ParticipantIface[];\n response?: ChannelInputResponseIface;\n conversationId?: string;\n cancelReason?: string;\n // Preserve this boundary when forwarding a retryable conversation Stop.\n cancelThroughMessageSeq?: number;\n requestedDelivery?: Delivery;\n}\n\n// An HTTP route a channel serves (webhooks), mounted by the front door at\n// /api/events/webhooks/:bindingId<path> and the per-agent aliases.\nexport interface ChannelRouteContextIface {\n bindings?: HostedBindingsIface;\n request: Request;\n secrets: { get(name: string): Promise<string | null> };\n receive: (input: JsonValue) => Promise<ChannelReceiveResult>;\n}\n\nexport interface ChannelSocketIface {\n readonly signal: AbortSignal;\n readonly messages: AsyncIterable<string | Uint8Array>;\n // Authenticate the request before accepting. The selected protocol must have been offered.\n accept(options?: { protocol?: string }): void;\n send(data: string | Uint8Array): void;\n close(code?: number, reason?: string): void;\n}\n\nexport interface HttpChannelRouteDefinitionIface {\n method: 'GET' | 'POST' | 'PUT' | 'DELETE';\n path: string;\n handler: (args: ChannelRouteContextIface) => Promise<Response>;\n}\n\nexport interface WebSocketChannelRouteDefinitionIface {\n method: 'WS';\n path: string;\n // Returning an HTTP response before accept rejects the handshake. The handler lives until close.\n handler: (\n args: ChannelRouteContextIface & { socket: ChannelSocketIface },\n ) => Promise<Response | void>;\n}\n\nexport type RouteDefinitionIface =\n | HttpChannelRouteDefinitionIface\n | WebSocketChannelRouteDefinitionIface;\n\n// The per-turn value a channel keeps between its project and event calls of\n// one turn (the definition's `State`). The platform holds it, so a channel\n// running in a Worker isolate keeps nothing in memory; it starts null each turn\n// and is discarded when the turn's projection finishes.\nexport interface ChannelTurnStateIface<State> {\n get(): State | null;\n set(state: State | null): void;\n}\n\nexport interface ProjectionContextIface<State = JsonValue> {\n bindings?: HostedBindingsIface;\n sessionId?: string;\n platform: ChannelPlatformIface;\n conversation: ConversationIface | null;\n agentParticipant: ParticipantIface | null;\n turn: { id: string; promptMessageId: string | null; authorParticipantId: string | null };\n seq: number;\n state: ChannelTurnStateIface<State>;\n}\n\nexport enum PendingEventKind {\n Created = 'pending.created',\n Resolved = 'pending.resolved',\n}\n\nexport type AcpUpdateKind = SessionUpdate['sessionUpdate'];\n\nexport type ChannelEventKind =\n | AcpUpdateKind\n | `${PendingEventKind}`\n | `${SemanticChannelEventKind}`;\n\nexport interface ChannelEventIface {\n type: string;\n data: JsonValue;\n seq: number;\n}\n\nexport type ChannelEventHandler<State = JsonValue> = (\n event: ChannelEventIface,\n ctx: ProjectionContextIface<State>,\n) => Promise<void>;\n\nexport enum PendingKind {\n Permission = 'permission',\n Elicitation = 'elicitation',\n}\n\n// `data` of a pending.created event: an ACP session/request_permission or\n// elicitation/create request awaiting its audience.\nexport const pendingCreatedDataSchema = z.object({\n pendingRequestId: z.string().min(1),\n kind: z.nativeEnum(PendingKind),\n audienceParticipantIds: z.array(z.string()),\n request: jsonValueSchema,\n});\n\nexport type PendingCreatedDataIface = z.infer<typeof pendingCreatedDataSchema>;\n\n// `data` of a pending.resolved event: the answer (or cancellation) as recorded.\nexport const pendingResolvedDataSchema = z.object({\n pendingRequestId: z.string().min(1),\n outcome: jsonValueSchema,\n});\n\nexport type PendingResolvedDataIface = z.infer<typeof pendingResolvedDataSchema>;\n\n// The visible-output updates `project` receives. After them, the\n// turn's projection ends with one ACP v2 idle `state_update` (turnEndUpdate).\n// Thought, tool, plan and every other update, other state updates included,\n// reach a channel only through an `events` handler for its kind.\nexport const PROJECTED_UPDATE_KINDS: ReadonlySet<AcpUpdateKind> = new Set<AcpUpdateKind>([\n 'agent_message_chunk',\n 'agent_message',\n]);\n\nconst turnEndSchema = z.looseObject({\n sessionUpdate: z.literal('state_update'),\n state: z.literal('idle'),\n stopReason: z.string().nullish(),\n _meta: z\n .looseObject({ 'final.ai': z.looseObject({ stopReason: z.string().nullish() }).nullish() })\n .nullish(),\n});\n\n// The stop reason when the update ends the turn (an idle state_update); null otherwise.\nexport const turnEndOf = (update: SessionUpdate): { stopReason: string | null } | null => {\n const parsed = turnEndSchema.safeParse(update);\n if (!parsed.success) return null;\n return {\n stopReason: parsed.data.stopReason ?? parsed.data._meta?.['final.ai']?.stopReason ?? null,\n };\n};\n\n// The idle state_update that ends a turn, as `project` receives it. A stop\n// reason outside ACP's known set rides in `_meta[\"final.ai\"]` (the SDK types\n// only received values as unknown variants).\nexport const turnEndUpdate = (stopReason: string | null): SessionUpdate => {\n switch (stopReason) {\n case null:\n return { sessionUpdate: 'state_update', state: 'idle' };\n case 'end_turn':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'end_turn' };\n case 'max_tokens':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'max_tokens' };\n case 'max_turn_requests':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'max_turn_requests' };\n case 'refusal':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'refusal' };\n case 'cancelled':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'cancelled' };\n default:\n return {\n sessionUpdate: 'state_update',\n state: 'idle',\n _meta: { 'final.ai': { stopReason } },\n };\n }\n};\n\n// Built-in and custom (bundle) channels implement exactly this; the\n// session service calls nothing else on a channel.\nexport interface ChannelDefinitionIface<Inbound, State = undefined> {\n config?: JsonObject;\n // Installed execution is an optimization for an uncustomized definition.\n installed?: ProviderRef;\n configure?: (config: JsonObject) => ChannelDefinitionIface<Inbound, State>;\n routes?: RouteDefinitionIface[];\n respond?(\n input: ChannelInputResponseIface,\n ctx: ChannelReceiveContextIface,\n ): Promise<{ resolved: boolean }>;\n cancel?(ctx: ChannelReceiveContextIface): Promise<{ accepted: boolean }>;\n // Inserts the input into its conversation and routes it. Returns where it went.\n receive(input: Inbound, ctx: ChannelReceiveContextIface): Promise<ChannelReceiveResult>;\n // Pure: who gets this message, and how. The channel applies it\n // to what it posts, from receive and project.\n route(args: RouteArgsIface): RouteDecisionIface[] | Promise<RouteDecisionIface[]>;\n turnPolicy: TurnPolicy;\n // ACP update \u2192 visible message / card. Called with a turn's\n // PROJECTED_UPDATE_KINDS updates in seq order, then its idle state_update.\n project(update: SessionUpdate, ctx: ProjectionContextIface<State>): Promise<void>;\n events?: Partial<Record<ChannelEventKind, ChannelEventHandler<State>>>;\n}\n\nexport const defineChannel = <Inbound, State = undefined>(\n definition: ChannelDefinitionIface<Inbound, State>,\n): ChannelDefinitionIface<Inbound, State> => definition;\n"],
5
- "mappings": "AAEA,YAAY,OAAO;AAEnB,SAAS,kBAAkB,uBAAwD;AAW5E,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,YAAS;AACT,EAAAA,kBAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAKL,IAAK,kBAAL,kBAAKC,qBAAL;AACL,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,YAAS;AAHC,SAAAA;AAAA,GAAA;AAML,IAAK,wBAAL,kBAAKC,2BAAL;AACL,EAAAA,uBAAA,cAAW;AACX,EAAAA,uBAAA,aAAU;AACV,EAAAA,uBAAA,UAAO;AACP,EAAAA,uBAAA,UAAO;AACP,EAAAA,uBAAA,YAAS;AALC,SAAAA;AAAA,GAAA;AAQL,IAAK,cAAL,kBAAKC,iBAAL;AACL,EAAAA,aAAA,aAAU;AACV,EAAAA,aAAA,SAAM;AACN,EAAAA,aAAA,aAAU;AAHA,SAAAA;AAAA,GAAA;AAML,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAKL,IAAK,WAAL,kBAAKC,cAAL;AACL,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;AAKL,IAAK,cAAL,kBAAKC,iBAAL;AACL,EAAAA,a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;AAAA,IAClF,KAAK;AACH,aAAO,EAAE,eAAe,gBAAgB,OAAO,QAAQ,YAAY,oBAAoB;AAAA,IACzF,KAAK;AACH,aAAO,EAAE,eAAe,gBAAgB,OAAO,QAAQ,YAAY,UAAU;AAAA,IAC/E,KAAK;AACH,aAAO,EAAE,eAAe,gBAAgB,OAAO,QAAQ,YAAY,YAAY;AAAA,IACjF;AACE,aAAO;AAAA,QACL,eAAe;AAAA,QACf,OAAO;AAAA,QACP,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE;AAAA,MACtC;AAAA,EACJ;AACF;AA2BO,MAAM,gBAAgB,CAC3B,eAC2C;",
6
- "names": ["ConversationKind", "ParticipantKind", "SystemParticipantKind", "RoutingMode", "TurnPolicy", "Delivery", "MessageKind", "CardKind", "PendingEventKind", "PendingKind"]
4
+ "sourcesContent": ["import type { HostedBindingsIface } from \"./hosted-bindings.mjs\";\nimport type { ContentBlock, SessionUpdate } from '@agentclientprotocol/sdk/experimental/v2';\nimport type { SessionUpdateKind } from '@finalai/acp-session';\nimport * as z from 'zod';\nimport type { ChannelSessionOperationsIface } from \"./channel-context.mjs\";\nimport { jsonObjectSchema, jsonValueSchema, type JsonObject, type JsonValue } from \"./json.mjs\";\nimport type { ProviderRef } from \"./provider-ref.mjs\";\nimport type { SemanticChannelEventKind } from \"./semantic-events.mjs\";\n\n// Channels. Messaging has no orchestrator: a channel\n// receives input, inserts it into the conversation, routes it to agent\n// participants as ACP prompt or observe, and projects ACP updates back into\n// visible messages and cards. The built-in messaging channels implement this\n// contract with no private hooks into the session service; the session\n// service hands every channel the same ChannelPlatformIface.\n//\n// Members of a conversation are people and agents. Everything else an agent\n// hears (a schedule, a webhook, a Goal, another agent or channel) is channel\n// input from a principal (`ChannelAuthIface`), sent with\n// `channelSessions.send`; it is never a message.\n\nexport enum ChannelPrincipalType {\n User = 'user',\n Service = 'service',\n}\n\n// Who a channel authenticated for an input or a response. Channels vouch for\n// their principals; one principal per authenticator (`slack:<user>`), so\n// the same person on two surfaces is two principals.\nexport interface ChannelAuthIface extends JsonObject {\n principalId: string;\n principalType: ChannelPrincipalType | `${ChannelPrincipalType}`;\n authenticator: string;\n // `displayName` (a string) when the channel names the principal; see principalDisplayName.\n attributes: JsonObject;\n}\n\nexport const channelAuthSchema = z.object({\n principalId: z.string().min(1),\n principalType: z.nativeEnum(ChannelPrincipalType),\n authenticator: z.string().min(1),\n // How the agent and the people reading its reply name the principal.\n displayName: z.string().min(1).max(200).optional(),\n attributes: jsonObjectSchema.default({}),\n});\n\n// How a principal is named to the agent and in captions: its `displayName`, else its id.\nexport const principalDisplayName = (auth: ChannelAuthIface): string => {\n const name = auth['displayName'];\n return typeof name === 'string' && name.length > 0 ? name : auth.principalId;\n};\n\nexport enum ConversationKind {\n Direct = 'direct',\n Group = 'group',\n}\n\nexport enum ParticipantKind {\n User = 'user',\n Agent = 'agent',\n}\n\nexport enum RoutingMode {\n Mention = 'mention',\n All = 'all',\n Default = 'default',\n}\n\nexport enum TurnPolicy {\n Steer = 'steer',\n Queue = 'queue',\n}\n\nexport enum Delivery {\n Prompt = 'prompt',\n Observe = 'observe',\n}\n\nexport enum MessageKind {\n Message = 'message',\n Card = 'card',\n}\n\nexport enum CardKind {\n Elicitation = 'elicitation',\n Permission = 'permission',\n Notice = 'notice',\n}\n\nexport interface ParticipantIface {\n id: string;\n kind: ParticipantKind;\n displayName: string;\n userId: string | null;\n definitionId: string | null;\n routingMode: RoutingMode | null;\n sessionId: string | null;\n // Whether the agent's harness supports _final/session/observe and renders\n // _meta[\"final.ai\"].author; null for non-agents.\n supportsObserve: boolean | null;\n rendersAuthorMeta: boolean | null;\n left: boolean;\n}\n\nexport const channelReceiveResultSchema = z.union([\n z.object({ conversationId: z.string().min(1) }),\n z.object({ sessionId: z.string().min(1) }),\n z.null(),\n]);\nexport type ChannelReceiveResult = z.infer<typeof channelReceiveResultSchema>;\n\nexport interface ConversationRefIface {\n conversationId: string;\n}\n\nexport interface ConversationIface extends ConversationRefIface {\n organizationId: string;\n kind: ConversationKind;\n title: string | null;\n isHome: boolean;\n turnPolicy: TurnPolicy;\n}\n\nexport interface MessageRefIface {\n messageId: string;\n seq: number;\n}\n\nexport interface ConversationMessageIface extends MessageRefIface {\n conversationId: string;\n authorParticipantId: string;\n kind: MessageKind;\n body: string;\n content: ContentBlock[];\n replyToMessageId: string | null;\n threadRootId: string | null;\n // Earlier messages of the conversation the author quoted, in order.\n quotedMessageIds: string[];\n // Agent participant ids explicitly mentioned in the message.\n mentionedParticipantIds: string[];\n // Number of agent-authored hops that led to this message (0 for humans).\n hopDepth: number;\n // The originating agent for a tool-posted message, including linked conversations.\n agentAuthorDefinitionId?: string | null;\n createdAt: string;\n}\n\nexport interface RouteArgsIface {\n conversation: ConversationIface;\n message: ConversationMessageIface;\n participants: ParticipantIface[];\n agentParticipantId?: string;\n}\n\nexport interface RouteDecisionIface {\n participantId: string;\n delivery: Delivery;\n}\n\nexport interface PostMessageArgsIface {\n conversationId: string;\n authorParticipantId: string;\n kind?: MessageKind;\n content: ContentBlock[];\n replyToMessageId?: string | null;\n threadRootId?: string | null;\n quotedMessageIds?: string[];\n clientMessageId?: string | null;\n mentionedParticipantIds?: string[];\n attachmentIds?: string[];\n hopDepth?: number;\n // A tool or linked-conversation event carries the turn that produced it.\n originTurnId?: string | null;\n // Projection provenance for agent replies.\n source?: { turnId: string; fromSeq: number; toSeq: number } | null;\n}\n\nexport const channelMessageInputSchema = z.object({\n conversationId: z.string().min(1),\n authorParticipantId: z.string().min(1),\n kind: z.nativeEnum(MessageKind).default(MessageKind.Message),\n content: z.array(jsonObjectSchema).min(1),\n clientMessageId: z.string().min(1).nullish(),\n replyToMessageId: z.string().min(1).nullish(),\n threadRootId: z.string().min(1).nullish(),\n quotedMessageIds: z.array(z.string().min(1)).default([]),\n mentionedParticipantIds: z.array(z.string().min(1)).default([]),\n});\n\nexport interface CardArgsIface {\n conversationId: string;\n authorParticipantId: string;\n kind: CardKind;\n pendingRequestId: string | null;\n // Generic cards only: a title, body, options, and entity links (a Goal is an\n // entity link, not a card kind).\n state: JsonObject;\n entityLinks: {\n kind: string;\n id: string;\n title?: string;\n url?: string;\n description?: string;\n imageUrl?: string;\n }[];\n}\n\nexport interface PromptArgsIface {\n waitForAcceptance?: boolean;\n channelBinding?: { id: string; revisionId: string };\n auth?: ChannelAuthIface | null;\n title?: string;\n participantId: string;\n content: ContentBlock[];\n turnPolicy: TurnPolicy;\n replyExpected: boolean;\n idempotencyKey: string;\n // Who prompted (for payer resolution and pending-request audience).\n authorParticipantId: string;\n // The person a prompt from no person acts for (payer and audience).\n actingUserId?: string | null;\n audienceParticipantIds: string[];\n sourceMessageId: string;\n}\n\nexport interface ObserveArgsIface {\n participantId: string;\n content: ContentBlock[];\n idempotencyKey: string;\n}\n\n// What the session service lets a channel do. Implemented once, handed to\n// built-in and custom channels alike.\nexport interface ChannelPlatformIface {\n channelSessions?: ChannelSessionOperationsIface;\n conversations: {\n get(conversationId: string): Promise<ConversationIface | null>;\n createAttachmentUpload?(args: {\n conversationId: string;\n name: string;\n contentType: string;\n sizeBytes: number;\n }): Promise<{\n attachmentId: string;\n uploadUrl: string;\n method: string;\n headers: Record<string, string>;\n expiresAt: string;\n }>;\n getAttachmentUrl?(args: {\n conversationId: string;\n attachmentId: string;\n }): Promise<{ attachmentId: string; url: string; expiresAt: string }>;\n // Dispatch a stored reply to each recipient's binding; each channel owns routing.\n dispatchMessage?(args: {\n conversationId: string;\n messageId: string;\n participantId?: string;\n requestedDelivery?: Delivery;\n }): Promise<void>;\n findOrCreateDirect(args: {\n organizationId: string;\n userId: string;\n definitionId: string;\n }): Promise<ConversationIface>;\n // The conversation a channel binding is attached to.\n boundTo(bindingId: string): Promise<ConversationIface | null>;\n participants(conversationId: string): Promise<ParticipantIface[]>;\n postMessage(args: PostMessageArgsIface): Promise<ConversationMessageIface>;\n updateMessage(args: {\n messageId: string;\n content: ContentBlock[];\n final: boolean;\n }): Promise<void>;\n postCard(args: CardArgsIface): Promise<ConversationMessageIface>;\n updateCard(args: { messageId: string; state: JsonObject }): Promise<void>;\n recentMessages(args: {\n conversationId: string;\n limit: number;\n beforeSeq?: number;\n afterSeq?: number;\n }): Promise<ConversationMessageIface[]>;\n // Messages of the conversation by id, however old (reply, thread and quote\n // context outside the recent window); unknown and deleted ones are absent.\n getMessages(args: {\n conversationId: string;\n messageIds: string[];\n }): Promise<ConversationMessageIface[]>;\n };\n sessions: {\n prompt(\n args: PromptArgsIface,\n ): Promise<{ messageId: string; sessionId?: string; turnId?: string }>;\n observe(args: ObserveArgsIface): Promise<void>;\n cancel(args: {\n participantId: string;\n reason?: string;\n throughMessageSeq?: number;\n }): Promise<void>;\n respond?(args: ChannelInputResponseIface): Promise<{ resolved: boolean }>;\n };\n log(message: string, details?: Record<string, JsonValue>): void;\n}\n\nexport interface ChannelInputResponseIface {\n channelBinding?: { id: string; revisionId: string };\n auth?: ChannelAuthIface | null;\n participantId: string;\n pendingId: string;\n outcome: JsonValue;\n actorParticipantId: string;\n userId: string | null;\n}\n\nexport interface ChannelReceiveContextIface {\n bindings?: HostedBindingsIface;\n platform: ChannelPlatformIface;\n organizationId: string;\n definitionId: string | null;\n bindingId: string | null;\n config: JsonObject;\n secrets: { get(name: string): Promise<string | null> };\n // A stored, authenticated delivery to one agent in a shared conversation.\n agentParticipantId?: string;\n message?: ConversationMessageIface;\n conversation?: ConversationIface;\n participants?: readonly ParticipantIface[];\n response?: ChannelInputResponseIface;\n conversationId?: string;\n cancelReason?: string;\n // Preserve this boundary when forwarding a retryable conversation Stop.\n cancelThroughMessageSeq?: number;\n requestedDelivery?: Delivery;\n}\n\n// An HTTP route a channel serves (webhooks), mounted by the front door at\n// /api/events/webhooks/:bindingId<path> and the per-agent aliases.\nexport interface ChannelRouteContextIface {\n bindings?: HostedBindingsIface;\n request: Request;\n secrets: { get(name: string): Promise<string | null> };\n receive: (input: JsonValue) => Promise<ChannelReceiveResult>;\n}\n\nexport interface ChannelSocketIface {\n readonly signal: AbortSignal;\n readonly messages: AsyncIterable<string | Uint8Array>;\n // Authenticate the request before accepting. The selected protocol must have been offered.\n accept(options?: { protocol?: string }): void;\n send(data: string | Uint8Array): void;\n close(code?: number, reason?: string): void;\n}\n\nexport interface HttpChannelRouteDefinitionIface {\n method: 'GET' | 'POST' | 'PUT' | 'DELETE';\n path: string;\n handler: (args: ChannelRouteContextIface) => Promise<Response>;\n}\n\nexport interface WebSocketChannelRouteDefinitionIface {\n method: 'WS';\n path: string;\n // Returning an HTTP response before accept rejects the handshake. The handler lives until close.\n handler: (\n args: ChannelRouteContextIface & { socket: ChannelSocketIface },\n ) => Promise<Response | void>;\n}\n\nexport type RouteDefinitionIface =\n | HttpChannelRouteDefinitionIface\n | WebSocketChannelRouteDefinitionIface;\n\n// The per-turn value a channel keeps between its project and event calls of\n// one turn (the definition's `State`). The platform holds it, so a channel\n// running in a Worker isolate keeps nothing in memory; it starts null each turn\n// and is discarded when the turn's projection finishes.\nexport interface ChannelTurnStateIface<State> {\n get(): State | null;\n set(state: State | null): void;\n}\n\nexport interface ProjectionContextIface<State = JsonValue> {\n bindings?: HostedBindingsIface;\n sessionId?: string;\n platform: ChannelPlatformIface;\n // The binding's config and the agent's secrets (manifest.secrets), as receive gets them:\n // a channel posts its replies back to its own service with them.\n config: JsonObject;\n secrets: { get(name: string): Promise<string | null> };\n conversation: ConversationIface | null;\n agentParticipant: ParticipantIface | null;\n turn: { id: string; promptMessageId: string | null; authorParticipantId: string | null };\n seq: number;\n state: ChannelTurnStateIface<State>;\n}\n\nexport enum PendingEventKind {\n Created = 'pending.created',\n Resolved = 'pending.resolved',\n}\n\nexport type AcpUpdateKind = SessionUpdate['sessionUpdate'];\n// The update kinds ACP v2 names; AcpUpdateKind also admits any other string.\nexport type KnownAcpUpdateKind = `${SessionUpdateKind}`;\n\nexport type ChannelEventKind =\n | AcpUpdateKind\n | `${PendingEventKind}`\n | `${SemanticChannelEventKind}`;\n\nexport interface ChannelEventIface {\n type: string;\n data: JsonValue;\n seq: number;\n}\n\nexport type ChannelEventHandler<State = JsonValue> = (\n event: ChannelEventIface,\n ctx: ProjectionContextIface<State>,\n) => Promise<void>;\n\nexport enum PendingKind {\n Permission = 'permission',\n Elicitation = 'elicitation',\n}\n\n// `data` of a pending.created event: an ACP session/request_permission or\n// elicitation/create request awaiting its audience.\nexport const pendingCreatedDataSchema = z.object({\n pendingRequestId: z.string().min(1),\n kind: z.nativeEnum(PendingKind),\n audienceParticipantIds: z.array(z.string()),\n request: jsonValueSchema,\n});\n\nexport type PendingCreatedDataIface = z.infer<typeof pendingCreatedDataSchema>;\n\n// `data` of a pending.resolved event: the answer (or cancellation) as recorded,\n// and the principal a channel answered as (null for Final rooms and expiries).\nexport const pendingResolvedDataSchema = z.object({\n pendingRequestId: z.string().min(1),\n outcome: jsonValueSchema,\n respondedBy: channelAuthSchema.nullable().default(null),\n});\n\nexport type PendingResolvedDataIface = z.infer<typeof pendingResolvedDataSchema>;\n\n// The visible-output updates `project` receives. After them, the\n// turn's projection ends with one ACP v2 idle `state_update` (turnEndUpdate).\n// Thought, tool, plan and every other update, other state updates included,\n// reach a channel only through an `events` handler for its kind.\nexport const PROJECTED_UPDATE_KINDS: ReadonlySet<AcpUpdateKind> = new Set<AcpUpdateKind>([\n 'agent_message_chunk',\n 'agent_message',\n]);\n\nconst turnEndSchema = z.looseObject({\n sessionUpdate: z.literal('state_update'),\n state: z.literal('idle'),\n stopReason: z.string().nullish(),\n _meta: z\n .looseObject({ 'final.ai': z.looseObject({ stopReason: z.string().nullish() }).nullish() })\n .nullish(),\n});\n\n// The stop reason when the update ends the turn (an idle state_update); null otherwise.\nexport const turnEndOf = (update: SessionUpdate): { stopReason: string | null } | null => {\n const parsed = turnEndSchema.safeParse(update);\n if (!parsed.success) return null;\n return {\n stopReason: parsed.data.stopReason ?? parsed.data._meta?.['final.ai']?.stopReason ?? null,\n };\n};\n\n// The idle state_update that ends a turn, as `project` receives it. A stop\n// reason outside ACP's known set rides in `_meta[\"final.ai\"]` (the SDK types\n// only received values as unknown variants).\nexport const turnEndUpdate = (stopReason: string | null): SessionUpdate => {\n switch (stopReason) {\n case null:\n return { sessionUpdate: 'state_update', state: 'idle' };\n case 'end_turn':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'end_turn' };\n case 'max_tokens':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'max_tokens' };\n case 'max_turn_requests':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'max_turn_requests' };\n case 'refusal':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'refusal' };\n case 'cancelled':\n return { sessionUpdate: 'state_update', state: 'idle', stopReason: 'cancelled' };\n default:\n return {\n sessionUpdate: 'state_update',\n state: 'idle',\n _meta: { 'final.ai': { stopReason } },\n };\n }\n};\n\n// Built-in and custom (bundle) channels implement exactly this; the\n// session service calls nothing else on a channel.\nexport interface ChannelDefinitionIface<Inbound, State = undefined> {\n config?: JsonObject;\n // Installed execution is an optimization for an uncustomized definition.\n installed?: ProviderRef;\n configure?: (config: JsonObject) => ChannelDefinitionIface<Inbound, State>;\n routes?: RouteDefinitionIface[];\n respond?(\n input: ChannelInputResponseIface,\n ctx: ChannelReceiveContextIface,\n ): Promise<{ resolved: boolean }>;\n cancel?(ctx: ChannelReceiveContextIface): Promise<{ accepted: boolean }>;\n // Inserts the input into its conversation and routes it. Returns where it went.\n receive(input: Inbound, ctx: ChannelReceiveContextIface): Promise<ChannelReceiveResult>;\n // Pure: who gets this message, and how. The channel applies it\n // to what it posts, from receive and project.\n route(args: RouteArgsIface): RouteDecisionIface[] | Promise<RouteDecisionIface[]>;\n turnPolicy: TurnPolicy;\n // ACP update \u2192 visible message / card. Called with a turn's\n // PROJECTED_UPDATE_KINDS updates in seq order, then its idle state_update.\n project(update: SessionUpdate, ctx: ProjectionContextIface<State>): Promise<void>;\n events?: Partial<Record<ChannelEventKind, ChannelEventHandler<State>>>;\n}\n\nexport const defineChannel = <Inbound, State = undefined>(\n definition: ChannelDefinition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,WAAW;AAAA,IAChF,KAAK;AACH,aAAO,EAAE,eAAe,gBAAgB,OAAO,QAAQ,YAAY,aAAa;AAAA,IAClF,KAAK;AACH,aAAO,EAAE,eAAe,gBAAgB,OAAO,QAAQ,YAAY,oBAAoB;AAAA,IACzF,KAAK;AACH,aAAO,EAAE,eAAe,gBAAgB,OAAO,QAAQ,YAAY,UAAU;AAAA,IAC/E,KAAK;AACH,aAAO,EAAE,eAAe,gBAAgB,OAAO,QAAQ,YAAY,YAAY;AAAA,IACjF;AACE,aAAO;AAAA,QACL,eAAe;AAAA,QACf,OAAO;AAAA,QACP,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE;AAAA,MACtC;AAAA,EACJ;AACF;AA2BO,MAAM,gBAAgB,CAC3B,eAC2C;",
6
+ "names": ["ChannelPrincipalType", "ConversationKind", "ParticipantKind", "RoutingMode", "TurnPolicy", "Delivery", "MessageKind", "CardKind", "PendingEventKind", "PendingKind"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finalai/agent-provider",
3
- "version": "0.1.7",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "description": "Provider contracts for the agent stack: harnesses, sandboxes (handle, wire, MCP projection), channels, credential policies, and the conformance kit.",
6
6
  "license": "Apache-2.0",
@@ -183,8 +183,8 @@
183
183
  },
184
184
  "dependencies": {
185
185
  "@agentclientprotocol/sdk": "1.8.0",
186
- "@finalai/acp-session": "0.1.4",
187
- "@finalai/agent-protocol": "0.1.4",
186
+ "@finalai/acp-session": "0.1.7",
187
+ "@finalai/agent-protocol": "0.2.1",
188
188
  "@modelcontextprotocol/client": "^2.1.0",
189
189
  "@modelcontextprotocol/core": "^2.1.0",
190
190
  "@modelcontextprotocol/server": "^2.1.0",