@lightblues/jig 0.0.2 → 0.0.4
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/agent-paseo/daemon.d.ts +98 -0
- package/dist/agent-paseo/daemon.js +177 -0
- package/dist/agent-paseo/index.d.ts +12 -0
- package/dist/agent-paseo/index.js +9 -0
- package/dist/agent-paseo/runner.d.ts +155 -0
- package/dist/agent-paseo/runner.js +383 -0
- package/dist/agent-paseo/turn.d.ts +100 -0
- package/dist/agent-paseo/turn.js +212 -0
- package/package.json +20 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type PaseoAgentTimelineEvent } from "@getpaseo/client";
|
|
2
|
+
import type { TimelineEntry, TimelineItem } from "./turn.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The local Paseo daemon as the runner needs it: read an agent, start one, send it a message, follow its
|
|
5
|
+
* timeline, read the timeline's tail, stop it. From assay-016's `daemon.ts`; tests pass a fake.
|
|
6
|
+
*/
|
|
7
|
+
export interface Daemon {
|
|
8
|
+
/** The agent as the host's filter needs it, or null when the daemon does not know it. */
|
|
9
|
+
agent(id: string): Promise<AgentInfo | null>;
|
|
10
|
+
/** A new agent in the configured workspace; returns its id. It has no prompt until `send`. */
|
|
11
|
+
create(req: {
|
|
12
|
+
cwd: string;
|
|
13
|
+
title: string;
|
|
14
|
+
labels: Record<string, string>;
|
|
15
|
+
}): Promise<string>;
|
|
16
|
+
/** Sends `text` as a user message with our id (`clientMessageId` in the timeline): the turn it starts is found by it. */
|
|
17
|
+
send(id: string, text: string, messageId: string): Promise<void>;
|
|
18
|
+
/** Live events of the agent's timeline until the returned function is called. Resolves once the subscription is up. */
|
|
19
|
+
subscribe(id: string, on: (e: LiveEvent) => void): Promise<() => void>;
|
|
20
|
+
/** The projected tail of the timeline, oldest first, with the cursor it reaches. */
|
|
21
|
+
tail(id: string, limit: number): Promise<Tail>;
|
|
22
|
+
cancel(id: string): Promise<void>;
|
|
23
|
+
/** Closes the connection; subscriptions on it end without `lost`. A later call connects again. */
|
|
24
|
+
close?(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export interface AgentInfo {
|
|
27
|
+
cwd: string;
|
|
28
|
+
archived: boolean;
|
|
29
|
+
status: string;
|
|
30
|
+
}
|
|
31
|
+
export interface Tail {
|
|
32
|
+
entries: TimelineEntry[];
|
|
33
|
+
/** The timeline's epoch and the last seq the page covers: live items at or below it are already in `entries`. */
|
|
34
|
+
epoch: string | null;
|
|
35
|
+
seq: number | null;
|
|
36
|
+
}
|
|
37
|
+
export type LiveEvent =
|
|
38
|
+
/** A timeline item; `seq`/`epoch` place it in the canonical timeline, `turnId` names its turn when the provider says. */
|
|
39
|
+
{
|
|
40
|
+
type: "timeline";
|
|
41
|
+
item: TimelineItem;
|
|
42
|
+
turnId?: string;
|
|
43
|
+
seq?: number;
|
|
44
|
+
epoch?: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: "turn_started";
|
|
47
|
+
turnId?: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: "turn_completed";
|
|
50
|
+
turnId?: string;
|
|
51
|
+
} | {
|
|
52
|
+
type: "turn_canceled";
|
|
53
|
+
turnId?: string;
|
|
54
|
+
reason?: string;
|
|
55
|
+
} | {
|
|
56
|
+
type: "turn_failed";
|
|
57
|
+
turnId?: string;
|
|
58
|
+
error: string;
|
|
59
|
+
}
|
|
60
|
+
/** The timeline was rebuilt under a new epoch: everything before it is void, re-tail. */
|
|
61
|
+
| {
|
|
62
|
+
type: "replacement";
|
|
63
|
+
epoch: string;
|
|
64
|
+
}
|
|
65
|
+
/** Live delivery resumed after a reconnect; events in between may be missing, re-tail. */
|
|
66
|
+
| {
|
|
67
|
+
type: "subscription_restored";
|
|
68
|
+
}
|
|
69
|
+
/** The connection to the daemon dropped or the subscription failed. */
|
|
70
|
+
| {
|
|
71
|
+
type: "lost";
|
|
72
|
+
error: string;
|
|
73
|
+
};
|
|
74
|
+
export interface PaseoDaemonConfig {
|
|
75
|
+
/** Workspace id new agents start in (assay: `ASSAY_PASEO_WORKSPACE`). */
|
|
76
|
+
workspace: string;
|
|
77
|
+
/** `<provider>/<model>` as the CLI takes it (`claude/cbi/claude-opus-5.5`). */
|
|
78
|
+
provider: string;
|
|
79
|
+
/** Defaults to `$PASEO_HOME`, then `~/.paseo`. */
|
|
80
|
+
home?: string;
|
|
81
|
+
/** Prefix of the client id the daemon sees (`<clientName>-<uuid>`). */
|
|
82
|
+
clientName?: string;
|
|
83
|
+
}
|
|
84
|
+
export declare const paseoHome: (home?: string) => string;
|
|
85
|
+
/**
|
|
86
|
+
* The startup guard: this part runs only beside a local Paseo daemon. Throws unless the Paseo home holds the
|
|
87
|
+
* daemon's `paseo.pid` and its `local-credential`, so a multi-user app that bundles it by mistake fails at once.
|
|
88
|
+
*/
|
|
89
|
+
export declare function assertLocalDaemon(home?: string): string;
|
|
90
|
+
/** The daemon's address from `paseo.pid`, as `@getpaseo/client/node` takes it (`host:port` or `unix://path`). */
|
|
91
|
+
export declare function localAddress(home: string): string;
|
|
92
|
+
/** Maps one event of `agents.ref(id).timeline.subscribe` to a `LiveEvent`, or null for events the runner ignores. */
|
|
93
|
+
export declare function liveEvent(m: PaseoAgentTimelineEvent): LiveEvent | null;
|
|
94
|
+
/**
|
|
95
|
+
* The local daemon over one kept-alive connection. A dropped connection reports `lost` to every subscription on
|
|
96
|
+
* it; the next call opens a new one. Refuses to construct without a local daemon credential (`assertLocalDaemon`).
|
|
97
|
+
*/
|
|
98
|
+
export declare function paseoDaemon(cfg: PaseoDaemonConfig): Daemon;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
// J004: public entry points only (`@getpaseo/client` and `@getpaseo/client/node`), no `internal/*` import.
|
|
6
|
+
// This is the only file that imports `@getpaseo/client`; the version is pinned to the daemon's (0.16.1).
|
|
7
|
+
import { createPaseoApi } from "@getpaseo/client";
|
|
8
|
+
import { createHostClient } from "@getpaseo/client/node";
|
|
9
|
+
export const paseoHome = (home) => home ?? process.env.PASEO_HOME ?? path.join(os.homedir(), ".paseo");
|
|
10
|
+
/**
|
|
11
|
+
* The startup guard: this part runs only beside a local Paseo daemon. Throws unless the Paseo home holds the
|
|
12
|
+
* daemon's `paseo.pid` and its `local-credential`, so a multi-user app that bundles it by mistake fails at once.
|
|
13
|
+
*/
|
|
14
|
+
export function assertLocalDaemon(home) {
|
|
15
|
+
const h = paseoHome(home);
|
|
16
|
+
for (const f of ["paseo.pid", "local-credential"])
|
|
17
|
+
if (!existsSync(path.join(h, f)))
|
|
18
|
+
throw new Error(`@lightblues/jig/agent-paseo: no ${f} in ${h}; it runs only on a machine with a local Paseo daemon (PASEO_HOME)`);
|
|
19
|
+
return h;
|
|
20
|
+
}
|
|
21
|
+
/** The daemon's address from `paseo.pid`, as `@getpaseo/client/node` takes it (`host:port` or `unix://path`). */
|
|
22
|
+
export function localAddress(home) {
|
|
23
|
+
const pid = JSON.parse(readFileSync(path.join(home, "paseo.pid"), "utf8"));
|
|
24
|
+
const listen = pid.listen?.trim();
|
|
25
|
+
if (!listen)
|
|
26
|
+
throw new Error(`no listen address in ${home}/paseo.pid`);
|
|
27
|
+
return listen.startsWith("/") ? `unix://${listen}` : listen;
|
|
28
|
+
}
|
|
29
|
+
const TIMEOUT_MS = 20_000;
|
|
30
|
+
async function withTimeout(p, ms, what) {
|
|
31
|
+
let timer;
|
|
32
|
+
const timeout = new Promise((_, reject) => {
|
|
33
|
+
timer = setTimeout(() => reject(new Error(`${what} timed out after ${ms} ms`)), ms);
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
return await Promise.race([p, timeout]);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Maps one event of `agents.ref(id).timeline.subscribe` to a `LiveEvent`, or null for events the runner ignores. */
|
|
43
|
+
export function liveEvent(m) {
|
|
44
|
+
const e = m.event;
|
|
45
|
+
const at = m;
|
|
46
|
+
switch (e.type) {
|
|
47
|
+
case "timeline":
|
|
48
|
+
return e.item ? { type: "timeline", item: e.item, ...(e.turnId ? { turnId: e.turnId } : {}), ...(at.seq != null ? { seq: at.seq } : {}), ...(at.epoch ? { epoch: at.epoch } : {}) } : null;
|
|
49
|
+
case "turn_started":
|
|
50
|
+
case "turn_completed":
|
|
51
|
+
return { type: e.type, turnId: e.turnId };
|
|
52
|
+
case "turn_canceled":
|
|
53
|
+
return { type: "turn_canceled", turnId: e.turnId, reason: e.reason };
|
|
54
|
+
case "turn_failed":
|
|
55
|
+
return { type: "turn_failed", turnId: e.turnId, error: e.error ?? "the turn failed" };
|
|
56
|
+
case "replacement":
|
|
57
|
+
return { type: "replacement", epoch: e.epoch ?? "" };
|
|
58
|
+
case "subscription_restored":
|
|
59
|
+
return { type: "subscription_restored" };
|
|
60
|
+
case "error":
|
|
61
|
+
return { type: "lost", error: e.error ?? "the timeline subscription failed" };
|
|
62
|
+
default:
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The local daemon over one kept-alive connection. A dropped connection reports `lost` to every subscription on
|
|
68
|
+
* it; the next call opens a new one. Refuses to construct without a local daemon credential (`assertLocalDaemon`).
|
|
69
|
+
*/
|
|
70
|
+
export function paseoDaemon(cfg) {
|
|
71
|
+
const home = assertLocalDaemon(cfg.home);
|
|
72
|
+
const slash = cfg.provider.indexOf("/");
|
|
73
|
+
const provider = slash < 0 ? cfg.provider : cfg.provider.slice(0, slash);
|
|
74
|
+
const model = slash < 0 ? undefined : cfg.provider.slice(slash + 1);
|
|
75
|
+
let conn = null;
|
|
76
|
+
/** Called when the kept-alive connection drops, so subscriptions on it report `lost`. */
|
|
77
|
+
const onLost = new Set();
|
|
78
|
+
function connect() {
|
|
79
|
+
if (conn)
|
|
80
|
+
return conn;
|
|
81
|
+
const token = readFileSync(path.join(home, "local-credential"), "utf8").trim();
|
|
82
|
+
const client = createHostClient(localAddress(home), {
|
|
83
|
+
clientId: `${cfg.clientName ?? "jig-agent-paseo"}-${randomUUID()}`,
|
|
84
|
+
clientType: "cli",
|
|
85
|
+
connectTimeoutMs: 5000,
|
|
86
|
+
reconnect: { enabled: false },
|
|
87
|
+
localCredential: () => token,
|
|
88
|
+
});
|
|
89
|
+
const p = withTimeout(client.connect(), TIMEOUT_MS, "connecting to the Paseo daemon").then(() => ({ client, api: createPaseoApi(client) }));
|
|
90
|
+
conn = p;
|
|
91
|
+
p.catch(() => {
|
|
92
|
+
if (conn === p)
|
|
93
|
+
conn = null;
|
|
94
|
+
void client.close().catch(() => { });
|
|
95
|
+
});
|
|
96
|
+
let up = false;
|
|
97
|
+
client.subscribeConnectionStatus((s) => {
|
|
98
|
+
if (s.status === "connected")
|
|
99
|
+
up = true;
|
|
100
|
+
if (!up || s.status === "connected" || conn !== p)
|
|
101
|
+
return;
|
|
102
|
+
conn = null;
|
|
103
|
+
const why = s.status === "disconnected" ? (s.reason ?? "disconnected") : s.status;
|
|
104
|
+
for (const f of [...onLost])
|
|
105
|
+
f(`the connection to Paseo dropped (${why})`);
|
|
106
|
+
void client.close().catch(() => { });
|
|
107
|
+
});
|
|
108
|
+
return p;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
async agent(id) {
|
|
112
|
+
const { api } = await connect();
|
|
113
|
+
const r = await withTimeout(api.agents.ref(id).refresh(), TIMEOUT_MS, "reading the agent").catch((e) => {
|
|
114
|
+
if (/not found|unknown agent/i.test(e.message))
|
|
115
|
+
return null;
|
|
116
|
+
throw e;
|
|
117
|
+
});
|
|
118
|
+
if (!r)
|
|
119
|
+
return null;
|
|
120
|
+
return { cwd: r.agent.cwd, archived: Boolean(r.agent.archivedAt), status: r.agent.status };
|
|
121
|
+
},
|
|
122
|
+
async create(req) {
|
|
123
|
+
// The client's own create: `workspaces.ref(id).agents.create` would put the agent in the workspace's directory, not `req.cwd`.
|
|
124
|
+
const { client } = await connect();
|
|
125
|
+
const a = await withTimeout(client.createAgent({ provider, ...(model ? { model } : {}), cwd: req.cwd, workspaceId: cfg.workspace, title: req.title, labels: req.labels }), 60_000, "starting the agent");
|
|
126
|
+
return a.id;
|
|
127
|
+
},
|
|
128
|
+
async send(id, text, messageId) {
|
|
129
|
+
const { api } = await connect();
|
|
130
|
+
await withTimeout(api.agents.ref(id).send(text, { messageId }), TIMEOUT_MS, "sending to the agent");
|
|
131
|
+
},
|
|
132
|
+
async subscribe(id, on) {
|
|
133
|
+
const { api } = await connect();
|
|
134
|
+
const lost = (error) => on({ type: "lost", error });
|
|
135
|
+
onLost.add(lost);
|
|
136
|
+
const sub = api.agents.ref(id).timeline.subscribe((m) => {
|
|
137
|
+
const e = liveEvent(m);
|
|
138
|
+
if (e)
|
|
139
|
+
on(e);
|
|
140
|
+
});
|
|
141
|
+
const stop = () => {
|
|
142
|
+
onLost.delete(lost);
|
|
143
|
+
sub();
|
|
144
|
+
};
|
|
145
|
+
try {
|
|
146
|
+
await withTimeout(sub.ready, TIMEOUT_MS, "subscribing to the timeline");
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
stop();
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
152
|
+
return stop;
|
|
153
|
+
},
|
|
154
|
+
async tail(id, limit) {
|
|
155
|
+
const { api } = await connect();
|
|
156
|
+
const page = await withTimeout(api.agents.ref(id).timeline.refetch({ direction: "tail", limit, projection: "projected" }), 30_000, "reading the timeline");
|
|
157
|
+
const last = page.entries.at(-1);
|
|
158
|
+
return {
|
|
159
|
+
entries: page.entries.map((e) => ({ timestamp: e.timestamp, item: e.item, ...(e.turnId ? { turnId: e.turnId } : {}) })),
|
|
160
|
+
epoch: page.epoch ?? null,
|
|
161
|
+
seq: last ? last.seqEnd : null,
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
async cancel(id) {
|
|
165
|
+
// Agent handles have no cancel in 0.16.1; the client returned by `createHostClient` has.
|
|
166
|
+
const { client } = await connect();
|
|
167
|
+
await withTimeout(client.cancelAgent(id), TIMEOUT_MS, "stopping the agent");
|
|
168
|
+
},
|
|
169
|
+
async close() {
|
|
170
|
+
const p = conn;
|
|
171
|
+
conn = null;
|
|
172
|
+
onLost.clear();
|
|
173
|
+
if (p)
|
|
174
|
+
await p.then(({ client }) => client.close()).catch(() => { });
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@lightblues/jig/agent-paseo`: follow a local Paseo agent's timeline as `@ag-ui/core` events, one run per host
|
|
3
|
+
* thread, with replay of the turn in progress and recovery after a gap or a restart. Server only: `paseoDaemon`
|
|
4
|
+
* refuses to start without a local daemon credential in `PASEO_HOME`. Never bundle it into a multi-user app.
|
|
5
|
+
* See `.ea/docs/agent-paseo.md`.
|
|
6
|
+
*/
|
|
7
|
+
export { assertLocalDaemon, liveEvent, localAddress, paseoDaemon, paseoHome } from "./daemon.ts";
|
|
8
|
+
export type { AgentInfo, Daemon, LiveEvent, PaseoDaemonConfig, Tail } from "./daemon.ts";
|
|
9
|
+
export { PaseoThreadRunner, paseoThreadRunner } from "./runner.ts";
|
|
10
|
+
export type { Listener, PaseoThreadRunnerOptions, ReadyValue, RecoverRequest, RecoverResult, SendRequest, ThreadStore } from "./runner.ts";
|
|
11
|
+
export { TurnFolder, afterMessage, chat, finalText, isProviderError, toolSummary } from "./turn.ts";
|
|
12
|
+
export type { ChatItem, FoldedEvent, PaseoEvent, TimelineEntry, TimelineItem, ToolView } from "./turn.ts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@lightblues/jig/agent-paseo`: follow a local Paseo agent's timeline as `@ag-ui/core` events, one run per host
|
|
3
|
+
* thread, with replay of the turn in progress and recovery after a gap or a restart. Server only: `paseoDaemon`
|
|
4
|
+
* refuses to start without a local daemon credential in `PASEO_HOME`. Never bundle it into a multi-user app.
|
|
5
|
+
* See `.ea/docs/agent-paseo.md`.
|
|
6
|
+
*/
|
|
7
|
+
export { assertLocalDaemon, liveEvent, localAddress, paseoDaemon, paseoHome } from "./daemon.js";
|
|
8
|
+
export { PaseoThreadRunner, paseoThreadRunner } from "./runner.js";
|
|
9
|
+
export { TurnFolder, afterMessage, chat, finalText, isProviderError, toolSummary } from "./turn.js";
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { AgentInfo, Daemon } from "./daemon.ts";
|
|
2
|
+
import { type PaseoEvent, type ToolView } from "./turn.ts";
|
|
3
|
+
/**
|
|
4
|
+
* What the runner needs from the host's thread storage. The host keeps threads, messages and their ids; the
|
|
5
|
+
* runner only asks which agent a thread has and hands back each run's outcome.
|
|
6
|
+
*/
|
|
7
|
+
export interface ThreadStore<TResult = unknown> {
|
|
8
|
+
/** The thread's agent, or null when it has none yet. */
|
|
9
|
+
agentOf(threadId: string): Promise<string | null>;
|
|
10
|
+
/** Records the agent the runner started for the thread. */
|
|
11
|
+
setAgent(threadId: string, agentId: string): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Stores a run's answer: the text after the turn's last tool call and the calls' one-line summaries. Returns
|
|
14
|
+
* what `RUN_FINISHED.result` carries (assay: the stored message). `status` is `stopped` when the user stopped the
|
|
15
|
+
* turn and `error` when it failed after some text (then `error` says why).
|
|
16
|
+
*/
|
|
17
|
+
saveAnswer(threadId: string, run: {
|
|
18
|
+
runId: string;
|
|
19
|
+
agentId: string;
|
|
20
|
+
text: string;
|
|
21
|
+
tools: ToolView[];
|
|
22
|
+
status: "done" | "stopped" | "error";
|
|
23
|
+
error?: string;
|
|
24
|
+
}): Promise<TResult>;
|
|
25
|
+
/** Records why a run failed; a `RUN_ERROR` with the same message follows. */
|
|
26
|
+
saveError(threadId: string, run: {
|
|
27
|
+
runId: string;
|
|
28
|
+
agentId: string | null;
|
|
29
|
+
error: string;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export interface PaseoThreadRunnerOptions<TResult = unknown> {
|
|
33
|
+
daemon: Daemon;
|
|
34
|
+
/** Whether a thread's agent may take its next message (assay: not archived and working in the checkout). Required. */
|
|
35
|
+
filter: (agent: AgentInfo) => boolean;
|
|
36
|
+
store: ThreadStore<TResult>;
|
|
37
|
+
/** How long a run may go without an event before the daemon is asked how the agent is. Default 60 s. */
|
|
38
|
+
quietMs?: number;
|
|
39
|
+
/** How many timeline entries a re-tail reads. Default 300. */
|
|
40
|
+
tailLimit?: number;
|
|
41
|
+
/** Where errors of background checks go. Default `console.error`. */
|
|
42
|
+
log?: (message: string) => void;
|
|
43
|
+
}
|
|
44
|
+
/** One message to send: the host composes the text, the runner picks or starts the agent. */
|
|
45
|
+
export interface SendRequest {
|
|
46
|
+
threadId: string;
|
|
47
|
+
/** Our id for the user message (`clientMessageId` in the timeline) and the AG-UI `runId`. Default `jig-<uuid>`. */
|
|
48
|
+
runId?: string;
|
|
49
|
+
/** How to start an agent when the thread has none or its agent fails the filter. */
|
|
50
|
+
create: () => {
|
|
51
|
+
cwd: string;
|
|
52
|
+
title: string;
|
|
53
|
+
labels: Record<string, string>;
|
|
54
|
+
} | Promise<{
|
|
55
|
+
cwd: string;
|
|
56
|
+
title: string;
|
|
57
|
+
labels: Record<string, string>;
|
|
58
|
+
}>;
|
|
59
|
+
/** The text for the agent. `fresh` is true for an agent just started for this message (assay adds its brief then). */
|
|
60
|
+
compose: (agent: {
|
|
61
|
+
id: string;
|
|
62
|
+
fresh: boolean;
|
|
63
|
+
}) => string | Promise<string>;
|
|
64
|
+
/** Copied into `RUN_STARTED.metadata` (assay: the user message's id). */
|
|
65
|
+
metadata?: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
export interface RecoverRequest {
|
|
68
|
+
threadId: string;
|
|
69
|
+
runId: string;
|
|
70
|
+
agentId: string;
|
|
71
|
+
/** When the message was sent: a message not yet in the timeline within `graceMs` of it is left alone. */
|
|
72
|
+
sentAt?: Date | string | number;
|
|
73
|
+
graceMs?: number;
|
|
74
|
+
metadata?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
export type RecoverResult = "following" | "finished" | "failed" | "pending" | "busy";
|
|
77
|
+
/** The value of `CUSTOM {name:"READY"}`: a follower drops any run it was drawing; if `running`, `RUN_STARTED` and a replay follow. */
|
|
78
|
+
export interface ReadyValue {
|
|
79
|
+
threadId: string;
|
|
80
|
+
runId: string | null;
|
|
81
|
+
running: boolean;
|
|
82
|
+
}
|
|
83
|
+
export type Listener = (e: PaseoEvent) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Runs a thread's turns on Paseo agents, one run per thread, and streams each as `@ag-ui/core` events:
|
|
86
|
+
* `RUN_STARTED`, `TEXT_MESSAGE_*`, `TOOL_CALL_START/ARGS/END`, `RUN_FINISHED` / `RUN_ERROR`, and `CUSTOM READY`.
|
|
87
|
+
* A follower that joins mid-turn, and every follower after a gap in the daemon's stream, gets `READY` and a replay
|
|
88
|
+
* of the turn so far. From assay-016's `Asa` (deliver, watch, recover, fail); threads, prompts and routes stay
|
|
89
|
+
* in the host.
|
|
90
|
+
*/
|
|
91
|
+
export declare class PaseoThreadRunner<TResult = unknown> {
|
|
92
|
+
private runs;
|
|
93
|
+
private listeners;
|
|
94
|
+
private o;
|
|
95
|
+
private quietMs;
|
|
96
|
+
private tailLimit;
|
|
97
|
+
private log;
|
|
98
|
+
constructor(o: PaseoThreadRunnerOptions<TResult>);
|
|
99
|
+
running(threadId: string): boolean;
|
|
100
|
+
/** The run in progress on a thread: its id and agent. */
|
|
101
|
+
current(threadId: string): {
|
|
102
|
+
runId: string;
|
|
103
|
+
agentId: string | null;
|
|
104
|
+
} | null;
|
|
105
|
+
/** Follows a thread: `READY` at once, then `RUN_STARTED` and a replay when a run is in progress, then live events. */
|
|
106
|
+
listen(threadId: string, fn: Listener): () => void;
|
|
107
|
+
/**
|
|
108
|
+
* Sends a message on a thread: picks the thread's agent if it passes the filter, else starts one; subscribes,
|
|
109
|
+
* then sends. Resolves with the run id once the run is registered (`RUN_STARTED` emitted); delivery continues in
|
|
110
|
+
* the background and a failure ends in `RUN_ERROR`. Throws when the thread already has a run.
|
|
111
|
+
*/
|
|
112
|
+
send(req: SendRequest): string;
|
|
113
|
+
stop(threadId: string): Promise<{
|
|
114
|
+
stopping: boolean;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* After a restart: a message the host sent and has no answer for is looked up in its agent's timeline. A turn
|
|
118
|
+
* still running is followed (`following`); one that ended is stored (`finished` / `failed`); a message the
|
|
119
|
+
* agent never got fails, unless it was sent within `graceMs` (`pending`).
|
|
120
|
+
*/
|
|
121
|
+
recover(req: RecoverRequest): Promise<RecoverResult>;
|
|
122
|
+
close(): void;
|
|
123
|
+
private newRun;
|
|
124
|
+
private started;
|
|
125
|
+
/** `READY`, then the run so far when there is one. */
|
|
126
|
+
private resync;
|
|
127
|
+
private emit;
|
|
128
|
+
private watch;
|
|
129
|
+
private deliver;
|
|
130
|
+
private onEvent;
|
|
131
|
+
/** Folds one live event: drops what the timeline position says is already folded, ends the run on its turn's end. */
|
|
132
|
+
private apply;
|
|
133
|
+
/**
|
|
134
|
+
* Fills a gap in the stream (replacement, restored subscription, a lost connection, a new epoch): holds live
|
|
135
|
+
* events, re-tails, rebuilds the turn from the tail, then sends every follower `READY` and the replay and folds
|
|
136
|
+
* the held events the tail did not have. An ended turn is finished instead.
|
|
137
|
+
*/
|
|
138
|
+
private regap;
|
|
139
|
+
/** Reads the agent and its tail and rebuilds the run; a full page without our message is read again, deeper. With `keep`, a tail without our message is an error rather than "not found". */
|
|
140
|
+
private retail;
|
|
141
|
+
/** Finishes a turn the re-tail found ended, with the end event held meanwhile when there is one. */
|
|
142
|
+
private finishHeld;
|
|
143
|
+
/** Replaces the run's folder with the turn in `entries` (after our message); null when our message is not there. */
|
|
144
|
+
private rebuild;
|
|
145
|
+
/** Folds the held events; with `resync`, first sends every follower `READY` and the replay of the rebuilt turn. */
|
|
146
|
+
private drain;
|
|
147
|
+
/** A quiet or broken stream: the daemon says whether the turn ended while no event came. */
|
|
148
|
+
private check;
|
|
149
|
+
private cleanup;
|
|
150
|
+
private fail;
|
|
151
|
+
/** Ends the run: stores the answer and emits `RUN_FINISHED`, or fails it. Resolves true when an answer was stored. */
|
|
152
|
+
private finish;
|
|
153
|
+
}
|
|
154
|
+
/** `new PaseoThreadRunner(o)`, under the name the design uses. */
|
|
155
|
+
export declare const paseoThreadRunner: <TResult = unknown>(o: PaseoThreadRunnerOptions<TResult>) => PaseoThreadRunner<TResult>;
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { EventType } from "@ag-ui/core";
|
|
3
|
+
import { TurnFolder, afterMessage, isProviderError } from "./turn.js";
|
|
4
|
+
/**
|
|
5
|
+
* Runs a thread's turns on Paseo agents, one run per thread, and streams each as `@ag-ui/core` events:
|
|
6
|
+
* `RUN_STARTED`, `TEXT_MESSAGE_*`, `TOOL_CALL_START/ARGS/END`, `RUN_FINISHED` / `RUN_ERROR`, and `CUSTOM READY`.
|
|
7
|
+
* A follower that joins mid-turn, and every follower after a gap in the daemon's stream, gets `READY` and a replay
|
|
8
|
+
* of the turn so far. From assay-016's `Asa` (deliver, watch, recover, fail); threads, prompts and routes stay
|
|
9
|
+
* in the host.
|
|
10
|
+
*/
|
|
11
|
+
export class PaseoThreadRunner {
|
|
12
|
+
runs = new Map();
|
|
13
|
+
listeners = new Map();
|
|
14
|
+
o;
|
|
15
|
+
quietMs;
|
|
16
|
+
tailLimit;
|
|
17
|
+
log;
|
|
18
|
+
constructor(o) {
|
|
19
|
+
if (typeof o.filter !== "function")
|
|
20
|
+
throw new Error("paseoThreadRunner: `filter` is required");
|
|
21
|
+
this.o = o;
|
|
22
|
+
this.quietMs = o.quietMs ?? 60_000;
|
|
23
|
+
this.tailLimit = o.tailLimit ?? 300;
|
|
24
|
+
this.log = o.log ?? ((m) => console.error(m));
|
|
25
|
+
}
|
|
26
|
+
running(threadId) {
|
|
27
|
+
return this.runs.has(threadId);
|
|
28
|
+
}
|
|
29
|
+
/** The run in progress on a thread: its id and agent. */
|
|
30
|
+
current(threadId) {
|
|
31
|
+
const r = this.runs.get(threadId);
|
|
32
|
+
return r ? { runId: r.runId, agentId: r.agentId } : null;
|
|
33
|
+
}
|
|
34
|
+
/** Follows a thread: `READY` at once, then `RUN_STARTED` and a replay when a run is in progress, then live events. */
|
|
35
|
+
listen(threadId, fn) {
|
|
36
|
+
let set = this.listeners.get(threadId);
|
|
37
|
+
if (!set)
|
|
38
|
+
this.listeners.set(threadId, (set = new Set()));
|
|
39
|
+
set.add(fn);
|
|
40
|
+
const r = this.runs.get(threadId);
|
|
41
|
+
for (const e of this.resync(threadId, r))
|
|
42
|
+
safe(fn, e);
|
|
43
|
+
return () => {
|
|
44
|
+
set.delete(fn);
|
|
45
|
+
if (!set.size)
|
|
46
|
+
this.listeners.delete(threadId);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sends a message on a thread: picks the thread's agent if it passes the filter, else starts one; subscribes,
|
|
51
|
+
* then sends. Resolves with the run id once the run is registered (`RUN_STARTED` emitted); delivery continues in
|
|
52
|
+
* the background and a failure ends in `RUN_ERROR`. Throws when the thread already has a run.
|
|
53
|
+
*/
|
|
54
|
+
send(req) {
|
|
55
|
+
if (this.runs.has(req.threadId))
|
|
56
|
+
throw new Error(`thread ${req.threadId} already has a run in progress`);
|
|
57
|
+
const run = this.newRun(req.threadId, req.runId ?? `jig-${randomUUID()}`, null, req.metadata, false);
|
|
58
|
+
this.runs.set(run.threadId, run);
|
|
59
|
+
this.emit(run.threadId, this.started(run));
|
|
60
|
+
void this.deliver(req, run).catch((e) => this.fail(run, e.message));
|
|
61
|
+
return run.runId;
|
|
62
|
+
}
|
|
63
|
+
async stop(threadId) {
|
|
64
|
+
const r = this.runs.get(threadId);
|
|
65
|
+
if (!r?.agentId)
|
|
66
|
+
return { stopping: false };
|
|
67
|
+
r.stopping = true;
|
|
68
|
+
try {
|
|
69
|
+
await this.o.daemon.cancel(r.agentId);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
r.stopping = false;
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
return { stopping: true };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* After a restart: a message the host sent and has no answer for is looked up in its agent's timeline. A turn
|
|
79
|
+
* still running is followed (`following`); one that ended is stored (`finished` / `failed`); a message the
|
|
80
|
+
* agent never got fails, unless it was sent within `graceMs` (`pending`).
|
|
81
|
+
*/
|
|
82
|
+
async recover(req) {
|
|
83
|
+
if (this.runs.has(req.threadId))
|
|
84
|
+
return "busy";
|
|
85
|
+
const run = this.newRun(req.threadId, req.runId, req.agentId, req.metadata, true);
|
|
86
|
+
this.runs.set(run.threadId, run);
|
|
87
|
+
try {
|
|
88
|
+
// Hold events from the first one: the turn may end while we subscribe.
|
|
89
|
+
run.buffer = [];
|
|
90
|
+
run.unsub = await this.o.daemon.subscribe(req.agentId, (e) => this.onEvent(run, e));
|
|
91
|
+
const t = await this.retail(run);
|
|
92
|
+
if (!t.found) {
|
|
93
|
+
this.cleanup(run);
|
|
94
|
+
const sent = req.sentAt == null ? 0 : new Date(req.sentAt).getTime();
|
|
95
|
+
if (Date.now() - sent < (req.graceMs ?? 60_000))
|
|
96
|
+
return "pending";
|
|
97
|
+
await this.o.store.saveError(req.threadId, { runId: req.runId, agentId: req.agentId, error: "the agent never got the message" });
|
|
98
|
+
return "failed";
|
|
99
|
+
}
|
|
100
|
+
if (t.running) {
|
|
101
|
+
this.watch(run);
|
|
102
|
+
this.drain(run, true);
|
|
103
|
+
return "following";
|
|
104
|
+
}
|
|
105
|
+
return (await this.finishHeld(run)) ? "finished" : "failed";
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
this.cleanup(run);
|
|
109
|
+
throw e;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
close() {
|
|
113
|
+
for (const r of [...this.runs.values()])
|
|
114
|
+
this.cleanup(r);
|
|
115
|
+
}
|
|
116
|
+
// ---- internals
|
|
117
|
+
newRun(threadId, runId, agentId, metadata, ours) {
|
|
118
|
+
return { threadId, runId, agentId, metadata, turn: new TurnFolder(), ours, turnId: null, epoch: null, seq: -1, buffer: null, again: null, sentAt: null, stopping: false, unsub: null, last: Date.now(), watch: null, done: false };
|
|
119
|
+
}
|
|
120
|
+
started(run) {
|
|
121
|
+
return { type: EventType.RUN_STARTED, threadId: run.threadId, runId: run.runId, ...(run.metadata ? { metadata: run.metadata } : {}) };
|
|
122
|
+
}
|
|
123
|
+
/** `READY`, then the run so far when there is one. */
|
|
124
|
+
resync(threadId, run) {
|
|
125
|
+
const value = { threadId, runId: run?.runId ?? null, running: Boolean(run) };
|
|
126
|
+
const out = [{ type: EventType.CUSTOM, name: "READY", value }];
|
|
127
|
+
if (run)
|
|
128
|
+
out.push(this.started(run), ...run.turn.replay());
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
emit(threadId, e) {
|
|
132
|
+
for (const f of this.listeners.get(threadId) ?? [])
|
|
133
|
+
safe(f, e);
|
|
134
|
+
}
|
|
135
|
+
watch(run) {
|
|
136
|
+
if (run.watch || run.done)
|
|
137
|
+
return;
|
|
138
|
+
run.watch = setInterval(() => void this.check(run), Math.max(1000, this.quietMs / 2));
|
|
139
|
+
run.watch.unref();
|
|
140
|
+
}
|
|
141
|
+
async deliver(req, run) {
|
|
142
|
+
const d = this.o.daemon;
|
|
143
|
+
let agent = await this.o.store.agentOf(req.threadId);
|
|
144
|
+
if (agent) {
|
|
145
|
+
const a = await d.agent(agent).catch(() => null);
|
|
146
|
+
if (!a || !this.o.filter(a))
|
|
147
|
+
agent = null;
|
|
148
|
+
}
|
|
149
|
+
let fresh = false;
|
|
150
|
+
if (!agent) {
|
|
151
|
+
agent = await d.create(await req.create());
|
|
152
|
+
fresh = true;
|
|
153
|
+
await this.o.store.setAgent(req.threadId, agent);
|
|
154
|
+
}
|
|
155
|
+
run.agentId = agent;
|
|
156
|
+
const text = await req.compose({ id: agent, fresh });
|
|
157
|
+
if (run.done)
|
|
158
|
+
return;
|
|
159
|
+
run.unsub = await d.subscribe(agent, (e) => this.onEvent(run, e));
|
|
160
|
+
if (run.done)
|
|
161
|
+
return run.unsub();
|
|
162
|
+
this.watch(run);
|
|
163
|
+
await d.send(agent, text, run.runId);
|
|
164
|
+
run.sentAt = Date.now();
|
|
165
|
+
}
|
|
166
|
+
onEvent(run, e) {
|
|
167
|
+
if (run.done)
|
|
168
|
+
return;
|
|
169
|
+
run.last = Date.now();
|
|
170
|
+
if (e.type === "lost" || e.type === "replacement" || e.type === "subscription_restored") {
|
|
171
|
+
const resubscribe = e.type === "lost";
|
|
172
|
+
if (run.buffer)
|
|
173
|
+
return void (run.again = { resubscribe: resubscribe || Boolean(run.again?.resubscribe) });
|
|
174
|
+
return void this.regap(run, e.type === "lost" ? e.error : e.type, resubscribe);
|
|
175
|
+
}
|
|
176
|
+
if (run.buffer)
|
|
177
|
+
return void run.buffer.push(e);
|
|
178
|
+
this.apply(run, e);
|
|
179
|
+
}
|
|
180
|
+
/** Folds one live event: drops what the timeline position says is already folded, ends the run on its turn's end. */
|
|
181
|
+
apply(run, e) {
|
|
182
|
+
if (e.type === "timeline") {
|
|
183
|
+
if (e.seq != null && e.epoch) {
|
|
184
|
+
if (run.epoch && e.epoch !== run.epoch)
|
|
185
|
+
return void this.regap(run, "epoch changed");
|
|
186
|
+
if (e.epoch === run.epoch && e.seq <= run.seq)
|
|
187
|
+
return;
|
|
188
|
+
run.epoch = e.epoch;
|
|
189
|
+
run.seq = e.seq;
|
|
190
|
+
}
|
|
191
|
+
const it = e.item;
|
|
192
|
+
if (it.type === "user_message" && (it.clientMessageId === run.runId || it.messageId === run.runId)) {
|
|
193
|
+
run.ours = true;
|
|
194
|
+
if (e.turnId)
|
|
195
|
+
run.turnId = e.turnId;
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!run.ours)
|
|
199
|
+
return;
|
|
200
|
+
if (run.turnId && e.turnId && e.turnId !== run.turnId)
|
|
201
|
+
return;
|
|
202
|
+
for (const x of run.turn.push(it))
|
|
203
|
+
this.emit(run.threadId, x);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
// `turn_started` claims nothing: it may be someone else's turn. The daemon shows our message right after ours starts.
|
|
207
|
+
if (e.type !== "turn_completed" && e.type !== "turn_canceled" && e.type !== "turn_failed")
|
|
208
|
+
return;
|
|
209
|
+
if (!run.ours)
|
|
210
|
+
return;
|
|
211
|
+
if (run.turnId && e.turnId && e.turnId !== run.turnId)
|
|
212
|
+
return;
|
|
213
|
+
if (e.type === "turn_completed")
|
|
214
|
+
void this.finish(run, "done");
|
|
215
|
+
else if (e.type === "turn_canceled")
|
|
216
|
+
void this.finish(run, "stopped");
|
|
217
|
+
else
|
|
218
|
+
void this.finish(run, "error", e.error);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Fills a gap in the stream (replacement, restored subscription, a lost connection, a new epoch): holds live
|
|
222
|
+
* events, re-tails, rebuilds the turn from the tail, then sends every follower `READY` and the replay and folds
|
|
223
|
+
* the held events the tail did not have. An ended turn is finished instead.
|
|
224
|
+
*/
|
|
225
|
+
async regap(run, why, resubscribe = false) {
|
|
226
|
+
if (run.done || !run.agentId || run.buffer)
|
|
227
|
+
return;
|
|
228
|
+
run.buffer = [];
|
|
229
|
+
try {
|
|
230
|
+
if (resubscribe) {
|
|
231
|
+
run.unsub?.();
|
|
232
|
+
run.unsub = await this.o.daemon.subscribe(run.agentId, (e) => this.onEvent(run, e));
|
|
233
|
+
if (run.done)
|
|
234
|
+
return run.unsub();
|
|
235
|
+
}
|
|
236
|
+
const t = await this.retail(run, true);
|
|
237
|
+
if (run.done)
|
|
238
|
+
return;
|
|
239
|
+
if (t.found && !t.running)
|
|
240
|
+
return void (await this.finishHeld(run));
|
|
241
|
+
if (!t.found && !t.running && run.sentAt != null && Date.now() - run.sentAt >= this.quietMs)
|
|
242
|
+
return this.fail(run, "the agent never got the message");
|
|
243
|
+
run.last = Date.now();
|
|
244
|
+
this.drain(run, true);
|
|
245
|
+
}
|
|
246
|
+
catch (e) {
|
|
247
|
+
run.buffer = null;
|
|
248
|
+
this.fail(run, `${why}: ${e.message}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** Reads the agent and its tail and rebuilds the run; a full page without our message is read again, deeper. With `keep`, a tail without our message is an error rather than "not found". */
|
|
252
|
+
async retail(run, keep = false) {
|
|
253
|
+
const a = await this.o.daemon.agent(run.agentId);
|
|
254
|
+
let tail = await this.o.daemon.tail(run.agentId, this.tailLimit);
|
|
255
|
+
const has = () => tail.entries.some((x) => x.item.type === "user_message" && (x.item.clientMessageId === run.runId || x.item.messageId === run.runId));
|
|
256
|
+
if (!has() && tail.entries.length >= this.tailLimit)
|
|
257
|
+
tail = await this.o.daemon.tail(run.agentId, this.tailLimit * 10);
|
|
258
|
+
// A read that failed to reach our message must not replace what a claimed run already folded.
|
|
259
|
+
if (keep && run.ours && !has())
|
|
260
|
+
throw new Error("the turn is no longer in the timeline's tail");
|
|
261
|
+
const after = this.rebuild(run, tail.entries, tail.epoch, tail.seq);
|
|
262
|
+
// A later message in another turn means ours has ended, whatever the agent is doing now.
|
|
263
|
+
const next = Boolean(run.turnId && after?.some((x) => x.item.type === "user_message" && x.turnId && x.turnId !== run.turnId));
|
|
264
|
+
return { found: Boolean(after), running: a?.status === "running" && !next };
|
|
265
|
+
}
|
|
266
|
+
/** Finishes a turn the re-tail found ended, with the end event held meanwhile when there is one. */
|
|
267
|
+
finishHeld(run) {
|
|
268
|
+
const end = run.buffer?.find((e) => (e.type === "turn_completed" || e.type === "turn_canceled" || e.type === "turn_failed") && !(run.turnId && e.turnId && e.turnId !== run.turnId));
|
|
269
|
+
run.buffer = null;
|
|
270
|
+
if (end?.type === "turn_failed")
|
|
271
|
+
return this.finish(run, "error", end.error);
|
|
272
|
+
return this.finish(run, end?.type === "turn_canceled" || (!end && run.stopping) ? "stopped" : "done");
|
|
273
|
+
}
|
|
274
|
+
/** Replaces the run's folder with the turn in `entries` (after our message); null when our message is not there. */
|
|
275
|
+
rebuild(run, entries, epoch, seq) {
|
|
276
|
+
const i = entries.findIndex((x) => x.item.type === "user_message" && (x.item.clientMessageId === run.runId || x.item.messageId === run.runId));
|
|
277
|
+
if (epoch) {
|
|
278
|
+
run.epoch = epoch;
|
|
279
|
+
run.seq = seq ?? -1;
|
|
280
|
+
}
|
|
281
|
+
if (i < 0)
|
|
282
|
+
return null;
|
|
283
|
+
const mine = entries[i];
|
|
284
|
+
if (mine.turnId)
|
|
285
|
+
run.turnId = mine.turnId;
|
|
286
|
+
const after = afterMessage(entries, run.runId);
|
|
287
|
+
run.ours = true;
|
|
288
|
+
run.turn = TurnFolder.fromEntries(run.turnId ? after.filter((x) => !x.turnId || x.turnId === run.turnId) : after);
|
|
289
|
+
return after;
|
|
290
|
+
}
|
|
291
|
+
/** Folds the held events; with `resync`, first sends every follower `READY` and the replay of the rebuilt turn. */
|
|
292
|
+
drain(run, resync = false) {
|
|
293
|
+
const held = run.buffer ?? [];
|
|
294
|
+
const again = run.again;
|
|
295
|
+
run.buffer = null;
|
|
296
|
+
run.again = null;
|
|
297
|
+
if (again)
|
|
298
|
+
return void this.regap(run, "another gap", again.resubscribe);
|
|
299
|
+
if (resync)
|
|
300
|
+
for (const e of this.resync(run.threadId, run))
|
|
301
|
+
this.emit(run.threadId, e);
|
|
302
|
+
for (const e of held) {
|
|
303
|
+
if (run.done || run.buffer)
|
|
304
|
+
return;
|
|
305
|
+
this.apply(run, e);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/** A quiet or broken stream: the daemon says whether the turn ended while no event came. */
|
|
309
|
+
async check(run) {
|
|
310
|
+
if (run.done || !run.agentId || run.buffer)
|
|
311
|
+
return;
|
|
312
|
+
if (Date.now() - run.last < this.quietMs)
|
|
313
|
+
return;
|
|
314
|
+
try {
|
|
315
|
+
const a = await this.o.daemon.agent(run.agentId);
|
|
316
|
+
if (a?.status === "running" || run.done)
|
|
317
|
+
return void (run.last = Date.now());
|
|
318
|
+
await this.regap(run, "quiet");
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
this.log(`agent-paseo thread ${run.threadId}: check: ${e.message}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
cleanup(run) {
|
|
325
|
+
run.done = true;
|
|
326
|
+
run.unsub?.();
|
|
327
|
+
run.unsub = null;
|
|
328
|
+
if (run.watch)
|
|
329
|
+
clearInterval(run.watch);
|
|
330
|
+
if (this.runs.get(run.threadId) === run)
|
|
331
|
+
this.runs.delete(run.threadId);
|
|
332
|
+
}
|
|
333
|
+
fail(run, error) {
|
|
334
|
+
if (run.done)
|
|
335
|
+
return;
|
|
336
|
+
this.cleanup(run);
|
|
337
|
+
for (const e of run.turn.end())
|
|
338
|
+
this.emit(run.threadId, e);
|
|
339
|
+
void this.o.store.saveError(run.threadId, { runId: run.runId, agentId: run.agentId, error: error.slice(0, 2000) }).catch((e) => this.log(`agent-paseo thread ${run.threadId}: saveError: ${e.message}`));
|
|
340
|
+
this.emit(run.threadId, { type: EventType.RUN_ERROR, message: error, metadata: { threadId: run.threadId, runId: run.runId } });
|
|
341
|
+
}
|
|
342
|
+
/** Ends the run: stores the answer and emits `RUN_FINISHED`, or fails it. Resolves true when an answer was stored. */
|
|
343
|
+
async finish(run, status, error) {
|
|
344
|
+
if (run.done)
|
|
345
|
+
return false;
|
|
346
|
+
const text = run.turn.text();
|
|
347
|
+
if (status === "done" && !text)
|
|
348
|
+
return (this.fail(run, "the turn ended without an answer"), false);
|
|
349
|
+
if (status === "done" && isProviderError(text))
|
|
350
|
+
return (this.fail(run, text.slice(0, 400)), false);
|
|
351
|
+
if (status === "error" && !text)
|
|
352
|
+
return (this.fail(run, error ?? "the turn failed"), false);
|
|
353
|
+
if (status === "stopped" && !text)
|
|
354
|
+
return (this.fail(run, "stopped before an answer"), false);
|
|
355
|
+
this.cleanup(run);
|
|
356
|
+
for (const e of run.turn.end())
|
|
357
|
+
this.emit(run.threadId, e);
|
|
358
|
+
try {
|
|
359
|
+
const result = await this.o.store.saveAnswer(run.threadId, { runId: run.runId, agentId: run.agentId, text, tools: run.turn.toolList(), status, ...(error ? { error } : {}) });
|
|
360
|
+
this.emit(run.threadId, {
|
|
361
|
+
type: EventType.RUN_FINISHED,
|
|
362
|
+
threadId: run.threadId,
|
|
363
|
+
runId: run.runId,
|
|
364
|
+
result,
|
|
365
|
+
...(status === "stopped" ? { outcome: { type: "cancelled" }, metadata: { stopped: true } } : {}),
|
|
366
|
+
...(status === "error" ? { metadata: { error: error ?? "the turn failed" } } : {}),
|
|
367
|
+
});
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
catch (e) {
|
|
371
|
+
this.emit(run.threadId, { type: EventType.RUN_ERROR, message: e.message, metadata: { threadId: run.threadId, runId: run.runId } });
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function safe(f, e) {
|
|
377
|
+
try {
|
|
378
|
+
f(e);
|
|
379
|
+
}
|
|
380
|
+
catch { }
|
|
381
|
+
}
|
|
382
|
+
/** `new PaseoThreadRunner(o)`, under the name the design uses. */
|
|
383
|
+
export const paseoThreadRunner = (o) => new PaseoThreadRunner(o);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One live turn's state from the daemon's timeline items.
|
|
3
|
+
* `push` returns the AG-UI events to emit; `replay` rebuilds the turn so far for a
|
|
4
|
+
* subscriber that connects mid-turn. All types come from `@ag-ui/core`; non-standard
|
|
5
|
+
* fields go in `metadata` (tool `summary`, turn `stopped`).
|
|
6
|
+
*
|
|
7
|
+
* From assay-016's `shape.ts` (`Turn`, now `TurnFolder`, plus `chat`, `afterMessage`, `finalText`, `toolSummary`,
|
|
8
|
+
* `isProviderError`). The events are `@ag-ui/core` types instead of assay's hand-rolled union.
|
|
9
|
+
*/
|
|
10
|
+
import type { CustomEvent, RunErrorEvent, RunFinishedEvent, RunStartedEvent, TextMessageContentEvent, TextMessageEndEvent, TextMessageStartEvent, ToolCallArgsEvent, ToolCallEndEvent, ToolCallStartEvent } from "@ag-ui/core";
|
|
11
|
+
/** One timeline entry as the daemon sends it (`fetchAgentTimeline` projected, or a live event's item). */
|
|
12
|
+
export interface TimelineItem {
|
|
13
|
+
type: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
messageId?: string;
|
|
16
|
+
clientMessageId?: string;
|
|
17
|
+
callId?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
status?: string;
|
|
20
|
+
detail?: {
|
|
21
|
+
type?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
error?: unknown;
|
|
25
|
+
message?: string;
|
|
26
|
+
level?: string;
|
|
27
|
+
agentMessage?: {
|
|
28
|
+
text?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface TimelineEntry {
|
|
32
|
+
timestamp?: string;
|
|
33
|
+
item: TimelineItem;
|
|
34
|
+
/** The turn the item belongs to, when the daemon says. */
|
|
35
|
+
turnId?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare const isProviderError: (text: string) => boolean;
|
|
38
|
+
export interface ToolView {
|
|
39
|
+
name: string;
|
|
40
|
+
summary: string | null;
|
|
41
|
+
status: string | null;
|
|
42
|
+
}
|
|
43
|
+
export declare function toolSummary(item: TimelineItem): string | null;
|
|
44
|
+
export type ChatItem = {
|
|
45
|
+
kind: "message";
|
|
46
|
+
at: string | null;
|
|
47
|
+
role: "user" | "assistant";
|
|
48
|
+
text: string;
|
|
49
|
+
error: boolean;
|
|
50
|
+
messageId?: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "tools";
|
|
53
|
+
at: string | null;
|
|
54
|
+
count: number;
|
|
55
|
+
last: ToolView | null;
|
|
56
|
+
tools: ToolView[];
|
|
57
|
+
} | {
|
|
58
|
+
kind: "notice";
|
|
59
|
+
at: string | null;
|
|
60
|
+
level: string;
|
|
61
|
+
text: string;
|
|
62
|
+
};
|
|
63
|
+
export declare function chat(entries: TimelineEntry[]): ChatItem[];
|
|
64
|
+
export declare function afterMessage(entries: TimelineEntry[], clientId: string): TimelineEntry[] | null;
|
|
65
|
+
export declare function finalText(items: ChatItem[]): string;
|
|
66
|
+
/** What `TurnFolder` emits for timeline items. */
|
|
67
|
+
export type FoldedEvent = TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent;
|
|
68
|
+
/** The union of AG-UI events this part emits. Never TOOL_CALL_RESULT. */
|
|
69
|
+
export type PaseoEvent = RunStartedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent | RunFinishedEvent | RunErrorEvent | CustomEvent;
|
|
70
|
+
/**
|
|
71
|
+
* Folds one turn's daemon timeline items into typed `@ag-ui/core` events.
|
|
72
|
+
*
|
|
73
|
+
* Non-standard fields go in `metadata`:
|
|
74
|
+
* - `TOOL_CALL_START` / `TOOL_CALL_ARGS`: `metadata.summary`
|
|
75
|
+
* - `TOOL_CALL_END`: `metadata.status`
|
|
76
|
+
*
|
|
77
|
+
* - an assistant message is closed (`TEXT_MESSAGE_END`) when the next message or tool call starts, or at `end()`
|
|
78
|
+
*
|
|
79
|
+
* Live assistant items are deltas under one message id; projected history items carry the whole text. Both fold
|
|
80
|
+
* the same way, so a folder rebuilt from the projected tail (`fromEntries`) holds what the live one would.
|
|
81
|
+
*/
|
|
82
|
+
export declare class TurnFolder {
|
|
83
|
+
private texts;
|
|
84
|
+
private tools;
|
|
85
|
+
private order;
|
|
86
|
+
private anon;
|
|
87
|
+
/** The assistant message still open (no TEXT_MESSAGE_END sent yet). */
|
|
88
|
+
private open;
|
|
89
|
+
/** TEXT_MESSAGE_END for the open message, if any. */
|
|
90
|
+
private close;
|
|
91
|
+
push(item: TimelineItem): FoldedEvent[];
|
|
92
|
+
/** At the turn's end: TEXT_MESSAGE_END for the message still open. */
|
|
93
|
+
end(): TextMessageEndEvent[];
|
|
94
|
+
/** The events that rebuild the turn so far, for a follower that joins mid-turn or after a gap. */
|
|
95
|
+
replay(): FoldedEvent[];
|
|
96
|
+
text(): string;
|
|
97
|
+
toolList(): ToolView[];
|
|
98
|
+
/** Reconstruct a TurnFolder from a projected tail slice (afterMessage). Used in recovery. */
|
|
99
|
+
static fromEntries(entries: TimelineEntry[]): TurnFolder;
|
|
100
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One live turn's state from the daemon's timeline items.
|
|
3
|
+
* `push` returns the AG-UI events to emit; `replay` rebuilds the turn so far for a
|
|
4
|
+
* subscriber that connects mid-turn. All types come from `@ag-ui/core`; non-standard
|
|
5
|
+
* fields go in `metadata` (tool `summary`, turn `stopped`).
|
|
6
|
+
*
|
|
7
|
+
* From assay-016's `shape.ts` (`Turn`, now `TurnFolder`, plus `chat`, `afterMessage`, `finalText`, `toolSummary`,
|
|
8
|
+
* `isProviderError`). The events are `@ag-ui/core` types instead of assay's hand-rolled union.
|
|
9
|
+
*/
|
|
10
|
+
import { EventType } from "@ag-ui/core";
|
|
11
|
+
const clip = (s, n) => s == null ? null : s.length > n ? `${s.slice(0, n - 1)}…` : s;
|
|
12
|
+
const TOOL_SUMMARY_CHARS = 160;
|
|
13
|
+
const ERROR_CHARS = 400;
|
|
14
|
+
const GROUP_TOOLS = 60;
|
|
15
|
+
const PROVIDER_ERRORS = [/^API Error\b/, /^\[System Error\]/, /^Error: [A-Z]\w*Error\b/];
|
|
16
|
+
export const isProviderError = (text) => PROVIDER_ERRORS.some((r) => r.test(text.trim()));
|
|
17
|
+
export function toolSummary(item) {
|
|
18
|
+
const d = item.detail ?? {};
|
|
19
|
+
const field = {
|
|
20
|
+
shell: ["command"],
|
|
21
|
+
read: ["filePath"],
|
|
22
|
+
edit: ["filePath"],
|
|
23
|
+
write: ["filePath"],
|
|
24
|
+
search: ["query"],
|
|
25
|
+
fetch: ["url"],
|
|
26
|
+
sub_agent: ["description", "subAgentType"],
|
|
27
|
+
plain_text: ["label", "text"],
|
|
28
|
+
plan: ["text"],
|
|
29
|
+
};
|
|
30
|
+
let raw = null;
|
|
31
|
+
for (const k of field[d.type ?? ""] ?? [])
|
|
32
|
+
if (typeof d[k] === "string" && d[k]) {
|
|
33
|
+
raw = d[k];
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
const line = raw?.split("\n").map((s) => s.trim()).find(Boolean) ?? null;
|
|
37
|
+
return clip(line, TOOL_SUMMARY_CHARS);
|
|
38
|
+
}
|
|
39
|
+
export function chat(entries) {
|
|
40
|
+
const out = [];
|
|
41
|
+
let group = null;
|
|
42
|
+
let calls = new Map();
|
|
43
|
+
for (const { item, timestamp } of entries) {
|
|
44
|
+
const at = timestamp ?? null;
|
|
45
|
+
const text = item.text?.trim();
|
|
46
|
+
if ((item.type === "user_message" || item.type === "assistant_message") && text) {
|
|
47
|
+
group = null;
|
|
48
|
+
const assistant = item.type === "assistant_message";
|
|
49
|
+
const id = assistant ? item.messageId : (item.clientMessageId ?? item.messageId);
|
|
50
|
+
out.push({ kind: "message", at, role: assistant ? "assistant" : "user", text, error: assistant && isProviderError(text), ...(id ? { messageId: id } : {}) });
|
|
51
|
+
}
|
|
52
|
+
else if (item.type === "tool_call" || item.type === "reasoning" || item.type === "todo") {
|
|
53
|
+
if (!group) {
|
|
54
|
+
group = { kind: "tools", at, count: 0, last: null, tools: [] };
|
|
55
|
+
calls = new Map();
|
|
56
|
+
out.push(group);
|
|
57
|
+
}
|
|
58
|
+
if (item.type !== "tool_call" || item.agentMessage)
|
|
59
|
+
continue;
|
|
60
|
+
const view = { name: clip(item.name, 80) ?? "tool", summary: toolSummary(item), status: item.status ?? null };
|
|
61
|
+
const seen = item.callId ? calls.get(item.callId) : undefined;
|
|
62
|
+
if (seen !== undefined)
|
|
63
|
+
group.tools[seen] = view;
|
|
64
|
+
else {
|
|
65
|
+
if (item.callId)
|
|
66
|
+
calls.set(item.callId, group.tools.length);
|
|
67
|
+
group.tools.push(view);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if ((item.type === "error" || item.type === "notification") && item.message?.trim()) {
|
|
71
|
+
group = null;
|
|
72
|
+
out.push({ kind: "notice", at, level: item.type === "error" ? "error" : (item.level ?? "info"), text: clip(item.message.trim(), ERROR_CHARS) });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const x of out) {
|
|
76
|
+
if (x.kind !== "tools")
|
|
77
|
+
continue;
|
|
78
|
+
x.count = x.tools.length;
|
|
79
|
+
x.last = x.tools.at(-1) ?? null;
|
|
80
|
+
x.tools = x.tools.slice(-GROUP_TOOLS);
|
|
81
|
+
}
|
|
82
|
+
return out.filter((x) => x.kind !== "tools" || x.count > 0);
|
|
83
|
+
}
|
|
84
|
+
export function afterMessage(entries, clientId) {
|
|
85
|
+
const i = entries.findIndex((e) => e.item.type === "user_message" && (e.item.clientMessageId === clientId || e.item.messageId === clientId));
|
|
86
|
+
return i < 0 ? null : entries.slice(i + 1);
|
|
87
|
+
}
|
|
88
|
+
export function finalText(items) {
|
|
89
|
+
const parts = [];
|
|
90
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
91
|
+
const x = items[i];
|
|
92
|
+
if (x.kind === "message" && x.role === "assistant")
|
|
93
|
+
parts.unshift(x.text);
|
|
94
|
+
else if (x.kind === "tools" && parts.length)
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
return parts.join("\n\n");
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Folds one turn's daemon timeline items into typed `@ag-ui/core` events.
|
|
101
|
+
*
|
|
102
|
+
* Non-standard fields go in `metadata`:
|
|
103
|
+
* - `TOOL_CALL_START` / `TOOL_CALL_ARGS`: `metadata.summary`
|
|
104
|
+
* - `TOOL_CALL_END`: `metadata.status`
|
|
105
|
+
*
|
|
106
|
+
* - an assistant message is closed (`TEXT_MESSAGE_END`) when the next message or tool call starts, or at `end()`
|
|
107
|
+
*
|
|
108
|
+
* Live assistant items are deltas under one message id; projected history items carry the whole text. Both fold
|
|
109
|
+
* the same way, so a folder rebuilt from the projected tail (`fromEntries`) holds what the live one would.
|
|
110
|
+
*/
|
|
111
|
+
export class TurnFolder {
|
|
112
|
+
texts = new Map();
|
|
113
|
+
tools = new Map();
|
|
114
|
+
order = [];
|
|
115
|
+
anon = 0;
|
|
116
|
+
/** The assistant message still open (no TEXT_MESSAGE_END sent yet). */
|
|
117
|
+
open = null;
|
|
118
|
+
/** TEXT_MESSAGE_END for the open message, if any. */
|
|
119
|
+
close() {
|
|
120
|
+
if (!this.open)
|
|
121
|
+
return [];
|
|
122
|
+
const messageId = this.open;
|
|
123
|
+
this.open = null;
|
|
124
|
+
return [{ type: EventType.TEXT_MESSAGE_END, messageId }];
|
|
125
|
+
}
|
|
126
|
+
push(item) {
|
|
127
|
+
if (item.type === "assistant_message" && item.text) {
|
|
128
|
+
const id = item.messageId ?? this.open ?? `m${this.anon++}`;
|
|
129
|
+
const out = [];
|
|
130
|
+
if (!this.texts.has(id)) {
|
|
131
|
+
out.push(...this.close());
|
|
132
|
+
this.open = id;
|
|
133
|
+
this.texts.set(id, "");
|
|
134
|
+
this.order.push({ kind: "text", id });
|
|
135
|
+
out.push({ type: EventType.TEXT_MESSAGE_START, messageId: id, role: "assistant" });
|
|
136
|
+
}
|
|
137
|
+
this.texts.set(id, this.texts.get(id) + item.text);
|
|
138
|
+
out.push({ type: EventType.TEXT_MESSAGE_CONTENT, messageId: id, delta: item.text });
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
if (item.type === "tool_call" && !item.agentMessage) {
|
|
142
|
+
const id = item.callId ?? `t${this.anon++}`;
|
|
143
|
+
const view = { name: clip(item.name, 80) ?? "tool", summary: toolSummary(item), status: item.status ?? null };
|
|
144
|
+
const ended = view.status === "completed" || view.status === "failed" || view.status === "canceled";
|
|
145
|
+
const cur = this.tools.get(id);
|
|
146
|
+
const out = [];
|
|
147
|
+
if (!cur) {
|
|
148
|
+
out.push(...this.close());
|
|
149
|
+
this.tools.set(id, { ...view, done: false });
|
|
150
|
+
this.order.push({ kind: "tool", id });
|
|
151
|
+
out.push({ type: EventType.TOOL_CALL_START, toolCallId: id, toolCallName: view.name, metadata: view.summary != null ? { summary: view.summary } : undefined });
|
|
152
|
+
}
|
|
153
|
+
else if (view.summary && view.summary !== cur.summary) {
|
|
154
|
+
out.push({ type: EventType.TOOL_CALL_ARGS, toolCallId: id, delta: JSON.stringify({ summary: view.summary }) });
|
|
155
|
+
}
|
|
156
|
+
const t = this.tools.get(id);
|
|
157
|
+
Object.assign(t, { summary: view.summary ?? t.summary, status: view.status });
|
|
158
|
+
if (ended && !t.done) {
|
|
159
|
+
t.done = true;
|
|
160
|
+
out.push({ type: EventType.TOOL_CALL_END, toolCallId: id, metadata: { status: view.status ?? "completed" } });
|
|
161
|
+
}
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
/** At the turn's end: TEXT_MESSAGE_END for the message still open. */
|
|
167
|
+
end() {
|
|
168
|
+
return this.close();
|
|
169
|
+
}
|
|
170
|
+
/** The events that rebuild the turn so far, for a follower that joins mid-turn or after a gap. */
|
|
171
|
+
replay() {
|
|
172
|
+
const out = [];
|
|
173
|
+
for (const x of this.order) {
|
|
174
|
+
if (x.kind === "text") {
|
|
175
|
+
out.push({ type: EventType.TEXT_MESSAGE_START, messageId: x.id, role: "assistant" });
|
|
176
|
+
out.push({ type: EventType.TEXT_MESSAGE_CONTENT, messageId: x.id, delta: this.texts.get(x.id) });
|
|
177
|
+
if (x.id !== this.open)
|
|
178
|
+
out.push({ type: EventType.TEXT_MESSAGE_END, messageId: x.id });
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const t = this.tools.get(x.id);
|
|
182
|
+
out.push({ type: EventType.TOOL_CALL_START, toolCallId: x.id, toolCallName: t.name, metadata: t.summary != null ? { summary: t.summary } : undefined });
|
|
183
|
+
if (t.done)
|
|
184
|
+
out.push({ type: EventType.TOOL_CALL_END, toolCallId: x.id, metadata: { status: t.status ?? "completed" } });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
text() {
|
|
190
|
+
const parts = [];
|
|
191
|
+
for (let i = this.order.length - 1; i >= 0; i--) {
|
|
192
|
+
const x = this.order[i];
|
|
193
|
+
if (x.kind === "tool") {
|
|
194
|
+
if (parts.length)
|
|
195
|
+
break;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
parts.unshift(this.texts.get(x.id).trim());
|
|
199
|
+
}
|
|
200
|
+
return parts.filter(Boolean).join("\n\n");
|
|
201
|
+
}
|
|
202
|
+
toolList() {
|
|
203
|
+
return [...this.tools.values()].map(({ name, summary, status }) => ({ name, summary, status })).slice(-GROUP_TOOLS);
|
|
204
|
+
}
|
|
205
|
+
/** Reconstruct a TurnFolder from a projected tail slice (afterMessage). Used in recovery. */
|
|
206
|
+
static fromEntries(entries) {
|
|
207
|
+
const f = new TurnFolder();
|
|
208
|
+
for (const x of entries)
|
|
209
|
+
f.push(x.item);
|
|
210
|
+
return f;
|
|
211
|
+
}
|
|
212
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightblues/jig",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Reusable parts for my apps: agent runtimes (Paseo, pi) that speak AG-UI, a thin thread-following client, and more as they prove reusable.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,16 +24,35 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"default": "./dist/index.js"
|
|
26
26
|
},
|
|
27
|
+
"./agent-paseo": {
|
|
28
|
+
"types": "./dist/agent-paseo/index.d.ts",
|
|
29
|
+
"default": "./dist/agent-paseo/index.js"
|
|
30
|
+
},
|
|
27
31
|
"./package.json": "./package.json"
|
|
28
32
|
},
|
|
29
33
|
"scripts": {
|
|
30
34
|
"build": "tsc -p tsconfig.build.json",
|
|
31
35
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
32
36
|
"test": "node --test --experimental-strip-types 'test/**/*.test.ts'",
|
|
37
|
+
"test:contract": "node --test --experimental-strip-types 'test/agent-paseo-contract.ts'",
|
|
33
38
|
"prepack": "npm run build"
|
|
34
39
|
},
|
|
35
40
|
"devDependencies": {
|
|
41
|
+
"@ag-ui/core": "1.0.5",
|
|
42
|
+
"@getpaseo/client": "0.16.1",
|
|
36
43
|
"@types/node": "^24.0.0",
|
|
37
44
|
"typescript": "^5.9.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@ag-ui/core": "^1.0.5",
|
|
48
|
+
"@getpaseo/client": "0.16.1"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@ag-ui/core": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"@getpaseo/client": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
38
57
|
}
|
|
39
58
|
}
|