@finalai/final-agent-provider 0.2.2 → 0.3.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.
- package/dist/modules/channel-factories.d.mts +3 -1
- package/dist/modules/channel-factories.mjs +32 -18
- package/dist/modules/channel-factories.mjs.map +2 -2
- package/dist/modules/channels/address-context.mjs +16 -53
- package/dist/modules/channels/address-context.mjs.map +3 -3
- package/dist/modules/channels/agent-events.d.mts +3 -29
- package/dist/modules/channels/agent-events.mjs +67 -146
- package/dist/modules/channels/agent-events.mjs.map +3 -3
- package/dist/modules/channels/agent-schedules.d.mts +1 -0
- package/dist/modules/channels/agent-schedules.mjs +18 -19
- package/dist/modules/channels/agent-schedules.mjs.map +2 -2
- package/dist/modules/channels/delivery.d.mts +1 -1
- package/dist/modules/channels/delivery.mjs +5 -23
- package/dist/modules/channels/delivery.mjs.map +2 -2
- package/dist/modules/channels/fake-platform.d.mts +6 -1
- package/dist/modules/channels/fake-platform.mjs +31 -12
- package/dist/modules/channels/fake-platform.mjs.map +2 -2
- package/dist/modules/channels/index.d.mts +1 -0
- package/dist/modules/channels/index.mjs +1 -0
- package/dist/modules/channels/index.mjs.map +2 -2
- package/dist/modules/channels/prompt.d.mts +19 -2
- package/dist/modules/channels/prompt.mjs +44 -17
- package/dist/modules/channels/prompt.mjs.map +2 -2
- package/dist/modules/channels/routing.mjs +1 -15
- package/dist/modules/channels/routing.mjs.map +2 -2
- package/dist/modules/channels/service-input.d.mts +22 -0
- package/dist/modules/channels/service-input.mjs +32 -0
- package/dist/modules/channels/service-input.mjs.map +7 -0
- package/package.json +5 -5
|
@@ -2,8 +2,7 @@ import {
|
|
|
2
2
|
ConversationKind,
|
|
3
3
|
Delivery,
|
|
4
4
|
ParticipantKind,
|
|
5
|
-
RoutingMode
|
|
6
|
-
SystemParticipantKind
|
|
5
|
+
RoutingMode
|
|
7
6
|
} from "@finalai/agent-provider/channel";
|
|
8
7
|
const MAX_AGENT_HOP_DEPTH = 2;
|
|
9
8
|
const activeAgents = (participants) => participants.filter(
|
|
@@ -13,28 +12,15 @@ const effectiveDefaultAgent = (participants) => {
|
|
|
13
12
|
const agents = activeAgents(participants);
|
|
14
13
|
return agents.find((agent) => agent.routingMode === RoutingMode.Default) ?? agents.find((agent) => agent.routingMode === RoutingMode.All) ?? null;
|
|
15
14
|
};
|
|
16
|
-
const observesEverything = (participant) => participant.routingMode === RoutingMode.All || participant.routingMode === RoutingMode.Default;
|
|
17
15
|
const routeMessage = (args) => {
|
|
18
16
|
const { conversation, message, participants } = args;
|
|
19
|
-
const author = participants.find((participant) => participant.id === message.authorParticipantId) ?? null;
|
|
20
17
|
const agents = activeAgents(participants).filter(
|
|
21
18
|
(agent) => agent.id !== message.authorParticipantId && (message.agentAuthorDefinitionId == null || agent.definitionId !== message.agentAuthorDefinitionId)
|
|
22
19
|
);
|
|
23
20
|
if (agents.length === 0) {
|
|
24
21
|
return [];
|
|
25
22
|
}
|
|
26
|
-
const authorKind = author?.kind ?? ParticipantKind.User;
|
|
27
23
|
const mentioned = new Set(message.mentionedParticipantIds);
|
|
28
|
-
if (authorKind === ParticipantKind.System && author?.systemKind !== SystemParticipantKind.ApiKey && message.agentAuthorDefinitionId == null) {
|
|
29
|
-
const sourceAgent = author?.definitionId == null ? null : agents.find((agent) => agent.definitionId === author.definitionId) ?? null;
|
|
30
|
-
const target = sourceAgent ?? (conversation.kind === ConversationKind.Direct ? agents[0] ?? null : effectiveDefaultAgent(agents));
|
|
31
|
-
return agents.flatMap((agent) => {
|
|
32
|
-
if (agent.id === target?.id) {
|
|
33
|
-
return [{ participantId: agent.id, delivery: Delivery.Prompt }];
|
|
34
|
-
}
|
|
35
|
-
return observesEverything(agent) ? [{ participantId: agent.id, delivery: Delivery.Observe }] : [];
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
24
|
const mayPrompt = message.hopDepth < MAX_AGENT_HOP_DEPTH;
|
|
39
25
|
const promptDelivery = mayPrompt ? Delivery.Prompt : Delivery.Observe;
|
|
40
26
|
if (conversation.kind === ConversationKind.Direct) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/channels/routing.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ConversationKind,\n Delivery,\n ParticipantKind,\n RoutingMode,\n
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n ConversationKind,\n Delivery,\n ParticipantKind,\n RoutingMode,\n type ParticipantIface,\n type RouteArgsIface,\n type RouteDecisionIface,\n} from '@finalai/agent-provider/channel';\n\n// Agent-authored messages may prompt other agents only while the chain of\n// agent hops that produced them is shorter than this: a human\n// message (0) prompts A, A's reply (1) may prompt B, B's reply (2) prompts no one.\nexport const MAX_AGENT_HOP_DEPTH = 2;\n\nconst activeAgents = (participants: ParticipantIface[]): ParticipantIface[] =>\n participants.filter(\n (participant) => participant.kind === ParticipantKind.Agent && !participant.left,\n );\n\n// The agent a no-mention message goes to: the Default agent, else (no Default)\n// the earliest-joined All agent, which then acts as the Default. Participants\n// arrive in join order.\nexport const effectiveDefaultAgent = (\n participants: ParticipantIface[],\n): ParticipantIface | null => {\n const agents = activeAgents(participants);\n return (\n agents.find((agent) => agent.routingMode === RoutingMode.Default) ??\n agents.find((agent) => agent.routingMode === RoutingMode.All) ??\n null\n );\n};\n\n// Pure: who gets a message and how. Users never receive decisions.\nexport const routeMessage = (args: RouteArgsIface): RouteDecisionIface[] => {\n const { conversation, message, participants } = args;\n const agents = activeAgents(participants).filter(\n (agent) =>\n agent.id !== message.authorParticipantId &&\n (message.agentAuthorDefinitionId == null ||\n agent.definitionId !== message.agentAuthorDefinitionId),\n );\n if (agents.length === 0) {\n return [];\n }\n const mentioned = new Set(message.mentionedParticipantIds);\n const mayPrompt = message.hopDepth < MAX_AGENT_HOP_DEPTH;\n const promptDelivery = mayPrompt ? Delivery.Prompt : Delivery.Observe;\n\n if (conversation.kind === ConversationKind.Direct) {\n return agents.map((agent) => ({ participantId: agent.id, delivery: promptDelivery }));\n }\n\n const anyAgentMentioned = agents.some((agent) => mentioned.has(agent.id));\n const defaultAgent = effectiveDefaultAgent(participants);\n return agents.flatMap((agent): RouteDecisionIface[] => {\n if (mentioned.has(agent.id)) {\n return [{ participantId: agent.id, delivery: promptDelivery }];\n }\n if (agent.routingMode === RoutingMode.Mention || agent.routingMode == null) {\n return [];\n }\n if (!anyAgentMentioned && agent.id === defaultAgent?.id) {\n return [{ participantId: agent.id, delivery: promptDelivery }];\n }\n return [{ participantId: agent.id, delivery: Delivery.Observe }];\n });\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAKA,MAAM,sBAAsB;AAEnC,MAAM,eAAe,CAAC,iBACpB,aAAa;AAAA,EACX,CAAC,gBAAgB,YAAY,SAAS,gBAAgB,SAAS,CAAC,YAAY;AAC9E;AAKK,MAAM,wBAAwB,CACnC,iBAC4B;AAC5B,QAAM,SAAS,aAAa,YAAY;AACxC,SACE,OAAO,KAAK,CAAC,UAAU,MAAM,gBAAgB,YAAY,OAAO,KAChE,OAAO,KAAK,CAAC,UAAU,MAAM,gBAAgB,YAAY,GAAG,KAC5D;AAEJ;AAGO,MAAM,eAAe,CAAC,SAA+C;AAC1E,QAAM,EAAE,cAAc,SAAS,aAAa,IAAI;AAChD,QAAM,SAAS,aAAa,YAAY,EAAE;AAAA,IACxC,CAAC,UACC,MAAM,OAAO,QAAQ,wBACpB,QAAQ,2BAA2B,QAClC,MAAM,iBAAiB,QAAQ;AAAA,EACrC;AACA,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO,CAAC;AAAA,EACV;AACA,QAAM,YAAY,IAAI,IAAI,QAAQ,uBAAuB;AACzD,QAAM,YAAY,QAAQ,WAAW;AACrC,QAAM,iBAAiB,YAAY,SAAS,SAAS,SAAS;AAE9D,MAAI,aAAa,SAAS,iBAAiB,QAAQ;AACjD,WAAO,OAAO,IAAI,CAAC,WAAW,EAAE,eAAe,MAAM,IAAI,UAAU,eAAe,EAAE;AAAA,EACtF;AAEA,QAAM,oBAAoB,OAAO,KAAK,CAAC,UAAU,UAAU,IAAI,MAAM,EAAE,CAAC;AACxE,QAAM,eAAe,sBAAsB,YAAY;AACvD,SAAO,OAAO,QAAQ,CAAC,UAAgC;AACrD,QAAI,UAAU,IAAI,MAAM,EAAE,GAAG;AAC3B,aAAO,CAAC,EAAE,eAAe,MAAM,IAAI,UAAU,eAAe,CAAC;AAAA,IAC/D;AACA,QAAI,MAAM,gBAAgB,YAAY,WAAW,MAAM,eAAe,MAAM;AAC1E,aAAO,CAAC;AAAA,IACV;AACA,QAAI,CAAC,qBAAqB,MAAM,OAAO,cAAc,IAAI;AACvD,aAAO,CAAC,EAAE,eAAe,MAAM,IAAI,UAAU,eAAe,CAAC;AAAA,IAC/D;AACA,WAAO,CAAC,EAAE,eAAe,MAAM,IAAI,UAAU,SAAS,QAAQ,CAAC;AAAA,EACjE,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ContentBlock } from '@agentclientprotocol/sdk/experimental/v2';
|
|
2
|
+
import { ChannelPrincipalType, type ChannelAuthIface, type ChannelInputReceiptIface, type ChannelPlatformIface, type JsonObject, type TurnPolicy } from '@finalai/agent-provider';
|
|
3
|
+
export interface ServiceInputArgsIface {
|
|
4
|
+
room: string;
|
|
5
|
+
participantId?: string;
|
|
6
|
+
content: ContentBlock[];
|
|
7
|
+
principal: {
|
|
8
|
+
principalId: string;
|
|
9
|
+
principalType?: ChannelPrincipalType | `${ChannelPrincipalType}`;
|
|
10
|
+
authenticator: string;
|
|
11
|
+
attributes?: JsonObject;
|
|
12
|
+
};
|
|
13
|
+
displayName: string;
|
|
14
|
+
actingUserId?: string;
|
|
15
|
+
originTurnId?: string;
|
|
16
|
+
idempotencyKey: string;
|
|
17
|
+
label: string;
|
|
18
|
+
context?: string[];
|
|
19
|
+
turnPolicy?: TurnPolicy | `${TurnPolicy}`;
|
|
20
|
+
}
|
|
21
|
+
export declare const serviceAuthOf: (args: ServiceInputArgsIface) => ChannelAuthIface;
|
|
22
|
+
export declare const sendServiceInput: (platform: Pick<ChannelPlatformIface, "channelSessions">, args: ServiceInputArgsIface) => Promise<ChannelInputReceiptIface>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChannelPrincipalType
|
|
3
|
+
} from "@finalai/agent-provider";
|
|
4
|
+
const serviceAuthOf = (args) => ({
|
|
5
|
+
principalId: args.principal.principalId,
|
|
6
|
+
principalType: args.principal.principalType ?? ChannelPrincipalType.Service,
|
|
7
|
+
authenticator: args.principal.authenticator,
|
|
8
|
+
displayName: args.displayName,
|
|
9
|
+
attributes: args.principal.attributes ?? {}
|
|
10
|
+
});
|
|
11
|
+
const sendServiceInput = async (platform, args) => {
|
|
12
|
+
if (platform.channelSessions == null)
|
|
13
|
+
throw new Error("channel session operations are unavailable");
|
|
14
|
+
return platform.channelSessions.send(
|
|
15
|
+
{ conversationId: args.room, participantId: args.participantId },
|
|
16
|
+
{
|
|
17
|
+
content: args.content,
|
|
18
|
+
idempotencyKey: args.idempotencyKey,
|
|
19
|
+
auth: serviceAuthOf(args),
|
|
20
|
+
actingUserId: args.actingUserId,
|
|
21
|
+
originTurnId: args.originTurnId,
|
|
22
|
+
source: { label: args.label },
|
|
23
|
+
context: args.context,
|
|
24
|
+
turnPolicy: args.turnPolicy
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
sendServiceInput,
|
|
30
|
+
serviceAuthOf
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=service-input.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/channels/service-input.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ContentBlock } from '@agentclientprotocol/sdk/experimental/v2';\nimport {\n ChannelPrincipalType,\n type ChannelAuthIface,\n type ChannelInputReceiptIface,\n type ChannelPlatformIface,\n type JsonObject,\n type TurnPolicy,\n} from '@finalai/agent-provider';\n\n// Input to a Final room's agent from no member of the room: a schedule\n// firing, a webhook, a linked conversation, a sandbox result, a handoff from\n// another channel. It is channel input from a principal, never a message: the\n// platform accepts it at once and prompts the agent; the agent's reply in the\n// room carries `label` as its caption.\n\nexport interface ServiceInputArgsIface {\n // The room (conversation id).\n room: string;\n // One agent of the room; the room's Default agent when absent.\n participantId?: string;\n content: ContentBlock[];\n // Who sent it. A service principal unless a channel authenticated a person.\n principal: {\n principalId: string;\n principalType?: ChannelPrincipalType | `${ChannelPrincipalType}`;\n authenticator: string;\n attributes?: JsonObject;\n };\n // How the agent and the room name the principal.\n displayName: string;\n // The person the input acts for: who pays for the turn and answers what it asks.\n actingUserId?: string;\n // The turn whose work produced the input, for loop limits and reply provenance.\n originTurnId?: string;\n idempotencyKey: string;\n // The reply's caption (\"After the 9:00 schedule\"), written by the producer.\n label: string;\n context?: string[];\n turnPolicy?: TurnPolicy | `${TurnPolicy}`;\n}\n\nexport const serviceAuthOf = (args: ServiceInputArgsIface): ChannelAuthIface => ({\n principalId: args.principal.principalId,\n principalType: args.principal.principalType ?? ChannelPrincipalType.Service,\n authenticator: args.principal.authenticator,\n displayName: args.displayName,\n attributes: args.principal.attributes ?? {},\n});\n\nexport const sendServiceInput = async (\n platform: Pick<ChannelPlatformIface, 'channelSessions'>,\n args: ServiceInputArgsIface,\n): Promise<ChannelInputReceiptIface> => {\n if (platform.channelSessions == null)\n throw new Error('channel session operations are unavailable');\n return platform.channelSessions.send(\n { conversationId: args.room, participantId: args.participantId },\n {\n content: args.content,\n idempotencyKey: args.idempotencyKey,\n auth: serviceAuthOf(args),\n actingUserId: args.actingUserId,\n originTurnId: args.originTurnId,\n source: { label: args.label },\n context: args.context,\n turnPolicy: args.turnPolicy,\n },\n );\n};\n"],
|
|
5
|
+
"mappings": "AACA;AAAA,EACE;AAAA,OAMK;AAkCA,MAAM,gBAAgB,CAAC,UAAmD;AAAA,EAC/E,aAAa,KAAK,UAAU;AAAA,EAC5B,eAAe,KAAK,UAAU,iBAAiB,qBAAqB;AAAA,EACpE,eAAe,KAAK,UAAU;AAAA,EAC9B,aAAa,KAAK;AAAA,EAClB,YAAY,KAAK,UAAU,cAAc,CAAC;AAC5C;AAEO,MAAM,mBAAmB,OAC9B,UACA,SACsC;AACtC,MAAI,SAAS,mBAAmB;AAC9B,UAAM,IAAI,MAAM,4CAA4C;AAC9D,SAAO,SAAS,gBAAgB;AAAA,IAC9B,EAAE,gBAAgB,KAAK,MAAM,eAAe,KAAK,cAAc;AAAA,IAC/D;AAAA,MACE,SAAS,KAAK;AAAA,MACd,gBAAgB,KAAK;AAAA,MACrB,MAAM,cAAc,IAAI;AAAA,MACxB,cAAc,KAAK;AAAA,MACnB,cAAc,KAAK;AAAA,MACnB,QAAQ,EAAE,OAAO,KAAK,MAAM;AAAA,MAC5B,SAAS,KAAK;AAAA,MACd,YAAY,KAAK;AAAA,IACnB;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finalai/final-agent-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Final's provider package: serverless, remote and local harnesses; the computer and device sandboxes; the messaging, schedule and event channels.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -208,14 +208,14 @@
|
|
|
208
208
|
},
|
|
209
209
|
"dependencies": {
|
|
210
210
|
"@agentclientprotocol/sdk": "1.8.0",
|
|
211
|
-
"@finalai/acp-session": "0.1.
|
|
212
|
-
"@finalai/agent-protocol": "0.1
|
|
213
|
-
"@finalai/agent-provider": "0.
|
|
211
|
+
"@finalai/acp-session": "0.1.7",
|
|
212
|
+
"@finalai/agent-protocol": "0.2.1",
|
|
213
|
+
"@finalai/agent-provider": "0.2.2",
|
|
214
214
|
"@finalai/computers": "0.1.4",
|
|
215
215
|
"@finalai/websockets": "0.1.4",
|
|
216
216
|
"ws": "^8.21.3",
|
|
217
217
|
"zod": "4.6.5",
|
|
218
|
-
"@finalai/agent-definition": "0.1.
|
|
218
|
+
"@finalai/agent-definition": "0.1.9"
|
|
219
219
|
},
|
|
220
220
|
"engines": {
|
|
221
221
|
"node": ">=26"
|