@finalai/agents 0.8.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.
Potentially problematic release.
This version of @finalai/agents might be problematic. Click here for more details.
- package/README.md +30 -0
- package/dist/modules/agent-client/acp-frames.d.mts +19 -0
- package/dist/modules/agent-client/acp-frames.mjs +49 -0
- package/dist/modules/agent-client/acp-frames.mjs.map +7 -0
- package/dist/modules/agent-client/acp.d.mts +43 -0
- package/dist/modules/agent-client/acp.mjs +76 -0
- package/dist/modules/agent-client/acp.mjs.map +7 -0
- package/dist/modules/agent-client/async-queue.d.mts +10 -0
- package/dist/modules/agent-client/async-queue.mjs +66 -0
- package/dist/modules/agent-client/async-queue.mjs.map +7 -0
- package/dist/modules/agent-client/build.d.mts +107 -0
- package/dist/modules/agent-client/build.mjs +222 -0
- package/dist/modules/agent-client/build.mjs.map +7 -0
- package/dist/modules/agent-client/client.d.mts +111 -0
- package/dist/modules/agent-client/client.mjs +198 -0
- package/dist/modules/agent-client/client.mjs.map +7 -0
- package/dist/modules/agent-client/collection-events.d.mts +35 -0
- package/dist/modules/agent-client/collection-events.mjs +142 -0
- package/dist/modules/agent-client/collection-events.mjs.map +7 -0
- package/dist/modules/agent-client/config-options.d.mts +24 -0
- package/dist/modules/agent-client/config-options.mjs +49 -0
- package/dist/modules/agent-client/config-options.mjs.map +7 -0
- package/dist/modules/agent-client/context.d.mts +31 -0
- package/dist/modules/agent-client/context.mjs +11 -0
- package/dist/modules/agent-client/context.mjs.map +7 -0
- package/dist/modules/agent-client/conversations.d.mts +385 -0
- package/dist/modules/agent-client/conversations.mjs +1156 -0
- package/dist/modules/agent-client/conversations.mjs.map +7 -0
- package/dist/modules/agent-client/errors.d.mts +85 -0
- package/dist/modules/agent-client/errors.mjs +94 -0
- package/dist/modules/agent-client/errors.mjs.map +7 -0
- package/dist/modules/agent-client/event-stream.d.mts +14 -0
- package/dist/modules/agent-client/event-stream.mjs +89 -0
- package/dist/modules/agent-client/event-stream.mjs.map +7 -0
- package/dist/modules/agent-client/frame-stream.d.mts +51 -0
- package/dist/modules/agent-client/frame-stream.mjs +333 -0
- package/dist/modules/agent-client/frame-stream.mjs.map +7 -0
- package/dist/modules/agent-client/http.d.mts +68 -0
- package/dist/modules/agent-client/http.mjs +168 -0
- package/dist/modules/agent-client/http.mjs.map +7 -0
- package/dist/modules/agent-client/index.d.mts +17 -0
- package/dist/modules/agent-client/index.mjs +86 -0
- package/dist/modules/agent-client/index.mjs.map +7 -0
- package/dist/modules/agent-client/live-stream.d.mts +18 -0
- package/dist/modules/agent-client/live-stream.mjs +94 -0
- package/dist/modules/agent-client/live-stream.mjs.map +7 -0
- package/dist/modules/agent-client/realtime.d.mts +72 -0
- package/dist/modules/agent-client/realtime.mjs +186 -0
- package/dist/modules/agent-client/realtime.mjs.map +7 -0
- package/dist/modules/agent-client/sandbox-uri.d.mts +19 -0
- package/dist/modules/agent-client/sandbox-uri.mjs +43 -0
- package/dist/modules/agent-client/sandbox-uri.mjs.map +7 -0
- package/dist/modules/agent-client/sessions.d.mts +124 -0
- package/dist/modules/agent-client/sessions.mjs +350 -0
- package/dist/modules/agent-client/sessions.mjs.map +7 -0
- package/dist/modules/agent-client/test-fakes.d.mts +40 -0
- package/dist/modules/agent-client/test-fakes.mjs +94 -0
- package/dist/modules/agent-client/test-fakes.mjs.map +7 -0
- package/dist/modules/authoring/approval.d.mts +1 -0
- package/dist/modules/authoring/approval.mjs +2 -0
- package/dist/modules/authoring/approval.mjs.map +7 -0
- package/dist/modules/authoring/channels.d.mts +1 -0
- package/dist/modules/authoring/channels.mjs +2 -0
- package/dist/modules/authoring/channels.mjs.map +7 -0
- package/dist/modules/authoring/final-channel.d.mts +1 -0
- package/dist/modules/authoring/final-channel.mjs +2 -0
- package/dist/modules/authoring/final-channel.mjs.map +7 -0
- package/dist/modules/authoring/hooks.d.mts +1 -0
- package/dist/modules/authoring/hooks.mjs +2 -0
- package/dist/modules/authoring/hooks.mjs.map +7 -0
- package/dist/modules/authoring/index.d.mts +1 -0
- package/dist/modules/authoring/index.mjs +2 -0
- package/dist/modules/authoring/index.mjs.map +7 -0
- package/dist/modules/authoring/instructions.d.mts +1 -0
- package/dist/modules/authoring/instructions.mjs +2 -0
- package/dist/modules/authoring/instructions.mjs.map +7 -0
- package/dist/modules/authoring/providers.d.mts +2 -0
- package/dist/modules/authoring/providers.mjs +1 -0
- package/dist/modules/authoring/providers.mjs.map +7 -0
- package/dist/modules/authoring/tools.d.mts +1 -0
- package/dist/modules/authoring/tools.mjs +2 -0
- package/dist/modules/authoring/tools.mjs.map +7 -0
- package/dist/modules/cli/build.d.mts +22 -0
- package/dist/modules/cli/build.mjs +77 -0
- package/dist/modules/cli/build.mjs.map +7 -0
- package/dist/modules/cli/channel-socket.d.mts +9 -0
- package/dist/modules/cli/channel-socket.mjs +114 -0
- package/dist/modules/cli/channel-socket.mjs.map +7 -0
- package/dist/modules/cli/cli.d.mts +16 -0
- package/dist/modules/cli/cli.mjs +151 -0
- package/dist/modules/cli/cli.mjs.map +7 -0
- package/dist/modules/cli/conformance.d.mts +36 -0
- package/dist/modules/cli/conformance.mjs +220 -0
- package/dist/modules/cli/conformance.mjs.map +7 -0
- package/dist/modules/cli/dev.d.mts +24 -0
- package/dist/modules/cli/dev.mjs +263 -0
- package/dist/modules/cli/dev.mjs.map +7 -0
- package/dist/modules/cli/files.d.mts +18 -0
- package/dist/modules/cli/files.mjs +66 -0
- package/dist/modules/cli/files.mjs.map +7 -0
- package/dist/modules/cli/harness-descriptions.d.mts +20 -0
- package/dist/modules/cli/harness-descriptions.mjs +70 -0
- package/dist/modules/cli/harness-descriptions.mjs.map +7 -0
- package/dist/modules/cli/main.d.mts +2 -0
- package/dist/modules/cli/main.mjs +20 -0
- package/dist/modules/cli/main.mjs.map +7 -0
- package/dist/modules/cli/output.d.mts +14 -0
- package/dist/modules/cli/output.mjs +94 -0
- package/dist/modules/cli/output.mjs.map +7 -0
- package/dist/modules/cli/publish.d.mts +14 -0
- package/dist/modules/cli/publish.mjs +89 -0
- package/dist/modules/cli/publish.mjs.map +7 -0
- package/dist/modules/compile.d.mts +3 -0
- package/dist/modules/compile.mjs +62 -0
- package/dist/modules/compile.mjs.map +7 -0
- package/dist/modules/harnesses.d.mts +1 -0
- package/dist/modules/harnesses.mjs +2 -0
- package/dist/modules/harnesses.mjs.map +7 -0
- package/dist/modules/index.browser.d.mts +4 -0
- package/dist/modules/index.browser.mjs +8 -0
- package/dist/modules/index.browser.mjs.map +7 -0
- package/dist/modules/index.d.mts +3 -0
- package/dist/modules/index.mjs +6 -0
- package/dist/modules/index.mjs.map +7 -0
- package/dist/modules/models.d.mts +1 -0
- package/dist/modules/models.mjs +2 -0
- package/dist/modules/models.mjs.map +7 -0
- package/dist/modules/public.d.mts +6 -0
- package/dist/modules/public.mjs +68 -0
- package/dist/modules/public.mjs.map +7 -0
- package/dist/modules/sandboxes.d.mts +1 -0
- package/dist/modules/sandboxes.mjs +2 -0
- package/dist/modules/sandboxes.mjs.map +7 -0
- package/examples/custom-harness/README.md +16 -0
- package/examples/custom-harness/agent.ts +154 -0
- package/examples/custom-sandbox/README.md +12 -0
- package/examples/custom-sandbox/agent.ts +14 -0
- package/examples/custom-sandbox/sandbox.ts +22 -0
- package/examples/release-scout/README.md +11 -0
- package/examples/release-scout/agent/agent.ts +22 -0
- package/examples/release-scout/agent/channels/github-signature.ts +27 -0
- package/examples/release-scout/agent/channels/github.ts +38 -0
- package/examples/release-scout/agent/connections/linear.ts +9 -0
- package/examples/release-scout/agent/hooks/audit.ts +24 -0
- package/examples/release-scout/agent/instructions/org-context.ts +26 -0
- package/examples/release-scout/agent/instructions.md +2 -0
- package/examples/release-scout/agent/sandbox.ts +20 -0
- package/examples/release-scout/agent/schedules/daily-digest.md +7 -0
- package/examples/release-scout/agent/skills/triage/SKILL.md +8 -0
- package/examples/release-scout/agent/skills/triage/checklist.md +3 -0
- package/examples/release-scout/agent/tools/lookup_release_notes.ts +24 -0
- package/examples/release-scout/client.ts +123 -0
- package/package.json +126 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
agentRealtimeFrameSchema,
|
|
3
|
+
AgentRealtimeFrameType,
|
|
4
|
+
parseAgentRealtimeEvent
|
|
5
|
+
} from "@finalai/agent-protocol/agent-platform";
|
|
6
|
+
import { createAsyncQueue, failOnAbort } from "./async-queue.mjs";
|
|
7
|
+
import {
|
|
8
|
+
isRetryableClientError,
|
|
9
|
+
isTerminalRealtimeError,
|
|
10
|
+
realtimeSubscriptionError
|
|
11
|
+
} from "./errors.mjs";
|
|
12
|
+
var CollectionEventKind = /* @__PURE__ */ ((CollectionEventKind2) => {
|
|
13
|
+
CollectionEventKind2["Resync"] = "collection.resync";
|
|
14
|
+
return CollectionEventKind2;
|
|
15
|
+
})(CollectionEventKind || {});
|
|
16
|
+
var CollectionResyncReason = /* @__PURE__ */ ((CollectionResyncReason2) => {
|
|
17
|
+
CollectionResyncReason2["Subscribed"] = "subscribed";
|
|
18
|
+
CollectionResyncReason2["ResyncRequired"] = "resync_required";
|
|
19
|
+
CollectionResyncReason2["Degraded"] = "degraded";
|
|
20
|
+
return CollectionResyncReason2;
|
|
21
|
+
})(CollectionResyncReason || {});
|
|
22
|
+
const MAX_LOOKUP_RETRY_MS = 3e4;
|
|
23
|
+
const streamCollectionEvents = (args) => {
|
|
24
|
+
const follow = args.options?.follow ?? true;
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
const signal = AbortSignal.any([
|
|
27
|
+
controller.signal,
|
|
28
|
+
args.context.closeSignal,
|
|
29
|
+
...args.options?.signal == null ? [] : [args.options.signal]
|
|
30
|
+
]);
|
|
31
|
+
let unsubscribe = null;
|
|
32
|
+
let pollTimer = null;
|
|
33
|
+
let lookupTimer = null;
|
|
34
|
+
const clearPoll = () => {
|
|
35
|
+
if (pollTimer != null) clearTimeout(pollTimer);
|
|
36
|
+
pollTimer = null;
|
|
37
|
+
};
|
|
38
|
+
let detachAbort = () => {
|
|
39
|
+
};
|
|
40
|
+
let detachClose = () => {
|
|
41
|
+
};
|
|
42
|
+
const queue = createAsyncQueue(() => {
|
|
43
|
+
controller.abort();
|
|
44
|
+
clearPoll();
|
|
45
|
+
if (lookupTimer != null) clearTimeout(lookupTimer);
|
|
46
|
+
unsubscribe?.();
|
|
47
|
+
detachAbort();
|
|
48
|
+
detachClose();
|
|
49
|
+
});
|
|
50
|
+
const resync = (topic, reason) => {
|
|
51
|
+
queue.push({ kind: "collection.resync" /* Resync */, topic, reason });
|
|
52
|
+
if (!follow) queue.end();
|
|
53
|
+
};
|
|
54
|
+
const degrade = (topic) => {
|
|
55
|
+
if (pollTimer != null || queue.closed()) return;
|
|
56
|
+
resync(topic, "degraded" /* Degraded */);
|
|
57
|
+
if (!follow || queue.closed()) return;
|
|
58
|
+
pollTimer = setTimeout(() => {
|
|
59
|
+
pollTimer = null;
|
|
60
|
+
degrade(topic);
|
|
61
|
+
}, args.context.timing.conversationPollIntervalMs);
|
|
62
|
+
};
|
|
63
|
+
const onFrame = (topic) => (raw) => {
|
|
64
|
+
const frame = agentRealtimeFrameSchema.safeParse(raw);
|
|
65
|
+
if (!frame.success || queue.closed()) return;
|
|
66
|
+
switch (frame.data.type) {
|
|
67
|
+
case AgentRealtimeFrameType.Event: {
|
|
68
|
+
const envelope = frame.data;
|
|
69
|
+
queue.push({
|
|
70
|
+
...parseAgentRealtimeEvent(envelope),
|
|
71
|
+
topic: envelope.topic,
|
|
72
|
+
cursor: envelope.cursor,
|
|
73
|
+
createdAt: envelope.createdAt,
|
|
74
|
+
replayed: false
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
case AgentRealtimeFrameType.Subscribed:
|
|
79
|
+
clearPoll();
|
|
80
|
+
resync(topic, "subscribed" /* Subscribed */);
|
|
81
|
+
return;
|
|
82
|
+
case AgentRealtimeFrameType.ResyncRequired:
|
|
83
|
+
resync(topic, "resync_required" /* ResyncRequired */);
|
|
84
|
+
return;
|
|
85
|
+
case AgentRealtimeFrameType.Error:
|
|
86
|
+
if (isTerminalRealtimeError(frame.data)) {
|
|
87
|
+
queue.fail(
|
|
88
|
+
realtimeSubscriptionError({
|
|
89
|
+
topic: frame.data.topic ?? topic,
|
|
90
|
+
code: frame.data.code ?? "unknown",
|
|
91
|
+
message: frame.data.message ?? "Realtime subscription was refused"
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
degrade(topic);
|
|
97
|
+
return;
|
|
98
|
+
default:
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
detachAbort = failOnAbort(queue, signal);
|
|
103
|
+
detachClose = failOnAbort(queue, args.context.closeSignal);
|
|
104
|
+
const userId = args.options?.userId;
|
|
105
|
+
let lookupFailures = 0;
|
|
106
|
+
const start = () => {
|
|
107
|
+
lookupTimer = null;
|
|
108
|
+
if (queue.closed()) return;
|
|
109
|
+
const topic = userId != null ? Promise.resolve(args.topicFor(userId)) : args.collection != null && args.context.realtimeCollectionTopic != null ? args.context.realtimeCollectionTopic(args.collection) : args.context.realtimeUserId().then(args.topicFor);
|
|
110
|
+
void topic.then(
|
|
111
|
+
(topic2) => {
|
|
112
|
+
if (queue.closed()) return;
|
|
113
|
+
const stop = args.context.realtime().subscribe(topic2, onFrame(topic2));
|
|
114
|
+
if (queue.closed()) stop();
|
|
115
|
+
else unsubscribe = stop;
|
|
116
|
+
},
|
|
117
|
+
(cause) => {
|
|
118
|
+
if (queue.closed()) return;
|
|
119
|
+
if (!isRetryableClientError(cause)) {
|
|
120
|
+
queue.fail(cause);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
resync(null, "degraded" /* Degraded */);
|
|
124
|
+
if (queue.closed()) return;
|
|
125
|
+
const delay = Math.min(
|
|
126
|
+
MAX_LOOKUP_RETRY_MS,
|
|
127
|
+
args.context.timing.conversationPollIntervalMs * 2 ** lookupFailures
|
|
128
|
+
);
|
|
129
|
+
lookupFailures += 1;
|
|
130
|
+
lookupTimer = setTimeout(start, delay);
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
start();
|
|
135
|
+
return queue.iterator;
|
|
136
|
+
};
|
|
137
|
+
export {
|
|
138
|
+
CollectionEventKind,
|
|
139
|
+
CollectionResyncReason,
|
|
140
|
+
streamCollectionEvents
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=collection-events.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/agent-client/collection-events.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n agentRealtimeFrameSchema,\n AgentRealtimeFrameType,\n parseAgentRealtimeEvent,\n} from '@finalai/agent-protocol/agent-platform';\nimport { createAsyncQueue, failOnAbort } from \"./async-queue.mjs\";\nimport type { ClientCollection, ClientContextIface, SignalOptionsIface } from \"./context.mjs\";\nimport type { ConversationEvent } from \"./conversations.mjs\";\nimport {\n isRetryableClientError,\n isTerminalRealtimeError,\n realtimeSubscriptionError,\n} from \"./errors.mjs\";\nimport type { RealtimeTransportFrameIface } from \"./realtime.mjs\";\n\n// The caller's collection topics (`user.collection:<userId>:conversations` and\n// `:pending`). They carry no replay, so a stream says when the\n// caller must re-read the collection over HTTP: on every (re)subscription and\n// resync, and while the realtime transport reports errors.\n\nexport enum CollectionEventKind {\n /** Re-read the collection (`conversations.list()`, `pending.mine()`); events may have been missed. */\n Resync = 'collection.resync',\n}\n\nexport enum CollectionResyncReason {\n Subscribed = 'subscribed',\n ResyncRequired = 'resync_required',\n /** The realtime transport is down; repeated every `timing.conversationPollIntervalMs`. */\n Degraded = 'degraded',\n}\n\nexport interface CollectionResyncEventIface {\n kind: CollectionEventKind.Resync;\n /** Null while the signed-in user, and so the topic, could not be read yet. */\n topic: string | null;\n reason: CollectionResyncReason;\n}\n\n/** A realtime event of the collection topic, or a cue to re-read the collection. */\nexport type CollectionEvent = ConversationEvent | CollectionResyncEventIface;\n\nexport interface CollectionEventsOptionsIface extends SignalOptionsIface {\n /** Keep streaming; false ends after the first resync. Defaults to true. */\n follow?: boolean;\n /**\n * The signed-in user the topics are keyed by. Defaults to the user of a\n * minted realtime session (`realtime.createSession()`).\n */\n userId?: string;\n}\n\nconst MAX_LOOKUP_RETRY_MS = 30_000;\n\nexport const streamCollectionEvents = (args: {\n context: ClientContextIface;\n topicFor: (userId: string) => string;\n collection?: ClientCollection;\n options: CollectionEventsOptionsIface | undefined;\n}): AsyncIterableIterator<CollectionEvent> => {\n const follow = args.options?.follow ?? true;\n const controller = new AbortController();\n const signal = AbortSignal.any([\n controller.signal,\n args.context.closeSignal,\n ...(args.options?.signal == null ? [] : [args.options.signal]),\n ]);\n let unsubscribe: (() => void) | null = null;\n let pollTimer: ReturnType<typeof setTimeout> | null = null;\n let lookupTimer: ReturnType<typeof setTimeout> | null = null;\n const clearPoll = (): void => {\n if (pollTimer != null) clearTimeout(pollTimer);\n pollTimer = null;\n };\n let detachAbort: () => void = () => {};\n let detachClose: () => void = () => {};\n const queue = createAsyncQueue<CollectionEvent>(() => {\n controller.abort();\n clearPoll();\n if (lookupTimer != null) clearTimeout(lookupTimer);\n unsubscribe?.();\n detachAbort();\n detachClose();\n });\n\n const resync = (topic: string | null, reason: CollectionResyncReason): void => {\n queue.push({ kind: CollectionEventKind.Resync, topic, reason });\n if (!follow) queue.end();\n };\n\n const degrade = (topic: string): void => {\n if (pollTimer != null || queue.closed()) return;\n resync(topic, CollectionResyncReason.Degraded);\n if (!follow || queue.closed()) return;\n pollTimer = setTimeout(() => {\n pollTimer = null;\n degrade(topic);\n }, args.context.timing.conversationPollIntervalMs);\n };\n\n const onFrame =\n (topic: string) =>\n (raw: RealtimeTransportFrameIface): void => {\n const frame = agentRealtimeFrameSchema.safeParse(raw);\n if (!frame.success || queue.closed()) return;\n switch (frame.data.type) {\n case AgentRealtimeFrameType.Event: {\n const envelope = frame.data;\n queue.push({\n ...parseAgentRealtimeEvent(envelope),\n topic: envelope.topic,\n cursor: envelope.cursor,\n createdAt: envelope.createdAt,\n replayed: false,\n });\n return;\n }\n case AgentRealtimeFrameType.Subscribed:\n clearPoll();\n resync(topic, CollectionResyncReason.Subscribed);\n return;\n case AgentRealtimeFrameType.ResyncRequired:\n resync(topic, CollectionResyncReason.ResyncRequired);\n return;\n case AgentRealtimeFrameType.Error:\n if (isTerminalRealtimeError(frame.data)) {\n queue.fail(\n realtimeSubscriptionError({\n topic: frame.data.topic ?? topic,\n code: frame.data.code ?? 'unknown',\n message: frame.data.message ?? 'Realtime subscription was refused',\n }),\n );\n return;\n }\n // The transport resubscribes; until then the caller re-reads periodically.\n degrade(topic);\n return;\n default:\n return;\n }\n };\n\n detachAbort = failOnAbort(queue, signal);\n detachClose = failOnAbort(queue, args.context.closeSignal);\n const userId = args.options?.userId;\n let lookupFailures = 0;\n const start = (): void => {\n lookupTimer = null;\n if (queue.closed()) return;\n const topic =\n userId != null\n ? Promise.resolve(args.topicFor(userId))\n : args.collection != null && args.context.realtimeCollectionTopic != null\n ? args.context.realtimeCollectionTopic(args.collection)\n : args.context.realtimeUserId().then(args.topicFor);\n void topic.then(\n (topic) => {\n if (queue.closed()) return;\n const stop = args.context.realtime().subscribe(topic, onFrame(topic));\n if (queue.closed()) stop();\n else unsubscribe = stop;\n },\n (cause: unknown) => {\n if (queue.closed()) return;\n if (!isRetryableClientError(cause)) {\n queue.fail(cause);\n return;\n }\n // The user lookup is unreachable: the caller re-reads meanwhile, and it is retried.\n resync(null, CollectionResyncReason.Degraded);\n if (queue.closed()) return;\n const delay = Math.min(\n MAX_LOOKUP_RETRY_MS,\n args.context.timing.conversationPollIntervalMs * 2 ** lookupFailures,\n );\n lookupFailures += 1;\n lookupTimer = setTimeout(start, delay);\n },\n );\n };\n start();\n return queue.iterator;\n};\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SA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S,MAAM,CAAC,IACrC,KAAK,cAAc,QAAQ,KAAK,QAAQ,2BAA2B,OACjE,KAAK,QAAQ,wBAAwB,KAAK,UAAU,IACpD,KAAK,QAAQ,eAAe,EAAE,KAAK,KAAK,QAAQ;AACxD,SAAK,MAAM;AAAA,MACT,CAACC,WAAU;AACT,YAAI,MAAM,OAAO,EAAG;AACpB,cAAM,OAAO,KAAK,QAAQ,SAAS,EAAE,UAAUA,QAAO,QAAQA,MAAK,CAAC;AACpE,YAAI,MAAM,OAAO,EAAG,MAAK;AAAA,YACpB,eAAc;AAAA,MACrB;AAAA,MACA,CAAC,UAAmB;AAClB,YAAI,MAAM,OAAO,EAAG;AACpB,YAAI,CAAC,uBAAuB,KAAK,GAAG;AAClC,gBAAM,KAAK,KAAK;AAChB;AAAA,QACF;AAEA,eAAO,MAAM,yBAA+B;AAC5C,YAAI,MAAM,OAAO,EAAG;AACpB,cAAM,QAAQ,KAAK;AAAA,UACjB;AAAA,UACA,KAAK,QAAQ,OAAO,6BAA6B,KAAK;AAAA,QACxD;AACA,0BAAkB;AAClB,sBAAc,WAAW,OAAO,KAAK;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AACA,QAAM;AACN,SAAO,MAAM;AACf;",
|
|
6
|
+
"names": ["CollectionEventKind", "CollectionResyncReason", "topic"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AgentSessionIface } from '@finalai/agent-protocol/agent-platform';
|
|
2
|
+
export type SessionConfigOptionIface = AgentSessionIface['configOptions'][number];
|
|
3
|
+
/** ACP's semantic categories (UX only); harnesses may add their own. */
|
|
4
|
+
export declare enum ConfigOptionCategory {
|
|
5
|
+
Mode = "mode",
|
|
6
|
+
Model = "model",
|
|
7
|
+
ThoughtLevel = "thought_level"
|
|
8
|
+
}
|
|
9
|
+
export interface ConfigSelectChoiceIface {
|
|
10
|
+
value: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
/** A single-value selector: `setConfigOption({ configId, value })` with one of `choices`. */
|
|
14
|
+
export interface ConfigSelectIface {
|
|
15
|
+
configId: string;
|
|
16
|
+
name: string;
|
|
17
|
+
category: string | null;
|
|
18
|
+
currentValue: string;
|
|
19
|
+
choices: ConfigSelectChoiceIface[];
|
|
20
|
+
}
|
|
21
|
+
/** The select options among a session's config options (booleans and unknown types skipped). */
|
|
22
|
+
export declare const configSelectsOf: (configOptions: readonly SessionConfigOptionIface[]) => ConfigSelectIface[];
|
|
23
|
+
/** The first select of a category (`model`, `thought_level`), if the harness advertises one. */
|
|
24
|
+
export declare const configSelectFor: (configOptions: readonly SessionConfigOptionIface[], category: ConfigOptionCategory | string) => ConfigSelectIface | null;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
var ConfigOptionCategory = /* @__PURE__ */ ((ConfigOptionCategory2) => {
|
|
3
|
+
ConfigOptionCategory2["Mode"] = "mode";
|
|
4
|
+
ConfigOptionCategory2["Model"] = "model";
|
|
5
|
+
ConfigOptionCategory2["ThoughtLevel"] = "thought_level";
|
|
6
|
+
return ConfigOptionCategory2;
|
|
7
|
+
})(ConfigOptionCategory || {});
|
|
8
|
+
const choiceSchema = z.looseObject({ value: z.string(), name: z.string().optional() });
|
|
9
|
+
const groupSchema = z.looseObject({ options: z.array(choiceSchema) });
|
|
10
|
+
const selectSchema = z.looseObject({
|
|
11
|
+
type: z.string().optional(),
|
|
12
|
+
configId: z.string().optional(),
|
|
13
|
+
id: z.string().optional(),
|
|
14
|
+
name: z.string().optional(),
|
|
15
|
+
category: z.string().nullish(),
|
|
16
|
+
currentValue: z.string(),
|
|
17
|
+
options: z.array(z.union([choiceSchema, groupSchema]))
|
|
18
|
+
});
|
|
19
|
+
const configSelectsOf = (configOptions) => configOptions.flatMap((option) => {
|
|
20
|
+
const parsed = selectSchema.safeParse(option);
|
|
21
|
+
if (!parsed.success) return [];
|
|
22
|
+
const select = parsed.data;
|
|
23
|
+
const configId = select.configId ?? select.id;
|
|
24
|
+
if (configId == null || select.type != null && select.type !== "select") return [];
|
|
25
|
+
const choices = select.options.flatMap((entry) => {
|
|
26
|
+
const single = choiceSchema.safeParse(entry);
|
|
27
|
+
if (single.success) return [single.data];
|
|
28
|
+
return groupSchema.safeParse(entry).data?.options ?? [];
|
|
29
|
+
});
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
configId,
|
|
33
|
+
name: select.name ?? configId,
|
|
34
|
+
category: select.category ?? null,
|
|
35
|
+
currentValue: select.currentValue,
|
|
36
|
+
choices: choices.map((choice) => ({
|
|
37
|
+
value: choice.value,
|
|
38
|
+
name: choice.name ?? choice.value
|
|
39
|
+
}))
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
});
|
|
43
|
+
const configSelectFor = (configOptions, category) => configSelectsOf(configOptions).find((select) => select.category === category) ?? null;
|
|
44
|
+
export {
|
|
45
|
+
ConfigOptionCategory,
|
|
46
|
+
configSelectFor,
|
|
47
|
+
configSelectsOf
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=config-options.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/agent-client/config-options.ts"],
|
|
4
|
+
"sourcesContent": ["import type { AgentSessionIface } from '@finalai/agent-protocol/agent-platform';\nimport * as z from 'zod';\n\n// ACP session config options as a session's harness advertises them\n// (`AgentSessionIface.configOptions`), read as pickers: what the model picker\n// and the reasoning picker render, and what `setConfigOption` takes.\n\nexport type SessionConfigOptionIface = AgentSessionIface['configOptions'][number];\n\n/** ACP's semantic categories (UX only); harnesses may add their own. */\nexport enum ConfigOptionCategory {\n Mode = 'mode',\n Model = 'model',\n ThoughtLevel = 'thought_level',\n}\n\nexport interface ConfigSelectChoiceIface {\n value: string;\n name: string;\n}\n\n/** A single-value selector: `setConfigOption({ configId, value })` with one of `choices`. */\nexport interface ConfigSelectIface {\n configId: string;\n name: string;\n category: string | null;\n currentValue: string;\n choices: ConfigSelectChoiceIface[];\n}\n\nconst choiceSchema = z.looseObject({ value: z.string(), name: z.string().optional() });\nconst groupSchema = z.looseObject({ options: z.array(choiceSchema) });\nconst selectSchema = z.looseObject({\n type: z.string().optional(),\n configId: z.string().optional(),\n id: z.string().optional(),\n name: z.string().optional(),\n category: z.string().nullish(),\n currentValue: z.string(),\n options: z.array(z.union([choiceSchema, groupSchema])),\n});\n\n/** The select options among a session's config options (booleans and unknown types skipped). */\nexport const configSelectsOf = (\n configOptions: readonly SessionConfigOptionIface[],\n): ConfigSelectIface[] =>\n configOptions.flatMap((option) => {\n const parsed = selectSchema.safeParse(option);\n if (!parsed.success) return [];\n const select = parsed.data;\n const configId = select.configId ?? select.id;\n if (configId == null || (select.type != null && select.type !== 'select')) return [];\n const choices = select.options.flatMap((entry) => {\n const single = choiceSchema.safeParse(entry);\n if (single.success) return [single.data];\n return groupSchema.safeParse(entry).data?.options ?? [];\n });\n return [\n {\n configId,\n name: select.name ?? configId,\n category: select.category ?? null,\n currentValue: select.currentValue,\n choices: choices.map((choice) => ({\n value: choice.value,\n name: choice.name ?? choice.value,\n })),\n },\n ];\n });\n\n/** The first select of a category (`model`, `thought_level`), if the harness advertises one. */\nexport const configSelectFor = (\n configOptions: readonly SessionConfigOptionIface[],\n category: ConfigOptionCategory | string,\n): ConfigSelectIface | null =>\n configSelectsOf(configOptions).find((select) => select.category === category) ?? null;\n"],
|
|
5
|
+
"mappings": "AACA,YAAY,OAAO;AASZ,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,WAAQ;AACR,EAAAA,sBAAA,kBAAe;AAHL,SAAAA;AAAA,GAAA;AAoBZ,MAAM,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACrF,MAAM,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,E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;",
|
|
6
|
+
"names": ["ConfigOptionCategory"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { StreamTimingIface } from "./frame-stream.mjs";
|
|
2
|
+
import type { FetchIface, HttpIface } from "./http.mjs";
|
|
3
|
+
import type { RealtimeTransportIface } from "./realtime.mjs";
|
|
4
|
+
export declare enum ClientCollection {
|
|
5
|
+
Conversations = "conversations",
|
|
6
|
+
Pending = "pending"
|
|
7
|
+
}
|
|
8
|
+
/** What every API group gets from `createClient`. */
|
|
9
|
+
export interface ClientContextIface {
|
|
10
|
+
http: HttpIface;
|
|
11
|
+
/** Aborts when `client.close()` is called; every stream ends with it. */
|
|
12
|
+
closeSignal: AbortSignal;
|
|
13
|
+
/** Presigned storage requests: no API credentials, client identity or cookies. */
|
|
14
|
+
storageFetch: FetchIface;
|
|
15
|
+
/** Resolved on first use, so clients that never stream never mint a gateway token. */
|
|
16
|
+
realtime: () => RealtimeTransportIface;
|
|
17
|
+
/** The signed-in user realtime topics are keyed by (a minted realtime session's); cached. */
|
|
18
|
+
realtimeUserId: () => Promise<string>;
|
|
19
|
+
realtimeCollectionTopic?: (collection: ClientCollection) => Promise<string>;
|
|
20
|
+
timing: StreamTimingIface;
|
|
21
|
+
/** Idempotency keys and client message ids. */
|
|
22
|
+
newKey: () => string;
|
|
23
|
+
/** Client clock in epoch ms. */
|
|
24
|
+
now: () => number;
|
|
25
|
+
}
|
|
26
|
+
export interface SignalOptionsIface {
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
/** Author calls may use the wire spelling or the exported enum constant. */
|
|
30
|
+
export type EnumInput<E extends string> = E | `${E}`;
|
|
31
|
+
export declare const encodePath: (segment: string) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var ClientCollection = /* @__PURE__ */ ((ClientCollection2) => {
|
|
2
|
+
ClientCollection2["Conversations"] = "conversations";
|
|
3
|
+
ClientCollection2["Pending"] = "pending";
|
|
4
|
+
return ClientCollection2;
|
|
5
|
+
})(ClientCollection || {});
|
|
6
|
+
const encodePath = (segment) => encodeURIComponent(segment);
|
|
7
|
+
export {
|
|
8
|
+
ClientCollection,
|
|
9
|
+
encodePath
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=context.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/agent-client/context.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StreamTimingIface } from \"./frame-stream.mjs\";\nimport type { FetchIface, HttpIface } from \"./http.mjs\";\nimport type { RealtimeTransportIface } from \"./realtime.mjs\";\n\nexport enum ClientCollection {\n Conversations = 'conversations',\n Pending = 'pending',\n}\n\n/** What every API group gets from `createClient`. */\nexport interface ClientContextIface {\n http: HttpIface;\n /** Aborts when `client.close()` is called; every stream ends with it. */\n closeSignal: AbortSignal;\n /** Presigned storage requests: no API credentials, client identity or cookies. */\n storageFetch: FetchIface;\n /** Resolved on first use, so clients that never stream never mint a gateway token. */\n realtime: () => RealtimeTransportIface;\n /** The signed-in user realtime topics are keyed by (a minted realtime session's); cached. */\n realtimeUserId: () => Promise<string>;\n realtimeCollectionTopic?: (collection: ClientCollection) => Promise<string>;\n timing: StreamTimingIface;\n /** Idempotency keys and client message ids. */\n newKey: () => string;\n /** Client clock in epoch ms. */\n now: () => number;\n}\n\nexport interface SignalOptionsIface {\n signal?: AbortSignal;\n}\n\n/** Author calls may use the wire spelling or the exported enum constant. */\nexport type EnumInput<E extends string> = E | `${E}`;\n\nexport const encodePath = (segment: string): string => encodeURIComponent(segment);\n"],
|
|
5
|
+
"mappings": "AAIO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,mBAAgB;AAChB,EAAAA,kBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;AA+BL,MAAM,aAAa,CAAC,YAA4B,mBAAmB,OAAO;",
|
|
6
|
+
"names": ["ClientCollection"]
|
|
7
|
+
}
|