@a-dray/aglib 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,8 @@ export declare function toolFingerprint(context: HarnessContext): string;
36
36
  * conversation and resuming it would answer from a past that is not the log's.
37
37
  * Then the session starts fresh, opened with the conversation so far rendered
38
38
  * as text: the vendor cannot be handed our messages as its own, and a summary
39
- * of them is the honest substitute. `fresh` asks for that start whatever the
39
+ * of them is the honest substitute. A long conversation is opened with its
40
+ * most recent part (`TRANSCRIPT_CHARS`). `fresh` asks for that start whatever the
40
41
  * log says, for a session the log names and the vendor no longer has; a
41
42
  * `fingerprint` that differs from the recorded one asks for it too.
42
43
  */
@@ -51,8 +52,15 @@ export declare function opening(context: HarnessContext, provider: string, optio
51
52
  export declare function arrivals(context: HarnessContext, shown: Set<number>): Content[];
52
53
  /** Seqs of this run's inputs that `opening` already put in the prompt. */
53
54
  export declare function openingInputs(context: HarnessContext): Set<number>;
55
+ /**
56
+ * The most of a conversation a new vendor session is opened with. A vendor
57
+ * refuses an input past a fixed size (Codex at 1,048,576 characters), and the
58
+ * model has to fit it in its window with room to work, so the transcript keeps
59
+ * what is most recent and says how much came before.
60
+ */
61
+ export declare const TRANSCRIPT_CHARS = 200000;
54
62
  /** A readable transcript. Tool output is cut, because the next turns can read again what matters. */
55
- export declare function transcriptText(messages: readonly Message[]): string;
63
+ export declare function transcriptText(messages: readonly Message[], maxChars?: number): string;
56
64
  /** Text, with media named rather than dropped silently. */
57
65
  export declare function described(content: Content): string;
58
66
  /**
@@ -37,7 +37,8 @@ export function toolFingerprint(context) {
37
37
  * conversation and resuming it would answer from a past that is not the log's.
38
38
  * Then the session starts fresh, opened with the conversation so far rendered
39
39
  * as text: the vendor cannot be handed our messages as its own, and a summary
40
- * of them is the honest substitute. `fresh` asks for that start whatever the
40
+ * of them is the honest substitute. A long conversation is opened with its
41
+ * most recent part (`TRANSCRIPT_CHARS`). `fresh` asks for that start whatever the
41
42
  * log says, for a session the log names and the vendor no longer has; a
42
43
  * `fingerprint` that differs from the recorded one asks for it too.
43
44
  */
@@ -83,21 +84,43 @@ function earlier(messages, current) {
83
84
  return out;
84
85
  }
85
86
  const RESULT_CHARS = 4_000;
87
+ /**
88
+ * The most of a conversation a new vendor session is opened with. A vendor
89
+ * refuses an input past a fixed size (Codex at 1,048,576 characters), and the
90
+ * model has to fit it in its window with room to work, so the transcript keeps
91
+ * what is most recent and says how much came before.
92
+ */
93
+ export const TRANSCRIPT_CHARS = 200_000;
86
94
  /** A readable transcript. Tool output is cut, because the next turns can read again what matters. */
87
- export function transcriptText(messages) {
88
- return messages.map((message) => {
89
- if (message.role === "user")
90
- return `[user]\n${described(message.content)}`;
91
- if (message.role === "assistant") {
92
- const calls = (message.calls ?? []).map((call) => `→ ${call.name}(${call.arguments})`);
93
- return [`[assistant]`, textOf(message.content), ...calls].filter(Boolean).join("\n");
95
+ export function transcriptText(messages, maxChars = TRANSCRIPT_CHARS) {
96
+ const texts = messages.map(messageText).filter(Boolean);
97
+ const kept = [];
98
+ let room = maxChars;
99
+ for (let index = texts.length - 1; index >= 0; index -= 1) {
100
+ const text = texts[index];
101
+ if (text.length > room) {
102
+ if (!kept.length)
103
+ kept.unshift(`${text.slice(0, room)}…`);
104
+ break;
94
105
  }
95
- if (message.role === "tool") {
96
- const text = described(message.content);
97
- return `[tool result${message.isError ? ", error" : ""}]\n${text.length > RESULT_CHARS ? `${text.slice(0, RESULT_CHARS)}…` : text}`;
98
- }
99
- return "";
100
- }).filter(Boolean).join("\n\n");
106
+ kept.unshift(text);
107
+ room -= text.length + 2;
108
+ }
109
+ const omitted = texts.length - kept.length;
110
+ return [...(omitted ? [`[${omitted} earlier ${omitted === 1 ? "message is" : "messages are"} not shown]`] : []), ...kept].join("\n\n");
111
+ }
112
+ function messageText(message) {
113
+ if (message.role === "user")
114
+ return `[user]\n${described(message.content)}`;
115
+ if (message.role === "assistant") {
116
+ const calls = (message.calls ?? []).map((call) => `→ ${call.name}(${call.arguments})`);
117
+ return [`[assistant]`, textOf(message.content), ...calls].filter(Boolean).join("\n");
118
+ }
119
+ if (message.role === "tool") {
120
+ const text = described(message.content);
121
+ return `[tool result${message.isError ? ", error" : ""}]\n${text.length > RESULT_CHARS ? `${text.slice(0, RESULT_CHARS)}…` : text}`;
122
+ }
123
+ return "";
101
124
  }
102
125
  /** Text, with media named rather than dropped silently. */
103
126
  export function described(content) {
@@ -1 +1 @@
1
- {"version":3,"file":"vendor.js","sourceRoot":"","sources":["../../../src/harness/adapters/vendor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C;;;;;;;;;;GAUG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,OAAe,EAAE,WAAoB;IAClF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAgB,EAAE,CAAC;AACpG,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,OAAuB;IACrD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACzH,IAAI,IAAI,GAAG,UAAU,CAAC;IACtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;QAAE,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,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,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,SAAS,CAAU,EAAE,CAAC;QAC7G,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { HarnessContext } from \"../harness.js\";\nimport type { Content, ContentPart } from \"../../content.js\";\nimport { textOf } from \"../../content.js\";\nimport type { Delivery, Entry, Stored, ToolCall, ToolResult, Usage } from \"../../session/entry.js\";\nimport type { Message } from \"../../session/messages.js\";\nimport type { JsonValue } from \"../../json.js\";\n\n/**\n * What a vendor-loop harness shares: an agent process that owns its own\n * context and model calls, running *our* tools and nothing of its own.\n *\n * Two facts hold for every such adapter and are why this file exists rather\n * than two copies of it. The vendor's conversation lives in the vendor's own\n * session store, so continuing it means naming that session; and our log has\n * to say what happened in a shape a native model could take over from, because\n * an owner who switches an instance from a subscription to an API key expects\n * the conversation to carry on.\n */\n\n/**\n * The vendor session a run continues, recorded on the run's final assistant\n * entry. `fingerprint` names what the session was opened with that cannot be\n * changed on resume — a vendor that fixes the tool list at session start is\n * resumed only while the list is the same.\n */\nexport function sessionState(provider: string, session: string, fingerprint?: string) {\n return { provider, items: [{ session, ...(fingerprint ? { fingerprint } : {}) }] as JsonValue[] };\n}\n\n/** A stable name for a tool list, by what the model is shown of it. */\nexport function toolFingerprint(context: HarnessContext): string {\n const text = JSON.stringify((context.tools?.list() ?? []).map((tool) => [tool.name, tool.description, tool.parameters]));\n let hash = 2166136261;\n for (let index = 0; index < text.length; index += 1) hash = Math.imul(hash ^ text.charCodeAt(index), 16777619) >>> 0;\n return hash.toString(16);\n}\n\n/**\n * Where this activation starts: the vendor session to resume, and the words to\n * open it with.\n *\n * A session is resumed only when the latest assistant entry in the log was\n * written by this provider and names it. Any later assistant entry means\n * another model spoke since, so the vendor's copy is missing part of the\n * conversation and resuming it would answer from a past that is not the log's.\n * Then the session starts fresh, opened with the conversation so far rendered\n * as text: the vendor cannot be handed our messages as its own, and a summary\n * of them is the honest substitute. `fresh` asks for that start whatever the\n * log says, for a session the log names and the vendor no longer has; a\n * `fingerprint` that differs from the recorded one asks for it too.\n */\nexport function opening(context: HarnessContext, provider: string, options: { fresh?: boolean; fingerprint?: string } = {}): { resume?: string; prompt: Content } {\n const entries = context.entries();\n const last = entries.findLast((entry) => entry.type === \"assistant\");\n const state = !options.fresh && last?.type === \"assistant\" && last.providerState?.provider === provider ? last.providerState.items[0] : undefined;\n const fields = state && typeof state === \"object\" && !Array.isArray(state) ? state as { readonly [key: string]: JsonValue } : {};\n const session = typeof fields[\"session\"] === \"string\" && fields[\"fingerprint\"] === options.fingerprint ? fields[\"session\"] : undefined;\n const turn = context.context?.turn ? [`<turn-context>\\n${context.context.turn}\\n</turn-context>`] : [];\n if (session) {\n const since = entries.filter((entry): entry is Stored<Extract<Entry, { type: \"run.started\" | \"hook.input\" }>> =>\n (entry.type === \"run.started\" || entry.type === \"hook.input\") && entry.seq > last!.seq);\n return { resume: session, prompt: join([...turn, ...since.map((entry) => entry.input)]) };\n }\n const current = entries.filter((entry) => entry.type === \"run.started\" && entry.runId === context.runId);\n const before = earlier(context.history(), current.length);\n const transcript = before.length ? [`<conversation-so-far>\\n${transcriptText(before)}\\n</conversation-so-far>`] : [];\n return { prompt: join([...transcript, ...turn, ...current.map((entry) => (entry as Extract<Entry, { type: \"run.started\" }>).input)]) };\n}\n\n/** Inputs folded into this run by `drain` that the vendor has not been shown yet. */\nexport function arrivals(context: HarnessContext, shown: Set<number>): Content[] {\n return context.entries()\n .filter((entry) => entry.type === \"run.started\" && entry.runId === context.runId && !shown.has(entry.seq))\n .map((entry) => { shown.add(entry.seq); return (entry as Extract<Entry, { type: \"run.started\" }>).input; });\n}\n\n/** Seqs of this run's inputs that `opening` already put in the prompt. */\nexport function openingInputs(context: HarnessContext): Set<number> {\n return new Set(context.entries().filter((entry) => entry.type === \"run.started\" && entry.runId === context.runId).map((entry) => entry.seq));\n}\n\n/**\n * The conversation before this run, as the model was shown it: the projection\n * minus its system messages (the vendor gets ours as its own instructions) and\n * minus the inputs this run is about to send.\n */\nfunction earlier(messages: readonly Message[], current: number): Message[] {\n const body = messages.filter((message) => message.role !== \"system\");\n let drop = current;\n const out = [...body];\n while (drop > 0 && out.length && out[out.length - 1]!.role === \"user\") { out.pop(); drop -= 1; }\n return out;\n}\n\nconst RESULT_CHARS = 4_000;\n\n/** A readable transcript. Tool output is cut, because the next turns can read again what matters. */\nexport function transcriptText(messages: readonly Message[]): string {\n return messages.map((message) => {\n if (message.role === \"user\") return `[user]\\n${described(message.content)}`;\n if (message.role === \"assistant\") {\n const calls = (message.calls ?? []).map((call) => `→ ${call.name}(${call.arguments})`);\n return [`[assistant]`, textOf(message.content), ...calls].filter(Boolean).join(\"\\n\");\n }\n if (message.role === \"tool\") {\n const text = described(message.content);\n return `[tool result${message.isError ? \", error\" : \"\"}]\\n${text.length > RESULT_CHARS ? `${text.slice(0, RESULT_CHARS)}…` : text}`;\n }\n return \"\";\n }).filter(Boolean).join(\"\\n\\n\");\n}\n\n/** Text, with media named rather than dropped silently. */\nexport function described(content: Content): string {\n if (typeof content === \"string\") return content;\n return content.map((part) => {\n if (part.type === \"text\") return part.text;\n if (part.type === \"image\") return `[image ${part.mediaType}]`;\n if (part.type === \"file\") return `[file ${part.name ?? \"\"} ${part.mediaType}]`.replace(\" \", \" \");\n return \"\";\n }).filter(Boolean).join(\"\\n\");\n}\n\nfunction join(parts: readonly Content[]): Content {\n const out: ContentPart[] = [];\n for (const part of parts) {\n if (typeof part === \"string\") { if (part) out.push({ type: \"text\", text: part }); }\n else out.push(...part);\n }\n return out.every((part) => part.type === \"text\") ? out.map((part) => (part as { text: string }).text).join(\"\\n\\n\") : out;\n}\n\n/**\n * Runs our tools for a vendor's loop, one call at a time, through the log.\n *\n * Each call is committed the way the native loop commits one — the assistant\n * turn that asked for it with the text said before it, then `tool.started`,\n * then `tool.finished` with the call's deliveries — so the log projects to a\n * conversation any model can continue. Calls are serialised: a vendor may run\n * several at once, and interleaving their entries would leave an assistant turn\n * whose calls are answered out of order.\n */\nexport function createToolRunner(context: HarnessContext) {\n let said = \"\";\n let tail: Promise<unknown> = Promise.resolve();\n let usage: Usage | undefined;\n return {\n /** A block of text the vendor said, since the last call or the start. */\n say(text: string) { if (text) said = said ? `${said}\\n\\n${text}` : text; },\n /** Usage to carry on the next committed assistant entry. */\n spent(next: Usage) { usage = addUsage(usage, next); },\n /**\n * A call the vendor made through one of its own account connectors, which\n * ran in the vendor's cloud rather than through our executor. It is\n * recorded as a note — what was said before it, then the call and what it\n * returned — not as a tool call, because a model that takes the session\n * over has no such tool, and a provider may refuse a history that calls a\n * tool the request does not declare.\n */\n note(call: { name: string; arguments: unknown; result: string; isError?: boolean }) {\n const record = `[connector ${call.name}] ${JSON.stringify(call.arguments ?? {})}\\n${call.isError ? \"failed: \" : \"→ \"}${call.result.length > RESULT_CHARS ? `${call.result.slice(0, RESULT_CHARS)}…` : call.result}`;\n const next = tail.then(async () => {\n const text = said;\n said = \"\";\n await context.commit([{ type: \"assistant\", runId: context.runId, content: text ? `${text}\\n\\n${record}` : record }]);\n });\n tail = next.catch(() => undefined);\n return next;\n },\n run(call: ToolCall): Promise<ToolResult> {\n const next = tail.then(() => runOne(call));\n tail = next.catch(() => undefined);\n return next;\n },\n /** The final assistant entry: what was said after the last call, and where the vendor's session is. */\n async finish(providerState: { provider: string; items: JsonValue[] }, generation: { id: string; model?: string; startedAt: string }) {\n await tail;\n const text = said;\n said = \"\";\n const spentHere = usage;\n usage = undefined;\n await context.commit([{\n type: \"assistant\", runId: context.runId, content: text,\n ...(spentHere ? { usage: spentHere } : {}), providerState,\n generation: { ...generation, endedAt: new Date().toISOString(), ...(context.context?.turn ? { turn: context.context.turn } : {}) },\n }]);\n return text;\n },\n };\n\n async function runOne(call: ToolCall): Promise<ToolResult> {\n const text = said;\n said = \"\";\n const spentHere = usage;\n usage = undefined;\n await context.commit([\n { type: \"assistant\", runId: context.runId, content: text, calls: [call], ...(spentHere ? { usage: spentHere } : {}) },\n { type: \"tool.started\", runId: context.runId, callId: call.callId },\n ]);\n let completion: { result: ToolResult; deliveries: readonly Delivery[] } | undefined;\n if (context.tools) {\n for await (const done of context.tools.execute({ calls: [call], signal: context.signal })) { completion = done; break; }\n }\n const result = completion?.result ?? { content: context.tools ? \"Tool use cancelled\" : `No tool named '${call.name}' is available.`, isError: true };\n await context.commit([{ type: \"tool.finished\", runId: context.runId, callId: call.callId, result }], completion?.deliveries ?? []);\n return result;\n }\n}\n\nexport function addUsage(a: Usage | undefined, b: Usage): Usage {\n if (!a) return { ...b };\n const out: Usage = { ...a };\n for (const key of [\"inputTokens\", \"outputTokens\", \"cacheReadTokens\", \"cacheWriteTokens\", \"costUsd\"] as const) {\n if (b[key] !== undefined) out[key] = (out[key] ?? 0) + b[key];\n }\n return out;\n}\n"]}
1
+ {"version":3,"file":"vendor.js","sourceRoot":"","sources":["../../../src/harness/adapters/vendor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAK1C;;;;;;;;;;GAUG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,OAAe,EAAE,WAAoB;IAClF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAgB,EAAE,CAAC;AACpG,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,OAAuB;IACrD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CA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C;AACH,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,CAAoB,EAAE,CAAQ;IACrD,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,MAAM,GAAG,GAAU,EAAE,GAAG,CAAC,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,SAAS,CAAU,EAAE,CAAC;QAC7G,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { HarnessContext } from \"../harness.js\";\nimport type { Content, ContentPart } from \"../../content.js\";\nimport { textOf } from \"../../content.js\";\nimport type { Delivery, Entry, Stored, ToolCall, ToolResult, Usage } from \"../../session/entry.js\";\nimport type { Message } from \"../../session/messages.js\";\nimport type { JsonValue } from \"../../json.js\";\n\n/**\n * What a vendor-loop harness shares: an agent process that owns its own\n * context and model calls, running *our* tools and nothing of its own.\n *\n * Two facts hold for every such adapter and are why this file exists rather\n * than two copies of it. The vendor's conversation lives in the vendor's own\n * session store, so continuing it means naming that session; and our log has\n * to say what happened in a shape a native model could take over from, because\n * an owner who switches an instance from a subscription to an API key expects\n * the conversation to carry on.\n */\n\n/**\n * The vendor session a run continues, recorded on the run's final assistant\n * entry. `fingerprint` names what the session was opened with that cannot be\n * changed on resume — a vendor that fixes the tool list at session start is\n * resumed only while the list is the same.\n */\nexport function sessionState(provider: string, session: string, fingerprint?: string) {\n return { provider, items: [{ session, ...(fingerprint ? { fingerprint } : {}) }] as JsonValue[] };\n}\n\n/** A stable name for a tool list, by what the model is shown of it. */\nexport function toolFingerprint(context: HarnessContext): string {\n const text = JSON.stringify((context.tools?.list() ?? []).map((tool) => [tool.name, tool.description, tool.parameters]));\n let hash = 2166136261;\n for (let index = 0; index < text.length; index += 1) hash = Math.imul(hash ^ text.charCodeAt(index), 16777619) >>> 0;\n return hash.toString(16);\n}\n\n/**\n * Where this activation starts: the vendor session to resume, and the words to\n * open it with.\n *\n * A session is resumed only when the latest assistant entry in the log was\n * written by this provider and names it. Any later assistant entry means\n * another model spoke since, so the vendor's copy is missing part of the\n * conversation and resuming it would answer from a past that is not the log's.\n * Then the session starts fresh, opened with the conversation so far rendered\n * as text: the vendor cannot be handed our messages as its own, and a summary\n * of them is the honest substitute. A long conversation is opened with its\n * most recent part (`TRANSCRIPT_CHARS`). `fresh` asks for that start whatever the\n * log says, for a session the log names and the vendor no longer has; a\n * `fingerprint` that differs from the recorded one asks for it too.\n */\nexport function opening(context: HarnessContext, provider: string, options: { fresh?: boolean; fingerprint?: string } = {}): { resume?: string; prompt: Content } {\n const entries = context.entries();\n const last = entries.findLast((entry) => entry.type === \"assistant\");\n const state = !options.fresh && last?.type === \"assistant\" && last.providerState?.provider === provider ? last.providerState.items[0] : undefined;\n const fields = state && typeof state === \"object\" && !Array.isArray(state) ? state as { readonly [key: string]: JsonValue } : {};\n const session = typeof fields[\"session\"] === \"string\" && fields[\"fingerprint\"] === options.fingerprint ? fields[\"session\"] : undefined;\n const turn = context.context?.turn ? [`<turn-context>\\n${context.context.turn}\\n</turn-context>`] : [];\n if (session) {\n const since = entries.filter((entry): entry is Stored<Extract<Entry, { type: \"run.started\" | \"hook.input\" }>> =>\n (entry.type === \"run.started\" || entry.type === \"hook.input\") && entry.seq > last!.seq);\n return { resume: session, prompt: join([...turn, ...since.map((entry) => entry.input)]) };\n }\n const current = entries.filter((entry) => entry.type === \"run.started\" && entry.runId === context.runId);\n const before = earlier(context.history(), current.length);\n const transcript = before.length ? [`<conversation-so-far>\\n${transcriptText(before)}\\n</conversation-so-far>`] : [];\n return { prompt: join([...transcript, ...turn, ...current.map((entry) => (entry as Extract<Entry, { type: \"run.started\" }>).input)]) };\n}\n\n/** Inputs folded into this run by `drain` that the vendor has not been shown yet. */\nexport function arrivals(context: HarnessContext, shown: Set<number>): Content[] {\n return context.entries()\n .filter((entry) => entry.type === \"run.started\" && entry.runId === context.runId && !shown.has(entry.seq))\n .map((entry) => { shown.add(entry.seq); return (entry as Extract<Entry, { type: \"run.started\" }>).input; });\n}\n\n/** Seqs of this run's inputs that `opening` already put in the prompt. */\nexport function openingInputs(context: HarnessContext): Set<number> {\n return new Set(context.entries().filter((entry) => entry.type === \"run.started\" && entry.runId === context.runId).map((entry) => entry.seq));\n}\n\n/**\n * The conversation before this run, as the model was shown it: the projection\n * minus its system messages (the vendor gets ours as its own instructions) and\n * minus the inputs this run is about to send.\n */\nfunction earlier(messages: readonly Message[], current: number): Message[] {\n const body = messages.filter((message) => message.role !== \"system\");\n let drop = current;\n const out = [...body];\n while (drop > 0 && out.length && out[out.length - 1]!.role === \"user\") { out.pop(); drop -= 1; }\n return out;\n}\n\nconst RESULT_CHARS = 4_000;\n/**\n * The most of a conversation a new vendor session is opened with. A vendor\n * refuses an input past a fixed size (Codex at 1,048,576 characters), and the\n * model has to fit it in its window with room to work, so the transcript keeps\n * what is most recent and says how much came before.\n */\nexport const TRANSCRIPT_CHARS = 200_000;\n\n/** A readable transcript. Tool output is cut, because the next turns can read again what matters. */\nexport function transcriptText(messages: readonly Message[], maxChars = TRANSCRIPT_CHARS): string {\n const texts = messages.map(messageText).filter(Boolean);\n const kept: string[] = [];\n let room = maxChars;\n for (let index = texts.length - 1; index >= 0; index -= 1) {\n const text = texts[index]!;\n if (text.length > room) {\n if (!kept.length) kept.unshift(`${text.slice(0, room)}…`);\n break;\n }\n kept.unshift(text);\n room -= text.length + 2;\n }\n const omitted = texts.length - kept.length;\n return [...(omitted ? [`[${omitted} earlier ${omitted === 1 ? \"message is\" : \"messages are\"} not shown]`] : []), ...kept].join(\"\\n\\n\");\n}\n\nfunction messageText(message: Message): string {\n if (message.role === \"user\") return `[user]\\n${described(message.content)}`;\n if (message.role === \"assistant\") {\n const calls = (message.calls ?? []).map((call) => `→ ${call.name}(${call.arguments})`);\n return [`[assistant]`, textOf(message.content), ...calls].filter(Boolean).join(\"\\n\");\n }\n if (message.role === \"tool\") {\n const text = described(message.content);\n return `[tool result${message.isError ? \", error\" : \"\"}]\\n${text.length > RESULT_CHARS ? `${text.slice(0, RESULT_CHARS)}…` : text}`;\n }\n return \"\";\n}\n\n/** Text, with media named rather than dropped silently. */\nexport function described(content: Content): string {\n if (typeof content === \"string\") return content;\n return content.map((part) => {\n if (part.type === \"text\") return part.text;\n if (part.type === \"image\") return `[image ${part.mediaType}]`;\n if (part.type === \"file\") return `[file ${part.name ?? \"\"} ${part.mediaType}]`.replace(\" \", \" \");\n return \"\";\n }).filter(Boolean).join(\"\\n\");\n}\n\nfunction join(parts: readonly Content[]): Content {\n const out: ContentPart[] = [];\n for (const part of parts) {\n if (typeof part === \"string\") { if (part) out.push({ type: \"text\", text: part }); }\n else out.push(...part);\n }\n return out.every((part) => part.type === \"text\") ? out.map((part) => (part as { text: string }).text).join(\"\\n\\n\") : out;\n}\n\n/**\n * Runs our tools for a vendor's loop, one call at a time, through the log.\n *\n * Each call is committed the way the native loop commits one — the assistant\n * turn that asked for it with the text said before it, then `tool.started`,\n * then `tool.finished` with the call's deliveries — so the log projects to a\n * conversation any model can continue. Calls are serialised: a vendor may run\n * several at once, and interleaving their entries would leave an assistant turn\n * whose calls are answered out of order.\n */\nexport function createToolRunner(context: HarnessContext) {\n let said = \"\";\n let tail: Promise<unknown> = Promise.resolve();\n let usage: Usage | undefined;\n return {\n /** A block of text the vendor said, since the last call or the start. */\n say(text: string) { if (text) said = said ? `${said}\\n\\n${text}` : text; },\n /** Usage to carry on the next committed assistant entry. */\n spent(next: Usage) { usage = addUsage(usage, next); },\n /**\n * A call the vendor made through one of its own account connectors, which\n * ran in the vendor's cloud rather than through our executor. It is\n * recorded as a note — what was said before it, then the call and what it\n * returned — not as a tool call, because a model that takes the session\n * over has no such tool, and a provider may refuse a history that calls a\n * tool the request does not declare.\n */\n note(call: { name: string; arguments: unknown; result: string; isError?: boolean }) {\n const record = `[connector ${call.name}] ${JSON.stringify(call.arguments ?? {})}\\n${call.isError ? \"failed: \" : \"→ \"}${call.result.length > RESULT_CHARS ? `${call.result.slice(0, RESULT_CHARS)}…` : call.result}`;\n const next = tail.then(async () => {\n const text = said;\n said = \"\";\n await context.commit([{ type: \"assistant\", runId: context.runId, content: text ? `${text}\\n\\n${record}` : record }]);\n });\n tail = next.catch(() => undefined);\n return next;\n },\n run(call: ToolCall): Promise<ToolResult> {\n const next = tail.then(() => runOne(call));\n tail = next.catch(() => undefined);\n return next;\n },\n /** The final assistant entry: what was said after the last call, and where the vendor's session is. */\n async finish(providerState: { provider: string; items: JsonValue[] }, generation: { id: string; model?: string; startedAt: string }) {\n await tail;\n const text = said;\n said = \"\";\n const spentHere = usage;\n usage = undefined;\n await context.commit([{\n type: \"assistant\", runId: context.runId, content: text,\n ...(spentHere ? { usage: spentHere } : {}), providerState,\n generation: { ...generation, endedAt: new Date().toISOString(), ...(context.context?.turn ? { turn: context.context.turn } : {}) },\n }]);\n return text;\n },\n };\n\n async function runOne(call: ToolCall): Promise<ToolResult> {\n const text = said;\n said = \"\";\n const spentHere = usage;\n usage = undefined;\n await context.commit([\n { type: \"assistant\", runId: context.runId, content: text, calls: [call], ...(spentHere ? { usage: spentHere } : {}) },\n { type: \"tool.started\", runId: context.runId, callId: call.callId },\n ]);\n let completion: { result: ToolResult; deliveries: readonly Delivery[] } | undefined;\n if (context.tools) {\n for await (const done of context.tools.execute({ calls: [call], signal: context.signal })) { completion = done; break; }\n }\n const result = completion?.result ?? { content: context.tools ? \"Tool use cancelled\" : `No tool named '${call.name}' is available.`, isError: true };\n await context.commit([{ type: \"tool.finished\", runId: context.runId, callId: call.callId, result }], completion?.deliveries ?? []);\n return result;\n }\n}\n\nexport function addUsage(a: Usage | undefined, b: Usage): Usage {\n if (!a) return { ...b };\n const out: Usage = { ...a };\n for (const key of [\"inputTokens\", \"outputTokens\", \"cacheReadTokens\", \"cacheWriteTokens\", \"costUsd\"] as const) {\n if (b[key] !== undefined) out[key] = (out[key] ?? 0) + b[key];\n }\n return out;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-dray/aglib",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "type": "module",
5
5
  "description": "A small TypeScript toolkit for building your own agent harness.",
6
6
  "license": "MIT",