@guuey/host 0.1.0 → 0.2.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/dist/frameworks/claude-options.d.ts +46 -6
- package/dist/frameworks/claude-options.d.ts.map +1 -1
- package/dist/frameworks/claude-options.js +96 -6
- package/dist/frameworks/claude-runner.d.ts.map +1 -1
- package/dist/frameworks/claude-runner.js +1 -1
- package/dist/frameworks/claude.d.ts +26 -6
- package/dist/frameworks/claude.d.ts.map +1 -1
- package/dist/frameworks/claude.js +4 -0
- package/dist/frameworks/google-adk.d.ts +3 -4
- package/dist/frameworks/google-adk.d.ts.map +1 -1
- package/dist/frameworks/google-adk.js +40 -6
- package/dist/frameworks/openai-runner.d.ts.map +1 -1
- package/dist/frameworks/openai-runner.js +1 -1
- package/dist/frameworks/openai.d.ts +4 -2
- package/dist/frameworks/openai.d.ts.map +1 -1
- package/dist/frameworks/openai.js +40 -5
- package/dist/preamble.d.ts +87 -1
- package/dist/preamble.d.ts.map +1 -1
- package/dist/preamble.js +179 -0
- package/package.json +3 -3
- package/dist/creds.d.ts +0 -26
- package/dist/creds.d.ts.map +0 -1
- package/dist/creds.js +0 -45
- package/dist/options.d.ts +0 -173
- package/dist/options.d.ts.map +0 -1
- package/dist/options.js +0 -248
- package/dist/run-openai.d.ts +0 -65
- package/dist/run-openai.d.ts.map +0 -1
- package/dist/run-openai.js +0 -207
- package/dist/run.d.ts +0 -72
- package/dist/run.d.ts.map +0 -1
- package/dist/run.js +0 -80
package/dist/run.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { buildOptions, } from "./options.js";
|
|
2
|
-
import { resolveSdkVersion } from "./sdk-version.js";
|
|
3
|
-
/** The framework THIS run path runs. OpenAI has its own path (`run-openai.ts`). */
|
|
4
|
-
const CLAUDE_FRAMEWORK = "claude-agent-sdk";
|
|
5
|
-
/** The npm package whose installed version is this framework's `hello.sdkVersion`. */
|
|
6
|
-
const CLAUDE_SDK_PACKAGE = "@anthropic-ai/claude-agent-sdk";
|
|
7
|
-
function isResultMessage(msg) {
|
|
8
|
-
return msg.type === "result";
|
|
9
|
-
}
|
|
10
|
-
/** Map the SDK result message → the Worker Protocol `done` stopReason + result. */
|
|
11
|
-
function resultToDone(msg) {
|
|
12
|
-
const result = typeof msg.result === "string" ? msg.result : "";
|
|
13
|
-
const stopReason = msg.subtype === "success"
|
|
14
|
-
? "end_turn"
|
|
15
|
-
: msg.subtype === "error_max_turns"
|
|
16
|
-
? "max_turns"
|
|
17
|
-
: "error";
|
|
18
|
-
return { stopReason, result };
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Run one invoke. Emits `native` per SDKMessage, `done` on the result, `error`
|
|
22
|
-
* on a framework-gate violation or a thrown error. Never throws — every failure
|
|
23
|
-
* path becomes an `error` event so the Router always sees a terminal event.
|
|
24
|
-
*/
|
|
25
|
-
export async function runInvoke(snapshot, invoke, runtime, emit, query) {
|
|
26
|
-
// The SDK-version handshake (§8 item B, additive-optional) — ALWAYS the
|
|
27
|
-
// first event of this invoke's fd-3 stream, before the framework gate or any
|
|
28
|
-
// native/turn event. `sdkVersion` is resolved at runtime, never hardcoded;
|
|
29
|
-
// `null` (SDK not resolvable) is tolerated by the Router.
|
|
30
|
-
emit.hello(CLAUDE_FRAMEWORK, CLAUDE_SDK_PACKAGE, resolveSdkVersion(CLAUDE_SDK_PACKAGE));
|
|
31
|
-
// Framework gate: this run path is the Claude SDK. OpenAI agents route to
|
|
32
|
-
// `runInvokeOpenai` (selected in `index.ts` by `snapshot.framework`) and never
|
|
33
|
-
// reach here. A non-claude framework arriving here (e.g. `google-adk`,
|
|
34
|
-
// `vanilla`) has no run path yet → a clear `error`, never a silent mis-run.
|
|
35
|
-
if (snapshot.framework && snapshot.framework !== CLAUDE_FRAMEWORK) {
|
|
36
|
-
emit.error(`@guuey/host: the claude run path got framework '${snapshot.framework}'; no run path for it yet.`);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
let options;
|
|
40
|
-
try {
|
|
41
|
-
const ctx = {
|
|
42
|
-
input: invoke.input,
|
|
43
|
-
identity: invoke.identity,
|
|
44
|
-
fs: invoke.fs,
|
|
45
|
-
history: invoke.history,
|
|
46
|
-
listCredentials: runtime.listCredentials,
|
|
47
|
-
...(runtime.apiKey !== undefined ? { apiKey: runtime.apiKey } : {}),
|
|
48
|
-
...(runtime.baseUrl !== undefined ? { baseUrl: runtime.baseUrl } : {}),
|
|
49
|
-
...(runtime.authToken !== undefined ? { authToken: runtime.authToken } : {}),
|
|
50
|
-
...(invoke.priorMemory !== undefined ? { priorMemory: invoke.priorMemory } : {}),
|
|
51
|
-
...(invoke.priorState !== undefined ? { priorState: invoke.priorState } : {}),
|
|
52
|
-
};
|
|
53
|
-
options = buildOptions(snapshot, ctx);
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
emit.error(err instanceof Error ? err.message : String(err));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
let done;
|
|
61
|
-
for await (const msg of query({ prompt: invoke.input, options })) {
|
|
62
|
-
emit.native(CLAUDE_FRAMEWORK, toJson(msg));
|
|
63
|
-
if (isResultMessage(msg))
|
|
64
|
-
done = resultToDone(msg);
|
|
65
|
-
}
|
|
66
|
-
emit.done(done?.result ?? "", done?.stopReason ?? "end_turn");
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
emit.error(err instanceof Error ? err.message : String(err));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Coerce one SDKMessage to the `JsonValue` the `native` event carries. SDK
|
|
74
|
-
* messages are plain JSON-serializable objects; the round-trip drops any
|
|
75
|
-
* non-JSON surface (functions/symbols never appear on them) and yields the
|
|
76
|
-
* exact shape the Router's normalizer parses off the wire.
|
|
77
|
-
*/
|
|
78
|
-
function toJson(msg) {
|
|
79
|
-
return JSON.parse(JSON.stringify(msg));
|
|
80
|
-
}
|