@autonome-research/thread-phase-agents 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +207 -0
- package/dist/acp/adapter.d.ts +89 -0
- package/dist/acp/adapter.d.ts.map +1 -0
- package/dist/acp/adapter.js +461 -0
- package/dist/acp/adapter.js.map +1 -0
- package/dist/acp/index.d.ts +12 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +10 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/transport.d.ts +82 -0
- package/dist/acp/transport.d.ts.map +1 -0
- package/dist/acp/transport.js +199 -0
- package/dist/acp/transport.js.map +1 -0
- package/dist/acp/types.d.ts +157 -0
- package/dist/acp/types.d.ts.map +1 -0
- package/dist/acp/types.js +34 -0
- package/dist/acp/types.js.map +1 -0
- package/dist/anthropic/adapter.d.ts +55 -0
- package/dist/anthropic/adapter.d.ts.map +1 -0
- package/dist/anthropic/adapter.js +259 -0
- package/dist/anthropic/adapter.js.map +1 -0
- package/dist/anthropic/index.d.ts +8 -0
- package/dist/anthropic/index.d.ts.map +1 -0
- package/dist/anthropic/index.js +8 -0
- package/dist/anthropic/index.js.map +1 -0
- package/dist/claude-code/adapter.d.ts +56 -0
- package/dist/claude-code/adapter.d.ts.map +1 -0
- package/dist/claude-code/adapter.js +319 -0
- package/dist/claude-code/adapter.js.map +1 -0
- package/dist/claude-code/index.d.ts +8 -0
- package/dist/claude-code/index.d.ts.map +1 -0
- package/dist/claude-code/index.js +8 -0
- package/dist/claude-code/index.js.map +1 -0
- package/dist/codex/adapter.d.ts +62 -0
- package/dist/codex/adapter.d.ts.map +1 -0
- package/dist/codex/adapter.js +258 -0
- package/dist/codex/adapter.js.map +1 -0
- package/dist/codex/index.d.ts +9 -0
- package/dist/codex/index.d.ts.map +1 -0
- package/dist/codex/index.js +9 -0
- package/dist/codex/index.js.map +1 -0
- package/dist/codex-cli/adapter.d.ts +70 -0
- package/dist/codex-cli/adapter.d.ts.map +1 -0
- package/dist/codex-cli/adapter.js +368 -0
- package/dist/codex-cli/adapter.js.map +1 -0
- package/dist/codex-cli/index.d.ts +10 -0
- package/dist/codex-cli/index.d.ts.map +1 -0
- package/dist/codex-cli/index.js +10 -0
- package/dist/codex-cli/index.js.map +1 -0
- package/dist/hermes/index.d.ts +50 -0
- package/dist/hermes/index.d.ts.map +1 -0
- package/dist/hermes/index.js +43 -0
- package/dist/hermes/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/injectors.d.ts +104 -0
- package/dist/injectors.d.ts.map +1 -0
- package/dist/injectors.js +219 -0
- package/dist/injectors.js.map +1 -0
- package/dist/openclaw/index.d.ts +54 -0
- package/dist/openclaw/index.d.ts.map +1 -0
- package/dist/openclaw/index.js +61 -0
- package/dist/openclaw/index.js.map +1 -0
- package/dist/pi/adapter.d.ts +79 -0
- package/dist/pi/adapter.d.ts.map +1 -0
- package/dist/pi/adapter.js +396 -0
- package/dist/pi/adapter.js.map +1 -0
- package/dist/pi/index.d.ts +14 -0
- package/dist/pi/index.d.ts.map +1 -0
- package/dist/pi/index.js +14 -0
- package/dist/pi/index.js.map +1 -0
- package/dist/thread-bridge.d.ts +83 -0
- package/dist/thread-bridge.d.ts.map +1 -0
- package/dist/thread-bridge.js +143 -0
- package/dist/thread-bridge.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render a `Thread` into the input shape each adapter expects.
|
|
3
|
+
*
|
|
4
|
+
* Same-adapter handoff (claude-code → claude-code) uses the resume
|
|
5
|
+
* token; native fidelity. Cross-adapter handoff (claude-code →
|
|
6
|
+
* anthropic) loses the per-adapter native log and falls back to a
|
|
7
|
+
* text rendering of the canonical event stream.
|
|
8
|
+
*
|
|
9
|
+
* These helpers turn `thread.events` into the next adapter's input
|
|
10
|
+
* format. They're lossy by design — preserve the gist, not the
|
|
11
|
+
* adapter-specific structure. For tighter fidelity, pass the
|
|
12
|
+
* adapter's resume token via `injectResume.<adapter>` instead.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
import { threadToMessages, } from '@autonome-research/thread-phase/agents';
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Internal: render a thread's events as a single text transcript
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Produce a text transcript of the thread suitable for splicing into
|
|
22
|
+
* any adapter's prompt. Format is "[<source>] <text>" for assistant
|
|
23
|
+
* turns, "[<source>:tool] <name>(<input>)" for tool calls,
|
|
24
|
+
* "[<source>:result] <output>" for tool results. Skips native /
|
|
25
|
+
* thinking / lifecycle events.
|
|
26
|
+
*
|
|
27
|
+
* Output is bounded by the thread's content; very long threads
|
|
28
|
+
* produce very long transcripts — callers managing token budgets
|
|
29
|
+
* should pre-trim or summarize.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export function threadToTranscript(thread) {
|
|
34
|
+
const lines = [];
|
|
35
|
+
for (const event of thread.events) {
|
|
36
|
+
switch (event.type) {
|
|
37
|
+
case 'text': {
|
|
38
|
+
// Accumulate text per source — but for simplicity emit each delta
|
|
39
|
+
// as a separate line tagged with source. Lossy but unambiguous.
|
|
40
|
+
lines.push(`[${event.source}] ${event.delta}`);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 'tool_call': {
|
|
44
|
+
const inputStr = safeJson(event.input);
|
|
45
|
+
lines.push(`[${event.source}:tool_call ${event.name}] ${inputStr}`);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'tool_result': {
|
|
49
|
+
const outputStr = typeof event.output === 'string' ? event.output : safeJson(event.output);
|
|
50
|
+
const prefix = event.isError ? 'tool_error' : 'tool_result';
|
|
51
|
+
lines.push(`[${event.source}:${prefix} ${event.name}] ${outputStr}`);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'turn_end': {
|
|
55
|
+
// Assistant text from turn_end is redundant with prior text
|
|
56
|
+
// deltas — skip unless no text was streamed (turns-only adapters).
|
|
57
|
+
if (event.assistantText && event.toolCallCount === 0 && !lines.some((l) => l.startsWith(`[${event.source}] `))) {
|
|
58
|
+
lines.push(`[${event.source}] ${event.assistantText}`);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
default:
|
|
63
|
+
// skip agent_start, agent_end, error, native, thinking
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return lines.join('\n');
|
|
68
|
+
}
|
|
69
|
+
function safeJson(value) {
|
|
70
|
+
if (value === undefined)
|
|
71
|
+
return 'undefined';
|
|
72
|
+
try {
|
|
73
|
+
return JSON.stringify(value);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return String(value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Per-adapter prompt-input renderers
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
/**
|
|
83
|
+
* Render a thread as a single ACP `ContentBlock[]` (one text block).
|
|
84
|
+
* Suitable for `acpAgent.adapter({ ..., prompt: threadToAcpPrompt(thread) })`
|
|
85
|
+
* when a downstream adapter call shouldn't try same-session resume.
|
|
86
|
+
*
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export function threadToAcpPrompt(thread) {
|
|
90
|
+
const transcript = threadToTranscript(thread);
|
|
91
|
+
return [{ type: 'text', text: transcript }];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Render a thread as a plain string. Suitable for `claudeCodeAgent` or
|
|
95
|
+
* any adapter that takes a single user-prompt string.
|
|
96
|
+
*
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
export function threadToClaudeCodePrompt(thread) {
|
|
100
|
+
return threadToTranscript(thread);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Render a thread as a single text input for the OpenAI Responses API.
|
|
104
|
+
* The Responses API's `input` field accepts a string or an items array;
|
|
105
|
+
* we use the string form for cross-adapter handoff.
|
|
106
|
+
*
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
export function threadToCodexInput(thread) {
|
|
110
|
+
return threadToTranscript(thread);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Render a thread as Anthropic `MessageParam[]` — currently a single
|
|
114
|
+
* user message wrapping the transcript. Anthropic's role-based
|
|
115
|
+
* conversation structure doesn't round-trip from canonical events
|
|
116
|
+
* losslessly; for tighter fidelity, use Anthropic's own messages
|
|
117
|
+
* array directly rather than crossing adapter boundaries.
|
|
118
|
+
*
|
|
119
|
+
* The return type is intentionally typed loosely as `unknown[]` to
|
|
120
|
+
* avoid importing `@anthropic-ai/sdk` types from this module — the
|
|
121
|
+
* runtime shape matches `MessageParam[]` (role: 'user' | 'assistant',
|
|
122
|
+
* content: string), which is the broadly-compatible subset across
|
|
123
|
+
* Anthropic SDK versions.
|
|
124
|
+
*
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
export function threadToAnthropicMessages(thread) {
|
|
128
|
+
// For now: collapse to a single user message containing the
|
|
129
|
+
// transcript. Higher-fidelity conversion (turn-by-turn) is a
|
|
130
|
+
// follow-up.
|
|
131
|
+
const transcript = threadToTranscript(thread);
|
|
132
|
+
return [{ role: 'user', content: transcript }];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Render the thread's canonical event log to thread-phase's internal
|
|
136
|
+
* `Message[]` shape. Re-exports the upstream `threadToMessages` so
|
|
137
|
+
* sibling-package consumers can find all the bridge helpers in one
|
|
138
|
+
* place.
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export { threadTo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kB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAc;IAEd,4DAA4D;IAC5D,6DAA6D;IAC7D,aAAa;IACb,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autonome-research/thread-phase-agents",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Agent adapters for thread-phase — wraps hermes, openclaw, anthropic, codex, claude-code, pi behind a uniform AgentAdapter protocol.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@autonome-research/thread-phase": "^3.0.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@anthropic-ai/sdk": "^0.96.0",
|
|
28
|
+
"@mariozechner/pi-coding-agent": "^0.73.1",
|
|
29
|
+
"openai": "^6.38.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@autonome-research/thread-phase": "*",
|
|
33
|
+
"@types/node": "^22.0.0",
|
|
34
|
+
"tsx": "^4.19.0",
|
|
35
|
+
"typescript": "^5.6.0",
|
|
36
|
+
"vitest": "^2.1.0"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/Code4me2/thread-phase.git",
|
|
44
|
+
"directory": "packages/thread-phase-agents"
|
|
45
|
+
}
|
|
46
|
+
}
|