@finalai/final-agent-provider 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +1 -8
  2. package/dist/modules/sandboxes/local.d.mts +2 -1
  3. package/dist/modules/sandboxes/local.mjs +64 -8
  4. package/dist/modules/sandboxes/local.mjs.map +2 -2
  5. package/package.json +5 -41
  6. package/dist/modules/authoring-final-channel.d.mts +0 -3
  7. package/dist/modules/authoring-final-channel.mjs +0 -10
  8. package/dist/modules/authoring-final-channel.mjs.map +0 -7
  9. package/dist/modules/channel-factories.d.mts +0 -40
  10. package/dist/modules/channel-factories.mjs +0 -212
  11. package/dist/modules/channel-factories.mjs.map +0 -7
  12. package/dist/modules/channels/content.d.mts +0 -6
  13. package/dist/modules/channels/content.mjs +0 -31
  14. package/dist/modules/channels/content.mjs.map +0 -7
  15. package/dist/modules/channels/delivery.d.mts +0 -54
  16. package/dist/modules/channels/delivery.mjs +0 -243
  17. package/dist/modules/channels/delivery.mjs.map +0 -7
  18. package/dist/modules/channels/direct-messaging.d.mts +0 -5
  19. package/dist/modules/channels/direct-messaging.mjs +0 -8
  20. package/dist/modules/channels/direct-messaging.mjs.map +0 -7
  21. package/dist/modules/channels/fake-platform.d.mts +0 -36
  22. package/dist/modules/channels/fake-platform.mjs +0 -168
  23. package/dist/modules/channels/fake-platform.mjs.map +0 -7
  24. package/dist/modules/channels/group-messaging.d.mts +0 -5
  25. package/dist/modules/channels/group-messaging.mjs +0 -8
  26. package/dist/modules/channels/group-messaging.mjs.map +0 -7
  27. package/dist/modules/channels/inbound.d.mts +0 -52
  28. package/dist/modules/channels/inbound.mjs +0 -42
  29. package/dist/modules/channels/inbound.mjs.map +0 -7
  30. package/dist/modules/channels/index.d.mts +0 -9
  31. package/dist/modules/channels/index.mjs +0 -10
  32. package/dist/modules/channels/index.mjs.map +0 -7
  33. package/dist/modules/channels/messaging-channel.d.mts +0 -7
  34. package/dist/modules/channels/messaging-channel.mjs +0 -99
  35. package/dist/modules/channels/messaging-channel.mjs.map +0 -7
  36. package/dist/modules/channels/projection.d.mts +0 -36
  37. package/dist/modules/channels/projection.mjs +0 -233
  38. package/dist/modules/channels/projection.mjs.map +0 -7
  39. package/dist/modules/channels/prompt.d.mts +0 -72
  40. package/dist/modules/channels/prompt.mjs +0 -208
  41. package/dist/modules/channels/prompt.mjs.map +0 -7
  42. package/dist/modules/channels/routing.d.mts +0 -5
  43. package/dist/modules/channels/routing.mjs +0 -53
  44. package/dist/modules/channels/routing.mjs.map +0 -7
@@ -1,5 +0,0 @@
1
- import type { RoomSurfaceDefinitionIface, JsonValue } from '@finalai/agent-provider';
2
- import { type MessagingChannelConfigIface } from "./messaging-channel.mjs";
3
- export type DirectMessagingChannelConfigIface = MessagingChannelConfigIface;
4
- export declare const DIRECT_MESSAGING_SPECIFIER = "@finalai/final-agent-provider/channels/direct-messaging";
5
- export declare const createDirectMessagingChannel: (config?: DirectMessagingChannelConfigIface) => RoomSurfaceDefinitionIface<JsonValue, JsonValue>;
@@ -1,8 +0,0 @@
1
- import { createMessagingChannel } from "./messaging-channel.mjs";
2
- const DIRECT_MESSAGING_SPECIFIER = "@finalai/final-agent-provider/channels/direct-messaging";
3
- const createDirectMessagingChannel = (config = {}) => createMessagingChannel(config);
4
- export {
5
- DIRECT_MESSAGING_SPECIFIER,
6
- createDirectMessagingChannel
7
- };
8
- //# sourceMappingURL=direct-messaging.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/channels/direct-messaging.ts"],
4
- "sourcesContent": ["import type { RoomSurfaceDefinitionIface, JsonValue } from '@finalai/agent-provider';\nimport { createMessagingChannel, type MessagingChannelConfigIface } from \"./messaging-channel.mjs\";\n\nexport type DirectMessagingChannelConfigIface = MessagingChannelConfigIface;\n\nexport const DIRECT_MESSAGING_SPECIFIER = '@finalai/final-agent-provider/channels/direct-messaging';\n\n// One user and one agent; every human message prompts the agent.\nexport const createDirectMessagingChannel = (\n config: DirectMessagingChannelConfigIface = {},\n): RoomSurfaceDefinitionIface<JsonValue, JsonValue> => createMessagingChannel(config);\n"],
5
- "mappings": "AACA,SAAS,8BAAgE;AAIlE,MAAM,6BAA6B;AAGnC,MAAM,+BAA+B,CAC1C,SAA4C,CAAC,MACQ,uBAAuB,MAAM;",
6
- "names": []
7
- }
@@ -1,36 +0,0 @@
1
- import { ConversationKind, ParticipantKind, TurnPolicy, type RoomPlatformIface, type ConversationIface, type ConversationMessageIface, type JsonObject, type ObserveArgsIface, type ParticipantIface, type PromptArgsIface } from '@finalai/agent-provider';
2
- export interface FakeMessageIface extends ConversationMessageIface {
3
- final: boolean;
4
- updates: number;
5
- source: {
6
- turnId: string;
7
- fromSeq: number;
8
- toSeq: number;
9
- } | null;
10
- }
11
- export interface FakeCardIface {
12
- messageId: string;
13
- decisionId: string | null;
14
- state: JsonObject;
15
- }
16
- export interface FakePlatformIface {
17
- platform: RoomPlatformIface;
18
- conversations: Map<string, ConversationIface>;
19
- participants: Map<string, ParticipantIface[]>;
20
- messages: FakeMessageIface[];
21
- cards: FakeCardIface[];
22
- prompts: PromptArgsIface[];
23
- observes: ObserveArgsIface[];
24
- logs: string[];
25
- getMessagesCalls: string[][];
26
- addConversation(args: {
27
- conversationId: string;
28
- kind: ConversationKind;
29
- turnPolicy?: TurnPolicy;
30
- }): ConversationIface;
31
- addParticipant(conversationId: string, participant: Partial<ParticipantIface> & {
32
- id: string;
33
- kind: ParticipantKind;
34
- }): ParticipantIface;
35
- }
36
- export declare const createFakePlatform: () => FakePlatformIface;
@@ -1,168 +0,0 @@
1
- import {
2
- ConversationKind,
3
- MessageKind,
4
- ParticipantKind,
5
- TurnPolicy
6
- } from "@finalai/agent-provider";
7
- import { routeToParticipant } from "./routing.mjs";
8
- import { deliverMessage } from "./delivery.mjs";
9
- import { messageSummary } from "./prompt.mjs";
10
- import { routeMessage } from "./routing.mjs";
11
- const createFakePlatform = () => {
12
- const conversations = /* @__PURE__ */ new Map();
13
- const participants = /* @__PURE__ */ new Map();
14
- const messages = [];
15
- const cards = [];
16
- const prompts = [];
17
- const observes = [];
18
- const logs = [];
19
- const getMessagesCalls = [];
20
- let nextId = 1;
21
- const addConversation = (args) => {
22
- const conversation = {
23
- conversationId: args.conversationId,
24
- organizationId: "org",
25
- kind: args.kind,
26
- title: null,
27
- isHome: false,
28
- turnPolicy: args.turnPolicy ?? TurnPolicy.Steer
29
- };
30
- conversations.set(args.conversationId, conversation);
31
- participants.set(args.conversationId, []);
32
- return conversation;
33
- };
34
- const addParticipant = (conversationId, partial) => {
35
- const participant = {
36
- displayName: partial.id,
37
- userId: null,
38
- definitionId: null,
39
- routingMode: null,
40
- sessionId: partial.kind === ParticipantKind.Agent ? `session-${partial.id}` : null,
41
- supportsObserve: partial.kind === ParticipantKind.Agent ? true : null,
42
- rendersAuthorMeta: partial.kind === ParticipantKind.Agent ? true : null,
43
- left: false,
44
- ...partial
45
- };
46
- participants.get(conversationId)?.push(participant);
47
- return participant;
48
- };
49
- const nextSeq = (conversationId) => messages.filter((message) => message.conversationId === conversationId).length + 1;
50
- const insert = (args) => {
51
- const message = {
52
- messageId: `m${nextId++}`,
53
- seq: nextSeq(args.conversationId),
54
- conversationId: args.conversationId,
55
- authorParticipantId: args.authorParticipantId,
56
- kind: args.kind,
57
- body: messageSummary(args.content),
58
- content: args.content,
59
- replyToMessageId: args.replyToMessageId ?? null,
60
- threadRootId: args.threadRootId ?? null,
61
- quotedMessageIds: args.quotedMessageIds ?? [],
62
- mentionedParticipantIds: args.mentionedParticipantIds ?? [],
63
- hopDepth: args.hopDepth ?? 0,
64
- createdAt: (/* @__PURE__ */ new Date(0)).toISOString(),
65
- final: args.source == null,
66
- updates: 0,
67
- source: args.source ?? null
68
- };
69
- messages.push(message);
70
- return message;
71
- };
72
- const platform = {
73
- conversations: {
74
- dispatchMessage: async (input) => {
75
- const room = conversations.get(input.conversationId);
76
- const message = messages.find((entry) => entry.messageId === input.messageId);
77
- if (room == null || message == null) throw new Error("dispatch source missing");
78
- await deliverMessage({
79
- platform,
80
- conversation: room,
81
- message,
82
- turnPolicy: room.turnPolicy,
83
- route: input.participantId == null ? routeMessage : routeToParticipant(input.participantId)
84
- });
85
- },
86
- get: async (conversationId) => conversations.get(conversationId) ?? null,
87
- participants: async (conversationId) => participants.get(conversationId) ?? [],
88
- postMessage: async (args) => {
89
- if (args.clientMessageId != null) {
90
- const existing = messages.find(
91
- (message) => message.conversationId === args.conversationId && message.messageId === args.clientMessageId
92
- );
93
- if (existing != null) return existing;
94
- }
95
- return insert({ ...args, kind: args.kind ?? MessageKind.Message });
96
- },
97
- updateMessage: async (args) => {
98
- const message = messages.find((candidate) => candidate.messageId === args.messageId);
99
- if (message == null) throw new Error(`no message ${args.messageId}`);
100
- message.content = args.content;
101
- message.body = messageSummary(args.content);
102
- message.final = args.final;
103
- message.updates += 1;
104
- },
105
- postCard: async (args) => {
106
- const message = insert({
107
- conversationId: args.conversationId,
108
- authorParticipantId: args.authorParticipantId,
109
- kind: MessageKind.Card,
110
- content: []
111
- });
112
- cards.push({
113
- messageId: message.messageId,
114
- decisionId: args.decisionId,
115
- state: args.state
116
- });
117
- return message;
118
- },
119
- updateCard: async (args) => {
120
- const card = cards.find(
121
- (candidate) => candidate.messageId === args.messageId || candidate.decisionId === args.messageId
122
- );
123
- if (card == null) throw new Error(`no card ${args.messageId}`);
124
- card.state = { ...card.state, ...args.state };
125
- },
126
- recentMessages: async (args) => messages.filter(
127
- (message) => message.conversationId === args.conversationId && (args.beforeSeq == null || message.seq < args.beforeSeq) && (args.afterSeq == null || message.seq > args.afterSeq)
128
- ).slice(-args.limit),
129
- getMessages: async (args) => {
130
- getMessagesCalls.push(args.messageIds);
131
- return messages.filter(
132
- (message) => message.conversationId === args.conversationId && args.messageIds.includes(message.messageId)
133
- );
134
- }
135
- },
136
- sessions: {
137
- prompt: async (args) => {
138
- prompts.push(args);
139
- return { messageId: `acp-${prompts.length}` };
140
- },
141
- observe: async (args) => {
142
- observes.push(args);
143
- },
144
- cancel: async () => {
145
- }
146
- },
147
- log: (message) => {
148
- logs.push(message);
149
- }
150
- };
151
- return {
152
- platform,
153
- conversations,
154
- participants,
155
- messages,
156
- cards,
157
- prompts,
158
- observes,
159
- logs,
160
- getMessagesCalls,
161
- addConversation,
162
- addParticipant
163
- };
164
- };
165
- export {
166
- createFakePlatform
167
- };
168
- //# sourceMappingURL=fake-platform.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/channels/fake-platform.ts"],
4
- "sourcesContent": ["import type { ContentBlock } from '@agentclientprotocol/sdk/experimental/v2';\nimport {\n ConversationKind,\n MessageKind,\n ParticipantKind,\n TurnPolicy,\n type CardArgsIface,\n type RoomPlatformIface,\n type ConversationIface,\n type ConversationMessageIface,\n type JsonObject,\n type ObserveArgsIface,\n type ParticipantIface,\n type PromptArgsIface,\n} from '@finalai/agent-provider';\nimport { routeToParticipant } from \"./routing.mjs\";\nimport { deliverMessage } from \"./delivery.mjs\";\nimport { messageSummary } from \"./prompt.mjs\";\nimport { routeMessage } from \"./routing.mjs\";\n\n// An in-memory RoomPlatformIface for channel tests (not exported from the\n// package index). Records every prompt, observe, channel input and\n// visible-message write.\n\nexport interface FakeMessageIface extends ConversationMessageIface {\n final: boolean;\n updates: number;\n source: { turnId: string; fromSeq: number; toSeq: number } | null;\n}\n\nexport interface FakeCardIface {\n messageId: string;\n decisionId: string | null;\n state: JsonObject;\n}\n\nexport interface FakePlatformIface {\n platform: RoomPlatformIface;\n conversations: Map<string, ConversationIface>;\n participants: Map<string, ParticipantIface[]>;\n messages: FakeMessageIface[];\n cards: FakeCardIface[];\n prompts: PromptArgsIface[];\n observes: ObserveArgsIface[];\n logs: string[];\n // The message ids of each getMessages call.\n getMessagesCalls: string[][];\n addConversation(args: {\n conversationId: string;\n kind: ConversationKind;\n turnPolicy?: TurnPolicy;\n }): ConversationIface;\n addParticipant(\n conversationId: string,\n participant: Partial<ParticipantIface> & { id: string; kind: ParticipantKind },\n ): ParticipantIface;\n}\n\nexport const createFakePlatform = (): FakePlatformIface => {\n const conversations = new Map<string, ConversationIface>();\n const participants = new Map<string, ParticipantIface[]>();\n const messages: FakeMessageIface[] = [];\n const cards: FakeCardIface[] = [];\n const prompts: PromptArgsIface[] = [];\n const observes: ObserveArgsIface[] = [];\n const logs: string[] = [];\n const getMessagesCalls: string[][] = [];\n let nextId = 1;\n\n const addConversation: FakePlatformIface['addConversation'] = (args) => {\n const conversation: ConversationIface = {\n conversationId: args.conversationId,\n organizationId: 'org',\n kind: args.kind,\n title: null,\n isHome: false,\n turnPolicy: args.turnPolicy ?? TurnPolicy.Steer,\n };\n conversations.set(args.conversationId, conversation);\n participants.set(args.conversationId, []);\n return conversation;\n };\n\n const addParticipant: FakePlatformIface['addParticipant'] = (conversationId, partial) => {\n const participant: ParticipantIface = {\n displayName: partial.id,\n userId: null,\n definitionId: null,\n routingMode: null,\n sessionId: partial.kind === ParticipantKind.Agent ? `session-${partial.id}` : null,\n supportsObserve: partial.kind === ParticipantKind.Agent ? true : null,\n rendersAuthorMeta: partial.kind === ParticipantKind.Agent ? true : null,\n left: false,\n ...partial,\n };\n participants.get(conversationId)?.push(participant);\n return participant;\n };\n\n const nextSeq = (conversationId: string): number =>\n messages.filter((message) => message.conversationId === conversationId).length + 1;\n\n const insert = (args: {\n conversationId: string;\n authorParticipantId: string;\n kind: MessageKind;\n content: ContentBlock[];\n replyToMessageId?: string | null;\n threadRootId?: string | null;\n quotedMessageIds?: string[];\n mentionedParticipantIds?: string[];\n hopDepth?: number;\n source?: FakeMessageIface['source'];\n }): FakeMessageIface => {\n const message: FakeMessageIface = {\n messageId: `m${nextId++}`,\n seq: nextSeq(args.conversationId),\n conversationId: args.conversationId,\n authorParticipantId: args.authorParticipantId,\n kind: args.kind,\n body: messageSummary(args.content),\n content: args.content,\n replyToMessageId: args.replyToMessageId ?? null,\n threadRootId: args.threadRootId ?? null,\n quotedMessageIds: args.quotedMessageIds ?? [],\n mentionedParticipantIds: args.mentionedParticipantIds ?? [],\n hopDepth: args.hopDepth ?? 0,\n createdAt: new Date(0).toISOString(),\n final: args.source == null,\n updates: 0,\n source: args.source ?? null,\n };\n messages.push(message);\n return message;\n };\n\n const platform: RoomPlatformIface = {\n conversations: {\n dispatchMessage: async (input) => {\n const room = conversations.get(input.conversationId);\n const message = messages.find((entry) => entry.messageId === input.messageId);\n if (room == null || message == null) throw new Error('dispatch source missing');\n await deliverMessage({\n platform,\n conversation: room,\n message,\n turnPolicy: room.turnPolicy,\n route:\n input.participantId == null ? routeMessage : routeToParticipant(input.participantId),\n });\n },\n get: async (conversationId) => conversations.get(conversationId) ?? null,\n participants: async (conversationId) => participants.get(conversationId) ?? [],\n postMessage: async (args) => {\n if (args.clientMessageId != null) {\n const existing = messages.find(\n (message) =>\n message.conversationId === args.conversationId &&\n message.messageId === args.clientMessageId,\n );\n if (existing != null) return existing;\n }\n return insert({ ...args, kind: args.kind ?? MessageKind.Message });\n },\n updateMessage: async (args) => {\n const message = messages.find((candidate) => candidate.messageId === args.messageId);\n if (message == null) throw new Error(`no message ${args.messageId}`);\n message.content = args.content;\n message.body = messageSummary(args.content);\n message.final = args.final;\n message.updates += 1;\n },\n postCard: async (args: CardArgsIface) => {\n const message = insert({\n conversationId: args.conversationId,\n authorParticipantId: args.authorParticipantId,\n kind: MessageKind.Card,\n content: [],\n });\n cards.push({\n messageId: message.messageId,\n decisionId: args.decisionId,\n state: args.state,\n });\n return message;\n },\n updateCard: async (args) => {\n const card = cards.find(\n (candidate) =>\n candidate.messageId === args.messageId || candidate.decisionId === args.messageId,\n );\n if (card == null) throw new Error(`no card ${args.messageId}`);\n card.state = { ...card.state, ...args.state };\n },\n recentMessages: async (args) =>\n messages\n .filter(\n (message) =>\n message.conversationId === args.conversationId &&\n (args.beforeSeq == null || message.seq < args.beforeSeq) &&\n (args.afterSeq == null || message.seq > args.afterSeq),\n )\n .slice(-args.limit),\n getMessages: async (args) => {\n getMessagesCalls.push(args.messageIds);\n return messages.filter(\n (message) =>\n message.conversationId === args.conversationId &&\n args.messageIds.includes(message.messageId),\n );\n },\n },\n sessions: {\n prompt: async (args) => {\n prompts.push(args);\n return { messageId: `acp-${prompts.length}` };\n },\n observe: async (args) => {\n observes.push(args);\n },\n cancel: async () => {},\n },\n log: (message) => {\n logs.push(message);\n },\n };\n\n return {\n platform,\n conversations,\n participants,\n messages,\n cards,\n prompts,\n observes,\n logs,\n getMessagesCalls,\n addConversation,\n addParticipant,\n };\n};\n"],
5
- "mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OASK;AACP,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAwCtB,MAAM,qBAAqB,MAAyB;AACzD,QAAM,gBAAgB,oBAAI,IAA+B;AACzD,QAAM,eAAe,oBAAI,IAAgC;AACzD,QAAM,WAA+B,CAAC;AACtC,QAAM,QAAyB,CAAC;AAChC,QAAM,UAA6B,CAAC;AACpC,QAAM,WAA+B,CAAC;AACtC,QAAM,OAAiB,CAAC;AACxB,QAAM,mBAA+B,CAAC;AACtC,MAAI,SAAS;AAEb,QAAM,kBAAwD,CAAC,SAAS;AACtE,UAAM,eAAkC;AAAA,MACtC,gBAAgB,KAAK;AAAA,MACrB,gBAAgB;AAAA,MAChB,MAAM,KAAK;AAAA,MACX,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,YAAY,KAAK,cAAc,WAAW;AAAA,IAC5C;AACA,kBAAc,IAAI,KAAK,gBAAgB,YAAY;AACnD,iBAAa,IAAI,KAAK,gBAAgB,CAAC,CAAC;AACxC,WAAO;AAAA,EACT;AAEA,QAAM,iBAAsD,CAAC,gBAAgB,YAAY;AACvF,UAAM,cAAgC;AAAA,MACpC,aAAa,QAAQ;AAAA,MACrB,QAAQ;AAAA,MACR,cAAc;AAAA,MACd,aAAa;AAAA,MACb,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M,OAAO,MAAM;AAAA,UACjB,CAAC,cACC,UAAU,cAAc,KAAK,aAAa,UAAU,eAAe,KAAK;AAAA,QAC5E;AACA,YAAI,QAAQ,KAAM,OAAM,IAAI,MAAM,WAAW,KAAK,SAAS,EAAE;AAC7D,aAAK,QAAQ,EAAE,GAAG,KAAK,OAAO,GAAG,KAAK,MAAM;AAAA,MAC9C;AAAA,MACA,gBAAgB,OAAO,SACrB,SACG;AAAA,QACC,CAAC,YACC,QAAQ,mBAAmB,KAAK,mBAC/B,KAAK,aAAa,QAAQ,QAAQ,MAAM,KAAK,eAC7C,KAAK,YAAY,QAAQ,QAAQ,MAAM,KAAK;AAAA,MACjD,EACC,MAAM,CAAC,KAAK,KAAK;AAAA,MACtB,aAAa,OAAO,SAAS;AAC3B,yBAAiB,KAAK,KAAK,UAAU;AACrC,eAAO,SAAS;AAAA,UACd,CAAC,YACC,QAAQ,mBAAmB,KAAK,kBAChC,KAAK,WAAW,SAAS,QAAQ,SAAS;AAAA,QAC9C;AAAA,MACF;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,QAAQ,OAAO,SAAS;AACtB,gBAAQ,KAAK,IAAI;AACjB,eAAO,EAAE,WAAW,OAAO,QAAQ,MAAM,GAAG;AAAA,MAC9C;AAAA,MACA,SAAS,OAAO,SAAS;AACvB,iBAAS,KAAK,IAAI;AAAA,MACpB;AAAA,MACA,QAAQ,YAAY;AAAA,MAAC;AAAA,IACvB;AAAA,IACA,KAAK,CAAC,YAAY;AAChB,WAAK,KAAK,OAAO;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
6
- "names": []
7
- }
@@ -1,5 +0,0 @@
1
- import type { RoomSurfaceDefinitionIface, JsonValue } from '@finalai/agent-provider';
2
- import { type MessagingChannelConfigIface } from "./messaging-channel.mjs";
3
- export type GroupMessagingChannelConfigIface = MessagingChannelConfigIface;
4
- export declare const GROUP_MESSAGING_SPECIFIER = "@finalai/final-agent-provider/channels/group-messaging";
5
- export declare const createGroupMessagingChannel: (config?: GroupMessagingChannelConfigIface) => RoomSurfaceDefinitionIface<JsonValue, JsonValue>;
@@ -1,8 +0,0 @@
1
- import { createMessagingChannel } from "./messaging-channel.mjs";
2
- const GROUP_MESSAGING_SPECIFIER = "@finalai/final-agent-provider/channels/group-messaging";
3
- const createGroupMessagingChannel = (config = {}) => createMessagingChannel(config);
4
- export {
5
- GROUP_MESSAGING_SPECIFIER,
6
- createGroupMessagingChannel
7
- };
8
- //# sourceMappingURL=group-messaging.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/channels/group-messaging.ts"],
4
- "sourcesContent": ["import type { RoomSurfaceDefinitionIface, JsonValue } from '@finalai/agent-provider';\nimport { createMessagingChannel, type MessagingChannelConfigIface } from \"./messaging-channel.mjs\";\n\nexport type GroupMessagingChannelConfigIface = MessagingChannelConfigIface;\n\nexport const GROUP_MESSAGING_SPECIFIER = '@finalai/final-agent-provider/channels/group-messaging';\n\n// N users and M agents; routing modes and mentions decide prompt or observe.\nexport const createGroupMessagingChannel = (\n config: GroupMessagingChannelConfigIface = {},\n): RoomSurfaceDefinitionIface<JsonValue, JsonValue> => createMessagingChannel(config);\n"],
5
- "mappings": "AACA,SAAS,8BAAgE;AAIlE,MAAM,4BAA4B;AAGlC,MAAM,8BAA8B,CACzC,SAA2C,CAAC,MACS,uBAAuB,MAAM;",
6
- "names": []
7
- }
@@ -1,52 +0,0 @@
1
- import * as z from 'zod';
2
- import { MembershipChange } from "./delivery.mjs";
3
- export declare const messageInboundSchema: z.ZodObject<{
4
- conversationId: z.ZodString;
5
- authorParticipantId: z.ZodString;
6
- kind: z.ZodDefault<z.ZodEnum<typeof import("@finalai/agent-provider").MessageKind>>;
7
- content: z.ZodArray<z.ZodType<import("@finalai/agent-provider").JsonObject, unknown, z.core.$ZodTypeInternals<import("@finalai/agent-provider").JsonObject, unknown>>>;
8
- clientMessageId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9
- replyToMessageId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
10
- threadRootId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
11
- quotedMessageIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
12
- mentionedParticipantIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
13
- }, z.core.$strip>;
14
- export type MessageInboundIface = z.infer<typeof messageInboundSchema>;
15
- export declare enum ConversationEventKind {
16
- Reaction = "reaction",
17
- Membership = "membership"
18
- }
19
- export declare const reactionInboundSchema: z.ZodObject<{
20
- event: z.ZodLiteral<ConversationEventKind.Reaction>;
21
- conversationId: z.ZodString;
22
- messageId: z.ZodString;
23
- messageSeq: z.ZodNumber;
24
- latestOfAuthor: z.ZodBoolean;
25
- reactorParticipantId: z.ZodString;
26
- emoji: z.ZodString;
27
- eventId: z.ZodOptional<z.ZodString>;
28
- }, z.core.$strip>;
29
- export declare const membershipInboundSchema: z.ZodObject<{
30
- event: z.ZodLiteral<ConversationEventKind.Membership>;
31
- conversationId: z.ZodString;
32
- participantId: z.ZodString;
33
- change: z.ZodEnum<typeof MembershipChange>;
34
- eventId: z.ZodString;
35
- }, z.core.$strip>;
36
- export declare const conversationEventInboundSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
37
- event: z.ZodLiteral<ConversationEventKind.Reaction>;
38
- conversationId: z.ZodString;
39
- messageId: z.ZodString;
40
- messageSeq: z.ZodNumber;
41
- latestOfAuthor: z.ZodBoolean;
42
- reactorParticipantId: z.ZodString;
43
- emoji: z.ZodString;
44
- eventId: z.ZodOptional<z.ZodString>;
45
- }, z.core.$strip>, z.ZodObject<{
46
- event: z.ZodLiteral<ConversationEventKind.Membership>;
47
- conversationId: z.ZodString;
48
- participantId: z.ZodString;
49
- change: z.ZodEnum<typeof MembershipChange>;
50
- eventId: z.ZodString;
51
- }, z.core.$strip>], "event">;
52
- export type ConversationEventInboundIface = z.infer<typeof conversationEventInboundSchema>;
@@ -1,42 +0,0 @@
1
- import { roomMessageInputSchema } from "@finalai/agent-provider";
2
- import * as z from "zod";
3
- import { MembershipChange } from "./delivery.mjs";
4
- const messageInboundSchema = roomMessageInputSchema;
5
- var ConversationEventKind = /* @__PURE__ */ ((ConversationEventKind2) => {
6
- ConversationEventKind2["Reaction"] = "reaction";
7
- ConversationEventKind2["Membership"] = "membership";
8
- return ConversationEventKind2;
9
- })(ConversationEventKind || {});
10
- const reactionInboundSchema = z.object({
11
- event: z.literal("reaction" /* Reaction */),
12
- conversationId: z.string().min(1),
13
- messageId: z.string().min(1),
14
- // The reacted message's position, so it is read back however old it is.
15
- messageSeq: z.number().int().positive(),
16
- // Whether it is its author's newest message ("your last message").
17
- latestOfAuthor: z.boolean(),
18
- reactorParticipantId: z.string().min(1),
19
- emoji: z.string().min(1),
20
- // A new persisted message revision distinguishes removing and re-adding a reaction.
21
- eventId: z.string().min(1).optional()
22
- });
23
- const membershipInboundSchema = z.object({
24
- event: z.literal("membership" /* Membership */),
25
- conversationId: z.string().min(1),
26
- participantId: z.string().min(1),
27
- change: z.nativeEnum(MembershipChange),
28
- // Distinguishes repeated joins and leaves of one participant.
29
- eventId: z.string().min(1)
30
- });
31
- const conversationEventInboundSchema = z.discriminatedUnion("event", [
32
- reactionInboundSchema,
33
- membershipInboundSchema
34
- ]);
35
- export {
36
- ConversationEventKind,
37
- conversationEventInboundSchema,
38
- membershipInboundSchema,
39
- messageInboundSchema,
40
- reactionInboundSchema
41
- };
42
- //# sourceMappingURL=inbound.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/channels/inbound.ts"],
4
- "sourcesContent": ["import { roomMessageInputSchema } from '@finalai/agent-provider';\nimport * as z from 'zod';\nimport { MembershipChange } from \"./delivery.mjs\";\n\n// What the messaging channels receive: a message for an existing conversation,\n// authored by one of its participants (the HTTP API, an isolate callback).\nexport const messageInboundSchema = roomMessageInputSchema;\n\nexport type MessageInboundIface = z.infer<typeof messageInboundSchema>;\n\nexport enum ConversationEventKind {\n Reaction = 'reaction',\n Membership = 'membership',\n}\n\n// Conversation events that reach agents as observe-only system blocks.\nexport const reactionInboundSchema = z.object({\n event: z.literal(ConversationEventKind.Reaction),\n conversationId: z.string().min(1),\n messageId: z.string().min(1),\n // The reacted message's position, so it is read back however old it is.\n messageSeq: z.number().int().positive(),\n // Whether it is its author's newest message (\"your last message\").\n latestOfAuthor: z.boolean(),\n reactorParticipantId: z.string().min(1),\n emoji: z.string().min(1),\n // A new persisted message revision distinguishes removing and re-adding a reaction.\n eventId: z.string().min(1).optional(),\n});\n\nexport const membershipInboundSchema = z.object({\n event: z.literal(ConversationEventKind.Membership),\n conversationId: z.string().min(1),\n participantId: z.string().min(1),\n change: z.nativeEnum(MembershipChange),\n // Distinguishes repeated joins and leaves of one participant.\n eventId: z.string().min(1),\n});\n\nexport const conversationEventInboundSchema = z.discriminatedUnion('event', [\n reactionInboundSchema,\n membershipInboundSchema,\n]);\n\nexport type ConversationEventInboundIface = z.infer<typeof conversationEventInboundSchema>;\n"],
5
- "mappings": "AAAA,SAAS,8BAA8B;AACvC,YAAY,OAAO;AACnB,SAAS,wBAAwB;AAI1B,MAAM,uBAAuB;AAI7B,IAAK,wBAAL,kBAAKA,2BAAL;AACL,EAAAA,uBAAA,cAAW;AACX,EAAAA,uBAAA,gBAAa;AAFH,SAAAA;AAAA,GAAA;AAML,MAAM,wBAAwB,EAAE,OAAO;AAAA,EAC5C,OAAO,EAAE,QAAQ,yBAA8B;AAAA,EAC/C,gBAAgB,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAChC,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAE3B,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA;AAAA,EAEtC,gBAAgB,EAAE,QAAQ;AAAA,EAC1B,sBAAsB,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACtC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAEvB,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AACtC,CAAC;AAEM,MAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,OAAO,EAAE,QAAQ,6BAAgC;AAAA,EACjD,gBAAgB,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAChC,eAAe,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EAC/B,QAAQ,EAAE,WAAW,gBAAgB;AAAA;AAAA,EAErC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAC3B,CAAC;AAEM,MAAM,iCAAiC,EAAE,mBAAmB,SAAS;AAAA,EAC1E;AAAA,EACA;AACF,CAAC;",
6
- "names": ["ConversationEventKind"]
7
- }
@@ -1,9 +0,0 @@
1
- export * from "./content.mjs";
2
- export * from "./delivery.mjs";
3
- export * from "./direct-messaging.mjs";
4
- export * from "./group-messaging.mjs";
5
- export * from "./inbound.mjs";
6
- export * from "./messaging-channel.mjs";
7
- export * from "./projection.mjs";
8
- export * from "./prompt.mjs";
9
- export * from "./routing.mjs";
@@ -1,10 +0,0 @@
1
- export * from "./content.mjs";
2
- export * from "./delivery.mjs";
3
- export * from "./direct-messaging.mjs";
4
- export * from "./group-messaging.mjs";
5
- export * from "./inbound.mjs";
6
- export * from "./messaging-channel.mjs";
7
- export * from "./projection.mjs";
8
- export * from "./prompt.mjs";
9
- export * from "./routing.mjs";
10
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/channels/index.ts"],
4
- "sourcesContent": ["export * from \"./content.mjs\";\nexport * from \"./delivery.mjs\";\nexport * from \"./direct-messaging.mjs\";\nexport * from \"./group-messaging.mjs\";\nexport * from \"./inbound.mjs\";\nexport * from \"./messaging-channel.mjs\";\nexport * from \"./projection.mjs\";\nexport * from \"./prompt.mjs\";\nexport * from \"./routing.mjs\";\n"],
5
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- import { TurnPolicy, type RoomSurfaceDefinitionIface, type RoomReceiveContextIface, type ConversationRefIface, type JsonValue, type RouteArgsIface, type RouteDecisionIface } from '@finalai/agent-provider';
2
- import { type ProjectorConfigIface } from "./projection.mjs";
3
- export interface MessagingChannelConfigIface extends ProjectorConfigIface {
4
- route?: (args: RouteArgsIface) => RouteDecisionIface[] | Promise<RouteDecisionIface[]>;
5
- }
6
- export declare const createConversationReceive: (turnPolicy: TurnPolicy, route?: NonNullable<MessagingChannelConfigIface["route"]>) => (input: JsonValue, ctx: RoomReceiveContextIface) => Promise<ConversationRefIface>;
7
- export declare const createMessagingChannel: (config?: MessagingChannelConfigIface) => RoomSurfaceDefinitionIface<JsonValue, JsonValue>;
@@ -1,99 +0,0 @@
1
- import {
2
- defineRoomSurface,
3
- TurnPolicy
4
- } from "@finalai/agent-provider";
5
- import { contentBlocksOf } from "./content.mjs";
6
- import { deliverMessage, membershipNotice, reactionNotice } from "./delivery.mjs";
7
- import {
8
- conversationEventInboundSchema,
9
- ConversationEventKind,
10
- messageInboundSchema
11
- } from "./inbound.mjs";
12
- import { createProjector } from "./projection.mjs";
13
- import { routeMessage } from "./routing.mjs";
14
- const receiveConversationEvent = async (event, ctx) => {
15
- const participants = await ctx.platform.conversations.participants(event.conversationId);
16
- if (event.event === ConversationEventKind.Membership) {
17
- const subject = participants.find((participant) => participant.id === event.participantId);
18
- if (subject != null) {
19
- await membershipNotice({
20
- platform: ctx.platform,
21
- participants: participants.filter(
22
- (participant) => !participant.left && (participant.kind !== "agent" || ctx.agentParticipantId == null || participant.id === ctx.agentParticipantId)
23
- ),
24
- subject,
25
- change: event.change,
26
- idempotencyKey: `membership:${event.participantId}:${event.eventId}`
27
- });
28
- }
29
- return { conversationId: event.conversationId };
30
- }
31
- const [message] = (await ctx.platform.conversations.recentMessages({
32
- conversationId: event.conversationId,
33
- beforeSeq: event.messageSeq + 1,
34
- limit: 1
35
- })).filter((candidate) => candidate.messageId === event.messageId);
36
- if (message != null && (ctx.agentParticipantId == null || message.authorParticipantId === ctx.agentParticipantId)) {
37
- await reactionNotice({
38
- platform: ctx.platform,
39
- participants,
40
- message,
41
- isLatestOfAuthor: event.latestOfAuthor,
42
- reactorParticipantId: event.reactorParticipantId,
43
- emoji: event.emoji,
44
- eventId: event.eventId
45
- });
46
- }
47
- return { conversationId: event.conversationId };
48
- };
49
- const createConversationReceive = (turnPolicy, route = routeMessage) => async (input, ctx) => {
50
- const event = conversationEventInboundSchema.safeParse(input);
51
- if (event.success) {
52
- return receiveConversationEvent(event.data, ctx);
53
- }
54
- const inbound = messageInboundSchema.parse(input);
55
- const conversation = ctx.conversation ?? await ctx.platform.conversations.get(inbound.conversationId);
56
- if (conversation == null) {
57
- throw new Error(`conversation ${inbound.conversationId} not found`);
58
- }
59
- const message = ctx.message ?? await ctx.platform.conversations.postMessage({
60
- conversationId: inbound.conversationId,
61
- authorParticipantId: inbound.authorParticipantId,
62
- kind: inbound.kind,
63
- content: contentBlocksOf(inbound.content),
64
- clientMessageId: inbound.clientMessageId ?? null,
65
- replyToMessageId: inbound.replyToMessageId ?? null,
66
- threadRootId: inbound.threadRootId ?? null,
67
- quotedMessageIds: inbound.quotedMessageIds,
68
- mentionedParticipantIds: inbound.mentionedParticipantIds
69
- });
70
- await deliverMessage({
71
- platform: ctx.platform,
72
- route: async (args) => {
73
- const requested = ctx.requestedDelivery != null && ctx.agentParticipantId != null && route === routeMessage ? [{ participantId: ctx.agentParticipantId, delivery: ctx.requestedDelivery }] : await route({ ...args, agentParticipantId: ctx.agentParticipantId });
74
- return requested.filter(
75
- (decision) => ctx.agentParticipantId == null || decision.participantId === ctx.agentParticipantId
76
- );
77
- },
78
- conversation,
79
- message,
80
- participants: ctx.participants == null ? void 0 : [...ctx.participants],
81
- turnPolicy
82
- });
83
- return { conversationId: conversation.conversationId };
84
- };
85
- const createMessagingChannel = (config = {}) => {
86
- const turnPolicy = config.turnPolicy ?? TurnPolicy.Steer;
87
- const projector = createProjector({ ...config, turnPolicy });
88
- return defineRoomSurface({
89
- receive: createConversationReceive(turnPolicy, config.route),
90
- route: config.route ?? routeMessage,
91
- turnPolicy,
92
- project: projector.project
93
- });
94
- };
95
- export {
96
- createConversationReceive,
97
- createMessagingChannel
98
- };
99
- //# sourceMappingURL=messaging-channel.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/channels/messaging-channel.ts"],
4
- "sourcesContent": ["import {\n defineRoomSurface,\n TurnPolicy,\n type RoomSurfaceDefinitionIface,\n type RoomReceiveContextIface,\n type ConversationRefIface,\n type JsonValue,\n type RouteArgsIface,\n type RouteDecisionIface,\n} from '@finalai/agent-provider';\nimport { contentBlocksOf } from \"./content.mjs\";\nimport { deliverMessage, membershipNotice, reactionNotice } from \"./delivery.mjs\";\nimport {\n conversationEventInboundSchema,\n ConversationEventKind,\n messageInboundSchema,\n type ConversationEventInboundIface,\n} from \"./inbound.mjs\";\nimport { createProjector, type ProjectorConfigIface } from \"./projection.mjs\";\nimport { routeMessage } from \"./routing.mjs\";\n\n// `turnPolicy` (ProjectorConfigIface): steer unless configured; a conversation\n// set to queue overrides it.\nexport interface MessagingChannelConfigIface extends ProjectorConfigIface {\n route?: (args: RouteArgsIface) => RouteDecisionIface[] | Promise<RouteDecisionIface[]>;\n}\n\nconst receiveConversationEvent = async (\n event: ConversationEventInboundIface,\n ctx: RoomReceiveContextIface,\n): Promise<ConversationRefIface> => {\n const participants = await ctx.platform.conversations.participants(event.conversationId);\n if (event.event === ConversationEventKind.Membership) {\n const subject = participants.find((participant) => participant.id === event.participantId);\n if (subject != null) {\n await membershipNotice({\n platform: ctx.platform,\n participants: participants.filter(\n (participant) =>\n !participant.left &&\n (participant.kind !== 'agent' ||\n ctx.agentParticipantId == null ||\n participant.id === ctx.agentParticipantId),\n ),\n subject,\n change: event.change,\n idempotencyKey: `membership:${event.participantId}:${event.eventId}`,\n });\n }\n return { conversationId: event.conversationId };\n }\n const [message] = (\n await ctx.platform.conversations.recentMessages({\n conversationId: event.conversationId,\n beforeSeq: event.messageSeq + 1,\n limit: 1,\n })\n ).filter((candidate) => candidate.messageId === event.messageId);\n if (\n message != null &&\n (ctx.agentParticipantId == null || message.authorParticipantId === ctx.agentParticipantId)\n ) {\n await reactionNotice({\n platform: ctx.platform,\n participants,\n message,\n isLatestOfAuthor: event.latestOfAuthor,\n reactorParticipantId: event.reactorParticipantId,\n emoji: event.emoji,\n eventId: event.eventId,\n });\n }\n return { conversationId: event.conversationId };\n};\n\n// Persists the message before routing and delivering it to sessions,\n// using the channel's turnPolicy.\nexport const createConversationReceive =\n (\n turnPolicy: TurnPolicy,\n route: NonNullable<MessagingChannelConfigIface['route']> = routeMessage,\n ) =>\n async (input: JsonValue, ctx: RoomReceiveContextIface): Promise<ConversationRefIface> => {\n const event = conversationEventInboundSchema.safeParse(input);\n if (event.success) {\n return receiveConversationEvent(event.data, ctx);\n }\n const inbound = messageInboundSchema.parse(input);\n const conversation =\n ctx.conversation ?? (await ctx.platform.conversations.get(inbound.conversationId));\n if (conversation == null) {\n throw new Error(`conversation ${inbound.conversationId} not found`);\n }\n const message =\n ctx.message ??\n (await ctx.platform.conversations.postMessage({\n conversationId: inbound.conversationId,\n authorParticipantId: inbound.authorParticipantId,\n kind: inbound.kind,\n content: contentBlocksOf(inbound.content),\n clientMessageId: inbound.clientMessageId ?? null,\n replyToMessageId: inbound.replyToMessageId ?? null,\n threadRootId: inbound.threadRootId ?? null,\n quotedMessageIds: inbound.quotedMessageIds,\n mentionedParticipantIds: inbound.mentionedParticipantIds,\n }));\n await deliverMessage({\n platform: ctx.platform,\n route: async (args) => {\n const requested =\n ctx.requestedDelivery != null && ctx.agentParticipantId != null && route === routeMessage\n ? [{ participantId: ctx.agentParticipantId, delivery: ctx.requestedDelivery }]\n : await route({ ...args, agentParticipantId: ctx.agentParticipantId });\n return requested.filter(\n (decision) =>\n ctx.agentParticipantId == null || decision.participantId === ctx.agentParticipantId,\n );\n },\n conversation,\n message,\n participants: ctx.participants == null ? undefined : [...ctx.participants],\n turnPolicy,\n });\n return { conversationId: conversation.conversationId };\n };\n\n// The shared body of direct-messaging and group-messaging: one routing table\n// and one projection; the conversation kind selects the rules.\nexport const createMessagingChannel = (\n config: MessagingChannelConfigIface = {},\n): RoomSurfaceDefinitionIface<JsonValue, JsonValue> => {\n const turnPolicy = config.turnPolicy ?? TurnPolicy.Steer;\n const projector = createProjector({ ...config, turnPolicy });\n return defineRoomSurface<JsonValue, JsonValue>({\n receive: createConversationReceive(turnPolicy, config.route),\n route: config.route ?? routeMessage,\n turnPolicy,\n project: projector.project,\n });\n};\n"],
5
- "mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAOK;AACP,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,kBAAkB,sBAAsB;AACjE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,uBAAkD;AAC3D,SAAS,oBAAoB;AAQ7B,MAAM,2BAA2B,OAC/B,OACA,QACkC;AAClC,QAAM,eAAe,MAAM,IAAI,SAAS,cAAc,aAAa,MAAM,cAAc;AACvF,MAAI,MAAM,UAAU,sBAAsB,YAAY;AACpD,UAAM,UAAU,aAAa,KAAK,CAAC,gBAAgB,YAAY,OAAO,MAAM,aAAa;AACzF,QAAI,WAAW,MAAM;AACnB,YAAM,iBAAiB;AAAA,QACrB,UAAU,IAAI;AAAA,QACd,cAAc,aAAa;AAAA,UACzB,CAAC,gBACC,CAAC,YAAY,SACZ,YAAY,SAAS,WACpB,IAAI,sBAAsB,QAC1B,YAAY,OAAO,IAAI;AAAA,QAC7B;AAAA,QACA;AAAA,QACA,QA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B,QAAQ,mBAAmB;AAAA,IAC5C,kBAAkB,QAAQ,oBAAoB;AAAA,IAC9C,cAAc,QAAQ,gBAAgB;AAAA,IACtC,kBAAkB,QAAQ;AAAA,IAC1B,yBAAyB,QAAQ;AAAA,EACnC,CAAC;AACH,QAAM,eAAe;AAAA,IACnB,UAAU,IAAI;AAAA,IACd,OAAO,OAAO,SAAS;AACrB,YAAM,YACJ,IAAI,qBAAqB,QAAQ,IAAI,sBAAsB,QAAQ,UAAU,eACzE,CAAC,EAAE,eAAe,IAAI,oBAAoB,UAAU,IAAI,kBAAkB,CAAC,IAC3E,MAAM,MAAM,EAAE,GAAG,MAAM,oBAAoB,IAAI,mBAAmB,CAAC;AACzE,aAAO,UAAU;AAAA,QACf,CAAC,aACC,IAAI,sBAAsB,QAAQ,SAAS,kBAAkB,IAAI;AAAA,MACrE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,IAAI,gBAAgB,OAAO,SAAY,CAAC,GAAG,IAAI,YAAY;AAAA,IACzE;AAAA,EACF,CAAC;AACD,SAAO,EAAE,gBAAgB,aAAa,eAAe;AACvD;AAIK,MAAM,yBAAyB,CACpC,SAAsC,CAAC,MACc;AACrD,QAAM,aAAa,OAAO,cAAc,WAAW;AACnD,QAAM,YAAY,gBAAgB,EAAE,GAAG,QAAQ,WAAW,CAAC;AAC3D,SAAO,kBAAwC;AAAA,IAC7C,SAAS,0BAA0B,YAAY,OAAO,KAAK;AAAA,IAC3D,OAAO,OAAO,SAAS;AAAA,IACvB;AAAA,IACA,SAAS,UAAU;AAAA,EACrB,CAAC;AACH;",
6
- "names": []
7
- }
@@ -1,36 +0,0 @@
1
- import type { ContentBlock, SessionUpdate } from '@agentclientprotocol/sdk/experimental/v2';
2
- import { TurnPolicy, type JsonValue, type ProjectionContextIface } from '@finalai/agent-provider';
3
- import * as z from 'zod';
4
- export declare const DEFAULT_PROJECTION_UPDATE_INTERVAL_MS = 300;
5
- export declare const projectionStateSchema: z.ZodObject<{
6
- messageId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
7
- messageSeq: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
8
- fromSeq: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
9
- lastSeq: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
10
- lastFlushAt: z.ZodDefault<z.ZodNumber>;
11
- dirty: z.ZodDefault<z.ZodBoolean>;
12
- segments: z.ZodArray<z.ZodObject<{
13
- messageId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
14
- messageSeq: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
15
- fromSeq: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
16
- lastSeq: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
17
- lastFlushAt: z.ZodDefault<z.ZodNumber>;
18
- dirty: z.ZodDefault<z.ZodBoolean>;
19
- acpMessageId: z.ZodString;
20
- blocks: z.ZodArray<z.ZodType<import("@finalai/agent-provider").JsonObject, unknown, z.core.$ZodTypeInternals<import("@finalai/agent-provider").JsonObject, unknown>>>;
21
- }, z.core.$strip>>;
22
- }, z.core.$strip>;
23
- export type ProjectionStateIface = z.infer<typeof projectionStateSchema>;
24
- export interface ProjectorConfigIface {
25
- updateIntervalMs?: number;
26
- now?: () => number;
27
- turnPolicy?: TurnPolicy;
28
- }
29
- export declare const emptyProjectionState: () => ProjectionStateIface;
30
- export declare const projectionStateOf: (state: JsonValue | null) => ProjectionStateIface;
31
- export declare const visibleContent: (state: Pick<ProjectionStateIface, "segments">) => ContentBlock[];
32
- export declare const accumulateUpdate: (state: ProjectionStateIface, update: SessionUpdate) => ProjectionStateIface["segments"][number] | null;
33
- export interface ProjectorIface {
34
- project(update: SessionUpdate, ctx: ProjectionContextIface): Promise<void>;
35
- }
36
- export declare const createProjector: (config?: ProjectorConfigIface) => ProjectorIface;