@finalai/agents 0.4.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HOSTING.md +3 -3
- package/dist/modules/agent-client/build.d.mts +11 -1
- package/dist/modules/agent-client/build.mjs +1 -1
- package/dist/modules/agent-client/build.mjs.map +2 -2
- package/dist/modules/agent-client/client.d.mts +10 -22
- package/dist/modules/agent-client/client.mjs +10 -40
- package/dist/modules/agent-client/client.mjs.map +2 -2
- package/dist/modules/agent-client/collection-events.d.mts +1 -1
- package/dist/modules/agent-client/collection-events.mjs.map +1 -1
- package/dist/modules/agent-client/context.d.mts +1 -2
- package/dist/modules/agent-client/context.mjs +0 -1
- package/dist/modules/agent-client/context.mjs.map +2 -2
- package/dist/modules/agent-client/conversations.d.mts +35 -10
- package/dist/modules/agent-client/conversations.mjs +46 -42
- package/dist/modules/agent-client/conversations.mjs.map +2 -2
- package/dist/modules/agent-client/errors.d.mts +14 -14
- package/dist/modules/agent-client/errors.mjs +15 -15
- package/dist/modules/agent-client/errors.mjs.map +3 -3
- package/dist/modules/agent-client/frame-stream.d.mts +8 -8
- package/dist/modules/agent-client/frame-stream.mjs +36 -36
- package/dist/modules/agent-client/frame-stream.mjs.map +2 -2
- package/dist/modules/agent-client/http.d.mts +2 -2
- package/dist/modules/agent-client/http.mjs +10 -10
- package/dist/modules/agent-client/http.mjs.map +2 -2
- package/dist/modules/agent-client/index.d.mts +2 -2
- package/dist/modules/agent-client/index.mjs +6 -6
- package/dist/modules/agent-client/index.mjs.map +2 -2
- package/dist/modules/agent-client/sessions.d.mts +9 -8
- package/dist/modules/agent-client/sessions.mjs +13 -13
- package/dist/modules/agent-client/sessions.mjs.map +2 -2
- package/dist/modules/cli/cli.mjs +2 -2
- package/dist/modules/cli/cli.mjs.map +2 -2
- package/examples/release-scout/README.md +1 -1
- package/examples/release-scout/client.ts +2 -2
- package/package.json +5 -5
|
@@ -27,6 +27,8 @@ import {
|
|
|
27
27
|
createConversationRequestSchema,
|
|
28
28
|
createConversationScheduleRequestSchema,
|
|
29
29
|
createDirectConversationRequestSchema,
|
|
30
|
+
DecisionEventState,
|
|
31
|
+
decisionRecordListSchema,
|
|
30
32
|
decisionsPageSchema,
|
|
31
33
|
markReadRequestSchema,
|
|
32
34
|
messageDeliveriesSchema,
|
|
@@ -38,8 +40,6 @@ import {
|
|
|
38
40
|
ParticipantKind,
|
|
39
41
|
participantListSchema,
|
|
40
42
|
participantSchema,
|
|
41
|
-
PendingEventState,
|
|
42
|
-
pendingRequestListSchema,
|
|
43
43
|
postConversationEventRequestSchema,
|
|
44
44
|
postConversationEventResponseSchema,
|
|
45
45
|
pushDeliveryOpenResponseSchema,
|
|
@@ -47,8 +47,8 @@ import {
|
|
|
47
47
|
reactionsResponseSchema,
|
|
48
48
|
readStateSchema,
|
|
49
49
|
removeParticipantRequestSchema,
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
respondDecisionResponseSchema,
|
|
51
|
+
respondDecisionSchema,
|
|
52
52
|
sandboxDirectorySchema,
|
|
53
53
|
sandboxEditorAuthorizationSchema,
|
|
54
54
|
sandboxEditorSessionSchema,
|
|
@@ -90,7 +90,7 @@ const TURN_OPEN_SESSION_STATES = /* @__PURE__ */ new Set([
|
|
|
90
90
|
const conversationPath = (conversationId, suffix = "") => `/v1/conversations/${encodePath(conversationId)}${suffix}`;
|
|
91
91
|
const messagePath = (conversationId, messageId, suffix = "") => conversationPath(conversationId, `/messages/${encodePath(messageId)}${suffix}`);
|
|
92
92
|
const MAX_REMEMBERED = 4096;
|
|
93
|
-
const
|
|
93
|
+
const SESSION_DECISIONS_LIMIT = 200;
|
|
94
94
|
const remember = (map, key, value) => {
|
|
95
95
|
map.delete(key);
|
|
96
96
|
map.set(key, value);
|
|
@@ -99,7 +99,7 @@ const remember = (map, key, value) => {
|
|
|
99
99
|
if (oldest.done !== true) map.delete(oldest.value);
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
|
-
const isTransientEvent = (event) => event.kind === AgentRealtimeKind.
|
|
102
|
+
const isTransientEvent = (event) => event.kind === AgentRealtimeKind.DecisionChanged || event.kind === AgentRealtimeKind.TurnStarted || event.kind === AgentRealtimeKind.TurnEnded;
|
|
103
103
|
const REPLAY_PAGE = 100;
|
|
104
104
|
const RECOVERY_SKEW_MS = 3e4;
|
|
105
105
|
const stampOf = (message) => Math.max(
|
|
@@ -158,7 +158,7 @@ const streamConversationEvents = (args) => {
|
|
|
158
158
|
const held = [];
|
|
159
159
|
const recoverTransientState = args.options?.recoverTransient ?? true;
|
|
160
160
|
let transientClock = 0;
|
|
161
|
-
const
|
|
161
|
+
const decisionsSeen = /* @__PURE__ */ new Map();
|
|
162
162
|
const runningTurns = /* @__PURE__ */ new Map();
|
|
163
163
|
const endedTurns = /* @__PURE__ */ new Map();
|
|
164
164
|
let degraded = false;
|
|
@@ -202,24 +202,25 @@ const streamConversationEvents = (args) => {
|
|
|
202
202
|
previous == null ? { kind: AgentRealtimeKind.MessageCreated, message, ...meta } : { kind: AgentRealtimeKind.MessageUpdated, message, ...meta }
|
|
203
203
|
);
|
|
204
204
|
};
|
|
205
|
-
const
|
|
206
|
-
const seen =
|
|
207
|
-
if (state ===
|
|
208
|
-
if (seen?.state ===
|
|
205
|
+
const noteDecision = (decision, state) => {
|
|
206
|
+
const seen = decisionsSeen.get(decision.id);
|
|
207
|
+
if (state === DecisionEventState.Resolved) {
|
|
208
|
+
if (seen?.state === DecisionEventState.Resolved) return false;
|
|
209
209
|
transientClock += 1;
|
|
210
|
-
remember(
|
|
210
|
+
remember(decisionsSeen, decision.id, { state, decision, noted: transientClock });
|
|
211
211
|
return true;
|
|
212
212
|
}
|
|
213
|
-
if (state ===
|
|
213
|
+
if (state === DecisionEventState.Created) {
|
|
214
214
|
if (seen != null) return false;
|
|
215
215
|
transientClock += 1;
|
|
216
|
-
remember(
|
|
216
|
+
remember(decisionsSeen, decision.id, { state, decision, noted: transientClock });
|
|
217
217
|
return true;
|
|
218
218
|
}
|
|
219
219
|
return true;
|
|
220
220
|
};
|
|
221
221
|
const noteTransient = (event) => {
|
|
222
|
-
if (event.kind === AgentRealtimeKind.
|
|
222
|
+
if (event.kind === AgentRealtimeKind.DecisionChanged)
|
|
223
|
+
return noteDecision(event.decision, event.state);
|
|
223
224
|
if (event.kind === AgentRealtimeKind.TurnStarted) {
|
|
224
225
|
if (!endedTurns.has(event.turnId)) {
|
|
225
226
|
transientClock += 1;
|
|
@@ -353,8 +354,8 @@ const streamConversationEvents = (args) => {
|
|
|
353
354
|
)
|
|
354
355
|
);
|
|
355
356
|
const remembered = /* @__PURE__ */ new Set([
|
|
356
|
-
...[...
|
|
357
|
-
(seen) => seen.state ===
|
|
357
|
+
...[...decisionsSeen.values()].flatMap(
|
|
358
|
+
(seen) => seen.state === DecisionEventState.Created && seen.decision.sessionId != null ? [seen.decision.sessionId] : []
|
|
358
359
|
),
|
|
359
360
|
...[...runningTurns.values()].map((entry) => entry.turn.sessionId)
|
|
360
361
|
]);
|
|
@@ -362,7 +363,7 @@ const streamConversationEvents = (args) => {
|
|
|
362
363
|
[.../* @__PURE__ */ new Set([...current ?? [], ...remembered])].map(async (sessionId) => {
|
|
363
364
|
const [session, open] = await Promise.all([
|
|
364
365
|
optional(() => args.getSession(sessionId, { signal })),
|
|
365
|
-
optional(() => args.
|
|
366
|
+
optional(() => args.sessionDecisions(sessionId, { signal }))
|
|
366
367
|
]);
|
|
367
368
|
const departed = current != null && !current.has(sessionId);
|
|
368
369
|
return {
|
|
@@ -374,24 +375,24 @@ const streamConversationEvents = (args) => {
|
|
|
374
375
|
);
|
|
375
376
|
for (const { sessionId, running, open } of checked) {
|
|
376
377
|
if (open != null) {
|
|
377
|
-
const complete = open.length <
|
|
378
|
-
const openIds = new Set(open.map((
|
|
379
|
-
for (const
|
|
380
|
-
if (
|
|
378
|
+
const complete = open.length < SESSION_DECISIONS_LIMIT;
|
|
379
|
+
const openIds = new Set(open.map((decision) => decision.id));
|
|
380
|
+
for (const decision of open) {
|
|
381
|
+
if (noteDecision(decision, DecisionEventState.Created))
|
|
381
382
|
emitRecovered({
|
|
382
|
-
kind: AgentRealtimeKind.
|
|
383
|
-
|
|
384
|
-
state:
|
|
383
|
+
kind: AgentRealtimeKind.DecisionChanged,
|
|
384
|
+
decision,
|
|
385
|
+
state: DecisionEventState.Created
|
|
385
386
|
});
|
|
386
387
|
}
|
|
387
|
-
for (const seen of [...
|
|
388
|
-
if (!complete || seen.state !==
|
|
388
|
+
for (const seen of [...decisionsSeen.values()]) {
|
|
389
|
+
if (!complete || seen.state !== DecisionEventState.Created || seen.noted > asOf || seen.decision.sessionId !== sessionId || openIds.has(seen.decision.id))
|
|
389
390
|
continue;
|
|
390
|
-
|
|
391
|
+
noteDecision(seen.decision, DecisionEventState.Resolved);
|
|
391
392
|
emitRecovered({
|
|
392
|
-
kind: AgentRealtimeKind.
|
|
393
|
-
|
|
394
|
-
state:
|
|
393
|
+
kind: AgentRealtimeKind.DecisionChanged,
|
|
394
|
+
decision: seen.decision,
|
|
395
|
+
state: DecisionEventState.Resolved
|
|
395
396
|
});
|
|
396
397
|
}
|
|
397
398
|
}
|
|
@@ -623,12 +624,12 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
623
624
|
response: sessionSchema,
|
|
624
625
|
signal: options.signal
|
|
625
626
|
});
|
|
626
|
-
const
|
|
627
|
+
const sessionDecisions = async (sessionId, options) => (await http.request({
|
|
627
628
|
method: HttpMethod.Get,
|
|
628
|
-
path: `/v1/sessions/${encodePath(sessionId)}/
|
|
629
|
-
response:
|
|
629
|
+
path: `/v1/sessions/${encodePath(sessionId)}/decisions`,
|
|
630
|
+
response: decisionRecordListSchema,
|
|
630
631
|
signal: options.signal
|
|
631
|
-
})).
|
|
632
|
+
})).decisions;
|
|
632
633
|
const reaction = async (args) => (await http.request({
|
|
633
634
|
method: args.method,
|
|
634
635
|
path: messagePath(conversationId, args.messageId, "/reactions"),
|
|
@@ -678,7 +679,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
678
679
|
listMessages,
|
|
679
680
|
listParticipants,
|
|
680
681
|
getSession,
|
|
681
|
-
|
|
682
|
+
sessionDecisions
|
|
682
683
|
}),
|
|
683
684
|
messages: (options) => listMessages(options),
|
|
684
685
|
deliveries: async (args, options) => (await http.request({
|
|
@@ -740,12 +741,12 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
740
741
|
method: HttpMethod.Post,
|
|
741
742
|
path: conversationPath(conversationId, "/respond"),
|
|
742
743
|
body: {
|
|
743
|
-
schema:
|
|
744
|
-
value: {
|
|
744
|
+
schema: respondDecisionSchema,
|
|
745
|
+
value: { decisionId: args.decisionId, outcome: outcomeOf(args) }
|
|
745
746
|
},
|
|
746
|
-
response:
|
|
747
|
+
response: respondDecisionResponseSchema,
|
|
747
748
|
signal: options?.signal,
|
|
748
|
-
context: {
|
|
749
|
+
context: { decisionId: args.decisionId }
|
|
749
750
|
}),
|
|
750
751
|
cancel: async (options) => {
|
|
751
752
|
await http.request({
|
|
@@ -1071,7 +1072,8 @@ const createConversationsApi = (context) => {
|
|
|
1071
1072
|
query: {
|
|
1072
1073
|
cursor: options?.cursor,
|
|
1073
1074
|
limit: options?.limit,
|
|
1074
|
-
includeArchived: options?.includeArchived
|
|
1075
|
+
includeArchived: options?.includeArchived,
|
|
1076
|
+
projectId: options?.projectId
|
|
1075
1077
|
},
|
|
1076
1078
|
response: conversationListSchema,
|
|
1077
1079
|
signal: options?.signal
|
|
@@ -1089,6 +1091,7 @@ const createConversationsApi = (context) => {
|
|
|
1089
1091
|
await context.http.request({
|
|
1090
1092
|
method: HttpMethod.Get,
|
|
1091
1093
|
path: "/v1/conversations/home",
|
|
1094
|
+
query: { projectId: options?.projectId },
|
|
1092
1095
|
response: conversationSchema,
|
|
1093
1096
|
signal: options?.signal
|
|
1094
1097
|
})
|
|
@@ -1100,6 +1103,7 @@ const createConversationsApi = (context) => {
|
|
|
1100
1103
|
body: {
|
|
1101
1104
|
schema: createConversationRequestSchema,
|
|
1102
1105
|
value: {
|
|
1106
|
+
projectId: args.projectId,
|
|
1103
1107
|
kind: args.kind,
|
|
1104
1108
|
title: args.title,
|
|
1105
1109
|
participants: args.participants,
|
|
@@ -1132,7 +1136,7 @@ const createConversationsApi = (context) => {
|
|
|
1132
1136
|
decisions: (options) => context.http.request({
|
|
1133
1137
|
method: HttpMethod.Get,
|
|
1134
1138
|
path: "/v1/decisions",
|
|
1135
|
-
query: { cursor: options?.cursor, limit: options?.limit },
|
|
1139
|
+
query: { cursor: options?.cursor, limit: options?.limit, projectId: options?.projectId },
|
|
1136
1140
|
response: decisionsPageSchema,
|
|
1137
1141
|
signal: options?.signal
|
|
1138
1142
|
})
|