taugraph 0.2.0 → 0.4.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/CHANGELOG.md +89 -0
- package/README.md +283 -22
- package/README.zh-CN.md +283 -22
- package/dist/agent/index.d.ts +74 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +254 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/state.d.ts +30 -0
- package/dist/agent/state.d.ts.map +1 -0
- package/dist/agent/state.js +135 -0
- package/dist/agent/state.js.map +1 -0
- package/dist/agent/util.d.ts +19 -0
- package/dist/agent/util.d.ts.map +1 -0
- package/dist/agent/util.js +59 -0
- package/dist/agent/util.js.map +1 -0
- package/dist/core/engine.d.ts +1 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +237 -35
- package/dist/core/engine.js.map +1 -1
- package/dist/core/errors.d.ts +2 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js.map +1 -1
- package/dist/core/graph.d.ts.map +1 -1
- package/dist/core/graph.js +9 -1
- package/dist/core/graph.js.map +1 -1
- package/dist/core/node.d.ts +6 -1
- package/dist/core/node.d.ts.map +1 -1
- package/dist/core/node.js +55 -6
- package/dist/core/node.js.map +1 -1
- package/dist/core/patch.d.ts +26 -0
- package/dist/core/patch.d.ts.map +1 -0
- package/dist/core/patch.js +192 -0
- package/dist/core/patch.js.map +1 -0
- package/dist/core/retry.d.ts +20 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +79 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/trace.d.ts +39 -8
- package/dist/core/trace.d.ts.map +1 -1
- package/dist/core/trace.js +222 -29
- package/dist/core/trace.js.map +1 -1
- package/dist/core/types.d.ts +35 -4
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/util.d.ts +5 -1
- package/dist/core/util.d.ts.map +1 -1
- package/dist/core/util.js +41 -9
- package/dist/core/util.js.map +1 -1
- package/dist/file/index.d.ts +26 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/file/index.js +373 -0
- package/dist/file/index.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/nodes/code.d.ts +5 -0
- package/dist/nodes/code.d.ts.map +1 -1
- package/dist/nodes/code.js.map +1 -1
- package/dist/nodes/content.d.ts +18 -0
- package/dist/nodes/content.d.ts.map +1 -0
- package/dist/nodes/content.js +88 -0
- package/dist/nodes/content.js.map +1 -0
- package/dist/nodes/index.d.ts +2 -1
- package/dist/nodes/index.d.ts.map +1 -1
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/index.js.map +1 -1
- package/dist/nodes/llm.d.ts +100 -4
- package/dist/nodes/llm.d.ts.map +1 -1
- package/dist/nodes/llm.js +5 -1
- package/dist/nodes/llm.js.map +1 -1
- package/dist/openai/index.d.ts +55 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +208 -0
- package/dist/openai/index.js.map +1 -0
- package/package.json +20 -4
- package/src/agent/index.ts +359 -0
- package/src/agent/state.ts +147 -0
- package/src/agent/util.ts +74 -0
- package/src/core/engine.ts +241 -34
- package/src/core/errors.ts +2 -0
- package/src/core/graph.ts +7 -1
- package/src/core/node.ts +55 -6
- package/src/core/patch.ts +173 -0
- package/src/core/retry.ts +89 -0
- package/src/core/trace.ts +222 -29
- package/src/core/types.ts +37 -4
- package/src/core/util.ts +43 -10
- package/src/file/index.ts +408 -0
- package/src/index.ts +5 -1
- package/src/nodes/code.ts +5 -0
- package/src/nodes/content.ts +100 -0
- package/src/nodes/index.ts +10 -0
- package/src/nodes/llm.ts +109 -7
- package/src/openai/index.ts +286 -0
package/dist/nodes/llm.d.ts
CHANGED
|
@@ -1,8 +1,87 @@
|
|
|
1
1
|
import { type MaybePromise, type Node, type RetryPolicy, type StandardSchemaV1 } from "../index.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/** A tool the model may call. Field names follow MCP; `inputSchema` is JSON Schema for the arguments object. */
|
|
3
|
+
export interface ToolSpec {
|
|
4
|
+
/** Letters, digits, `_` and `-`, at most 64 characters: what every major provider accepts. */
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly description?: string;
|
|
7
|
+
readonly inputSchema: Readonly<Record<string, unknown>>;
|
|
8
|
+
}
|
|
9
|
+
/** A call the model asked for. Arguments are parsed JSON, as in MCP and Anthropic; adapters convert OpenAI's string. */
|
|
10
|
+
export interface ToolCall {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly arguments: Readonly<Record<string, unknown>>;
|
|
14
|
+
/** Set by an adapter that could not read the arguments as a JSON object; `arguments` is then `{}`. */
|
|
15
|
+
readonly parseError?: string;
|
|
16
|
+
/** The provider's opaque proof for this call (Gemini's thought signature). Send it back to the same model only. */
|
|
17
|
+
readonly signature?: string;
|
|
18
|
+
}
|
|
19
|
+
/** How the model may use tools: freely, not at all, at least one, or this one. */
|
|
20
|
+
export type ToolChoice = "auto" | "none" | "required" | {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* How much a model should think before it answers. Adapters map it to the provider's setting; an adapter that knows
|
|
25
|
+
* which levels a model has rounds to the nearest one.
|
|
26
|
+
*/
|
|
27
|
+
export type ReasoningLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
28
|
+
/**
|
|
29
|
+
* What a model thought before answering, in the order it gave. `signature` is the provider's opaque proof and is only
|
|
30
|
+
* valid for the model that wrote it: adapters send it back when the assistant message's `model` is their own `id`.
|
|
31
|
+
*/
|
|
32
|
+
export interface ReasoningPart {
|
|
33
|
+
readonly text: string;
|
|
34
|
+
readonly signature?: string;
|
|
35
|
+
/** The provider hid the text (a safety filter); `signature` holds the encrypted payload. */
|
|
36
|
+
readonly redacted?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Text in a message. */
|
|
39
|
+
export interface TextPart {
|
|
40
|
+
readonly type: "text";
|
|
41
|
+
readonly text: string;
|
|
5
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* An image in a message: its bytes in base64 (`data`, without a `data:` prefix), or a URL. A URL may be `https:`,
|
|
45
|
+
* `data:`, or a reference of your own such as `media:abc` that the adapter reads when it calls the model, which keeps
|
|
46
|
+
* traces and snapshots small. Field names follow MCP. If both `data` and `url` are present, `data` wins; narrow with
|
|
47
|
+
* `"data" in image`.
|
|
48
|
+
*/
|
|
49
|
+
export type ImagePart = {
|
|
50
|
+
readonly type: "image";
|
|
51
|
+
readonly data: string;
|
|
52
|
+
readonly mimeType: string;
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: "image";
|
|
55
|
+
readonly url: string;
|
|
56
|
+
readonly mimeType?: string;
|
|
57
|
+
};
|
|
58
|
+
export type ContentPart = TextPart | ImagePart;
|
|
59
|
+
/** What a user message or a tool result carries: plain text, or text and images in order. */
|
|
60
|
+
export type MessageContent = string | readonly ContentPart[];
|
|
61
|
+
/** One message of a conversation. User messages and tool results may carry images; the others are text. */
|
|
62
|
+
export type ChatMessage = {
|
|
63
|
+
readonly role: "system";
|
|
64
|
+
readonly content: string;
|
|
65
|
+
} | {
|
|
66
|
+
readonly role: "user";
|
|
67
|
+
readonly content: MessageContent;
|
|
68
|
+
} | {
|
|
69
|
+
readonly role: "assistant";
|
|
70
|
+
readonly content: string;
|
|
71
|
+
readonly toolCalls?: readonly ToolCall[];
|
|
72
|
+
/** What the model thought first. */
|
|
73
|
+
readonly reasoning?: readonly ReasoningPart[];
|
|
74
|
+
/**
|
|
75
|
+
* The `LLMModel.id` that wrote this message (not `LLMResponse.model`). Adapters send reasoning signatures,
|
|
76
|
+
* `redacted` parts and `ToolCall.signature` back only when it equals their own `id`.
|
|
77
|
+
*/
|
|
78
|
+
readonly model?: string;
|
|
79
|
+
} | {
|
|
80
|
+
readonly role: "tool";
|
|
81
|
+
readonly toolCallId: string;
|
|
82
|
+
readonly content: MessageContent;
|
|
83
|
+
readonly isError?: boolean;
|
|
84
|
+
};
|
|
6
85
|
/** Everything in a request is recorded in the trace, so keep it plain JSON. */
|
|
7
86
|
export interface LLMRequest {
|
|
8
87
|
readonly messages: readonly ChatMessage[];
|
|
@@ -12,18 +91,33 @@ export interface LLMRequest {
|
|
|
12
91
|
readonly responseFormat?: "text" | "json";
|
|
13
92
|
/** Provider-specific options, passed through by the adapter. */
|
|
14
93
|
readonly extra?: Readonly<Record<string, unknown>>;
|
|
94
|
+
/** Tools the model may call; adapters translate them to the provider's format. */
|
|
95
|
+
readonly tools?: readonly ToolSpec[];
|
|
96
|
+
readonly toolChoice?: ToolChoice;
|
|
97
|
+
/** How much the model should think first. Unset: the adapter sends nothing and the model uses its default. */
|
|
98
|
+
readonly reasoning?: ReasoningLevel;
|
|
15
99
|
}
|
|
16
100
|
export interface LLMResponse {
|
|
17
101
|
readonly content: string;
|
|
102
|
+
/** The provider's name for the model that answered, e.g. "gpt-4o-mini-2024-07-18". Not the `LLMModel.id`. */
|
|
18
103
|
readonly model?: string;
|
|
19
104
|
readonly finishReason?: string;
|
|
20
105
|
readonly usage?: {
|
|
21
106
|
readonly inputTokens?: number;
|
|
22
107
|
readonly outputTokens?: number;
|
|
108
|
+
/** Tokens spent thinking; already counted in `outputTokens`. */
|
|
109
|
+
readonly reasoningTokens?: number;
|
|
23
110
|
};
|
|
111
|
+
/** Tool calls the model asked for, in order. */
|
|
112
|
+
readonly toolCalls?: readonly ToolCall[];
|
|
113
|
+
/** What the model thought before answering, in order. */
|
|
114
|
+
readonly reasoning?: readonly ReasoningPart[];
|
|
24
115
|
}
|
|
25
116
|
export interface LLMModel {
|
|
26
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Recorded in every `llm_call` event, e.g. "openai:gpt-4o-mini" or "ollama:qwen3". It also decides which assistant
|
|
119
|
+
* messages count as this model's own for reasoning passback, so keep it stable and different for each model.
|
|
120
|
+
*/
|
|
27
121
|
readonly id: string;
|
|
28
122
|
complete(request: LLMRequest, options: {
|
|
29
123
|
readonly signal: AbortSignal;
|
|
@@ -35,6 +129,8 @@ interface LLMNodeBase<S> {
|
|
|
35
129
|
readonly prompt: (state: S) => LLMRequest | string;
|
|
36
130
|
/** Retries the whole call, including output parsing. */
|
|
37
131
|
readonly retry?: RetryPolicy;
|
|
132
|
+
/** Milliseconds each attempt may take; then the request's signal aborts and the attempt fails with TIMEOUT. */
|
|
133
|
+
readonly timeoutMs?: number;
|
|
38
134
|
}
|
|
39
135
|
export interface LLMTextNodeConfig<S> extends LLMNodeBase<S> {
|
|
40
136
|
/** Folds the reply into state. The return type does not drive inference; the graph does. */
|
package/dist/nodes/llm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/nodes/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,YAAY,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAOhH,MAAM,WAAW,WAAW;
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/nodes/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,YAAY,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAOhH,gHAAgH;AAChH,MAAM,WAAW,QAAQ;IACvB,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACzD;AAED,wHAAwH;AACxH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MA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/nodes/llm.js
CHANGED
|
@@ -31,7 +31,11 @@ export function LLMNode(config) {
|
|
|
31
31
|
return config.update(state, response.content, response);
|
|
32
32
|
return andThen(parseStructured(config.output, response.content), (data) => config.update(state, data, response));
|
|
33
33
|
});
|
|
34
|
-
}, {
|
|
34
|
+
}, {
|
|
35
|
+
kind: "llm",
|
|
36
|
+
...(config.retry && { retry: config.retry }),
|
|
37
|
+
...(config.timeoutMs !== undefined && { timeoutMs: config.timeoutMs }),
|
|
38
|
+
});
|
|
35
39
|
}
|
|
36
40
|
function parseStructured(schema, content) {
|
|
37
41
|
const fenced = /```(?:json)?\s*([\s\S]*?)```/i.exec(content);
|
package/dist/nodes/llm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../src/nodes/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyE,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../../src/nodes/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyE,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AA4JnD,gFAAgF;AAChF,MAAM,OAAO,cAAe,SAAQ,KAAK;IAI5B,OAAO;IACP,MAAM;IAJC,IAAI,GAAG,gBAAgB,CAAC;IAC1C,YACE,OAAe,EACN,OAAe,EACf,MAA0C;QAEnD,KAAK,CAAC,OAAO,CAAC,CAAC;uBAHN,OAAO;sBACP,MAAM;IAGjB,CAAC;CACF;AASD,MAAM,UAAU,OAAO,CAAO,MAA4D;IACxF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACjC,OAAO,UAAU,CACf,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACb,MAAM,KA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X,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;QAC5C,GAAG,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;KACvE,CACF,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAI,MAAoC,EAAE,OAAe;IAC/E,MAAM,MAAM,GAAG,+BAA+B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,cAAc,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE;QAC5D,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5C,MAAM,IAAI,cAAc,CAAC,2CAA2C,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ChatMessage, type ImageResolver, type LLMModel, type ReasoningLevel, type ToolCall, type ToolChoice, type ToolSpec } from "../nodes/index.js";
|
|
2
|
+
export interface OpenAICompatibleOptions {
|
|
3
|
+
/** e.g. "https://api.openai.com/v1" or "http://localhost:11434/v1" for Ollama */
|
|
4
|
+
readonly baseURL: string;
|
|
5
|
+
readonly model: string;
|
|
6
|
+
readonly apiKey?: string | undefined;
|
|
7
|
+
/** Reads image URLs OpenAI cannot fetch, e.g. `media:abc` from your store. http(s) and data: URLs go as they are. */
|
|
8
|
+
readonly resolveImage?: ImageResolver | undefined;
|
|
9
|
+
/** Request parameters for a reasoning level, merged before `extra`. Default: `{ reasoning_effort }`, "off" as "none". */
|
|
10
|
+
readonly reasoningParams?: ((level: ReasoningLevel) => Record<string, unknown>) | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Send a model's own reasoning back as `reasoning_content`. Default true: DeepSeek V4 and Kimi refuse a tool loop
|
|
13
|
+
* without it. Set false for endpoints that refuse the field in input messages, such as Groq and Cerebras.
|
|
14
|
+
*/
|
|
15
|
+
readonly sendReasoning?: boolean | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The request field that carries `maxTokens`. Default `"max_tokens"`; OpenAI's reasoning models (o-series, GPT-5)
|
|
18
|
+
* want `"max_completion_tokens"`.
|
|
19
|
+
*/
|
|
20
|
+
readonly tokenLimit?: "max_tokens" | "max_completion_tokens" | undefined;
|
|
21
|
+
/** Used instead of the global `fetch`, e.g. for a proxy or tests. */
|
|
22
|
+
readonly fetch?: typeof fetch | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** A tool call as OpenAI sends it: arguments are a JSON string. */
|
|
25
|
+
export interface OpenAIToolCall {
|
|
26
|
+
readonly id?: string;
|
|
27
|
+
readonly type?: string;
|
|
28
|
+
readonly function?: {
|
|
29
|
+
readonly name?: string;
|
|
30
|
+
readonly arguments?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** A response outside 200-299. `status` and `retryAfterMs` let `isRetryable` and the retry wait act on it. */
|
|
34
|
+
export declare class HTTPError extends Error {
|
|
35
|
+
readonly status: number;
|
|
36
|
+
readonly url: string;
|
|
37
|
+
/** From `Retry-After`, given in seconds or as an HTTP date; undefined when missing or unreadable. */
|
|
38
|
+
readonly retryAfterMs: number | undefined;
|
|
39
|
+
readonly name = "HTTPError";
|
|
40
|
+
constructor(message: string, status: number, url: string,
|
|
41
|
+
/** From `Retry-After`, given in seconds or as an HTTP date; undefined when missing or unreadable. */
|
|
42
|
+
retryAfterMs: number | undefined);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* taugraph messages in OpenAI's wire format. Images from tool results go into one user message right after the
|
|
46
|
+
* tool messages, since OpenAI's tool messages take text only. Image references must be read first (`resolveImage`).
|
|
47
|
+
* Pass the adapter's id as `modelId` to send that model's own reasoning back.
|
|
48
|
+
*/
|
|
49
|
+
export declare function toOpenAIMessages(messages: readonly ChatMessage[], modelId?: string): Record<string, unknown>[];
|
|
50
|
+
export declare function toOpenAITools(tools: readonly ToolSpec[]): Record<string, unknown>[];
|
|
51
|
+
export declare function toOpenAIToolChoice(choice: ToolChoice): unknown;
|
|
52
|
+
/** OpenAI's tool calls as taugraph's, arguments parsed. Unreadable arguments become `{}` with a `parseError`; missing ids become `call_<round>_<index>`. */
|
|
53
|
+
export declare function fromOpenAIToolCalls(calls: readonly OpenAIToolCall[], round?: number): ToolCall[];
|
|
54
|
+
export declare function openAICompatible(options: OpenAICompatibleOptions): LLMModel;
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAClB,KAAK,QAAQ,EAEb,KAAK,cAAc,EAEnB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,QAAQ,EAEd,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,uBAAuB;IACtC,iFAAiF;IACjF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ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AAS,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAuC9G;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAKnF;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAE9D;AAED,4JAA4J;AAC5J,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,EAAE,KAAK,SAAI,GAAG,QAAQ,EAAE,CAyB3F;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,QAAQ,CAmE3E"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { resolveImages, textOf, } from "../nodes/index.js";
|
|
2
|
+
/** A response outside 200-299. `status` and `retryAfterMs` let `isRetryable` and the retry wait act on it. */
|
|
3
|
+
export class HTTPError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
url;
|
|
6
|
+
retryAfterMs;
|
|
7
|
+
name = "HTTPError";
|
|
8
|
+
constructor(message, status, url,
|
|
9
|
+
/** From `Retry-After`, given in seconds or as an HTTP date; undefined when missing or unreadable. */
|
|
10
|
+
retryAfterMs) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.url = url;
|
|
14
|
+
this.retryAfterMs = retryAfterMs;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** `Retry-After` in milliseconds: a number of seconds, or an HTTP date (0 once it has passed). */
|
|
18
|
+
function retryAfter(header) {
|
|
19
|
+
if (header === null)
|
|
20
|
+
return undefined;
|
|
21
|
+
const text = header.trim();
|
|
22
|
+
if (/^\d+(\.\d+)?$/.test(text))
|
|
23
|
+
return Math.round(Number(text) * 1000);
|
|
24
|
+
const date = Date.parse(text);
|
|
25
|
+
return Number.isNaN(date) ? undefined : Math.max(0, date - Date.now());
|
|
26
|
+
}
|
|
27
|
+
const defaultReasoningParams = (level) => ({
|
|
28
|
+
reasoning_effort: level === "off" ? "none" : level,
|
|
29
|
+
});
|
|
30
|
+
/** A model's own reasoning as `reasoning_content`, which DeepSeek V4 requires back in tool loops. Never another model's. */
|
|
31
|
+
function reasoningOf(m, modelId) {
|
|
32
|
+
if (modelId === undefined || m.model !== modelId || !m.reasoning?.length)
|
|
33
|
+
return {};
|
|
34
|
+
const text = m.reasoning
|
|
35
|
+
.filter((r) => !r.redacted)
|
|
36
|
+
.map((r) => r.text)
|
|
37
|
+
.join("\n");
|
|
38
|
+
return text === "" ? {} : { reasoning_content: text };
|
|
39
|
+
}
|
|
40
|
+
/** URLs OpenAI takes as they are. */
|
|
41
|
+
const SENDABLE = /^(https?|data):/i;
|
|
42
|
+
const shown = (url) => (url.length > 100 ? `${url.slice(0, 100)}…` : url);
|
|
43
|
+
function imageURL(image) {
|
|
44
|
+
if ("data" in image)
|
|
45
|
+
return `data:${image.mimeType};base64,${image.data}`;
|
|
46
|
+
if (!SENDABLE.test(image.url)) {
|
|
47
|
+
throw new TypeError(`Image "${shown(image.url)}" cannot be sent as a URL; make resolveImage return { data, mimeType } or an http(s) URL`);
|
|
48
|
+
}
|
|
49
|
+
return image.url;
|
|
50
|
+
}
|
|
51
|
+
const imageOf = (image) => ({ type: "image_url", image_url: { url: imageURL(image) } });
|
|
52
|
+
const imagesIn = (content) => typeof content === "string" ? [] : content.filter((p) => p.type === "image");
|
|
53
|
+
/** OpenAI's tool messages take text only, and have no error flag: errors say so in the text. */
|
|
54
|
+
function toolText(m) {
|
|
55
|
+
const text = textOf(m.content, { imagePlaceholder: "" }) || (imagesIn(m.content).length > 0 ? "(image)" : "");
|
|
56
|
+
return m.isError && !text.startsWith("Error") ? `Error: ${text}` : text;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* taugraph messages in OpenAI's wire format. Images from tool results go into one user message right after the
|
|
60
|
+
* tool messages, since OpenAI's tool messages take text only. Image references must be read first (`resolveImage`).
|
|
61
|
+
* Pass the adapter's id as `modelId` to send that model's own reasoning back.
|
|
62
|
+
*/
|
|
63
|
+
export function toOpenAIMessages(messages, modelId) {
|
|
64
|
+
const out = [];
|
|
65
|
+
let toolImages = [];
|
|
66
|
+
const flush = () => {
|
|
67
|
+
if (toolImages.length > 0)
|
|
68
|
+
out.push({ role: "user", content: toolImages });
|
|
69
|
+
toolImages = [];
|
|
70
|
+
};
|
|
71
|
+
for (const m of messages) {
|
|
72
|
+
if (m.role === "tool") {
|
|
73
|
+
out.push({ role: "tool", tool_call_id: m.toolCallId, content: toolText(m) });
|
|
74
|
+
const images = imagesIn(m.content);
|
|
75
|
+
if (images.length > 0) {
|
|
76
|
+
toolImages.push({ type: "text", text: `Images from tool call ${m.toolCallId}:` }, ...images.map(imageOf));
|
|
77
|
+
}
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
flush();
|
|
81
|
+
if (m.role === "assistant" && m.toolCalls?.length) {
|
|
82
|
+
out.push({
|
|
83
|
+
role: "assistant",
|
|
84
|
+
content: m.content === "" ? null : m.content,
|
|
85
|
+
tool_calls: m.toolCalls.map((c) => ({
|
|
86
|
+
id: c.id,
|
|
87
|
+
type: "function",
|
|
88
|
+
function: { name: c.name, arguments: JSON.stringify(c.arguments) },
|
|
89
|
+
})),
|
|
90
|
+
...reasoningOf(m, modelId),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else if (m.role === "user" && typeof m.content !== "string") {
|
|
94
|
+
out.push({
|
|
95
|
+
role: "user",
|
|
96
|
+
content: m.content.map((p) => (p.type === "text" ? { type: "text", text: p.text } : imageOf(p))),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
out.push({ role: m.role, content: m.content, ...(m.role === "assistant" && reasoningOf(m, modelId)) });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
flush();
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
export function toOpenAITools(tools) {
|
|
107
|
+
return tools.map((t) => ({
|
|
108
|
+
type: "function",
|
|
109
|
+
function: { name: t.name, ...(t.description && { description: t.description }), parameters: t.inputSchema },
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
export function toOpenAIToolChoice(choice) {
|
|
113
|
+
return typeof choice === "string" ? choice : { type: "function", function: { name: choice.name } };
|
|
114
|
+
}
|
|
115
|
+
/** OpenAI's tool calls as taugraph's, arguments parsed. Unreadable arguments become `{}` with a `parseError`; missing ids become `call_<round>_<index>`. */
|
|
116
|
+
export function fromOpenAIToolCalls(calls, round = 1) {
|
|
117
|
+
return calls.flatMap((c, i) => {
|
|
118
|
+
const name = c.function?.name;
|
|
119
|
+
if (!name)
|
|
120
|
+
return [];
|
|
121
|
+
const raw = c.function?.arguments ?? "";
|
|
122
|
+
let parsed = {};
|
|
123
|
+
let parseError;
|
|
124
|
+
if (raw.trim() !== "") {
|
|
125
|
+
try {
|
|
126
|
+
parsed = JSON.parse(raw);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
parseError = "arguments are not valid JSON";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const isObject = typeof parsed === "object" && parsed !== null && !Array.isArray(parsed);
|
|
133
|
+
if (!parseError && !isObject)
|
|
134
|
+
parseError = "arguments are not a JSON object";
|
|
135
|
+
return [
|
|
136
|
+
{
|
|
137
|
+
id: c.id || `call_${round}_${i}`,
|
|
138
|
+
name,
|
|
139
|
+
arguments: isObject && !parseError ? parsed : {},
|
|
140
|
+
...(parseError && { parseError }),
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export function openAICompatible(options) {
|
|
146
|
+
const url = `${options.baseURL.replace(/\/+$/, "")}/chat/completions`;
|
|
147
|
+
const id = `openai-compatible:${options.model}`;
|
|
148
|
+
const tokenLimit = options.tokenLimit ?? "max_tokens";
|
|
149
|
+
if (tokenLimit !== "max_tokens" && tokenLimit !== "max_completion_tokens") {
|
|
150
|
+
throw new TypeError(`openAICompatible: tokenLimit must be "max_tokens" or "max_completion_tokens", got ${String(options.tokenLimit)}`);
|
|
151
|
+
}
|
|
152
|
+
const readImage = (image) => {
|
|
153
|
+
if (/^https?:/i.test(image))
|
|
154
|
+
return { type: "image", url: image };
|
|
155
|
+
if (!options.resolveImage)
|
|
156
|
+
throw new TypeError(`Image "${shown(image)}" needs resolveImage to be read`);
|
|
157
|
+
return options.resolveImage(image);
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
id,
|
|
161
|
+
async complete(request, { signal }) {
|
|
162
|
+
const messages = await resolveImages(request.messages, readImage);
|
|
163
|
+
const response = await (options.fetch ?? fetch)(url, {
|
|
164
|
+
method: "POST",
|
|
165
|
+
signal,
|
|
166
|
+
headers: {
|
|
167
|
+
"content-type": "application/json",
|
|
168
|
+
...(options.apiKey && { authorization: `Bearer ${options.apiKey}` }),
|
|
169
|
+
},
|
|
170
|
+
body: JSON.stringify({
|
|
171
|
+
model: options.model,
|
|
172
|
+
messages: toOpenAIMessages(messages, options.sendReasoning === false ? undefined : id),
|
|
173
|
+
temperature: request.temperature,
|
|
174
|
+
[tokenLimit]: request.maxTokens,
|
|
175
|
+
...(request.responseFormat === "json" && { response_format: { type: "json_object" } }),
|
|
176
|
+
...(request.tools?.length && { tools: toOpenAITools(request.tools) }),
|
|
177
|
+
...(request.toolChoice && { tool_choice: toOpenAIToolChoice(request.toolChoice) }),
|
|
178
|
+
...(request.reasoning && (options.reasoningParams ?? defaultReasoningParams)(request.reasoning)),
|
|
179
|
+
...request.extra,
|
|
180
|
+
}),
|
|
181
|
+
});
|
|
182
|
+
if (!response.ok) {
|
|
183
|
+
const text = await response.text().catch(() => "");
|
|
184
|
+
throw new HTTPError(`${url} responded ${response.status}: ${text.slice(0, 500)}`, response.status, url, retryAfter(response.headers.get("retry-after")));
|
|
185
|
+
}
|
|
186
|
+
const body = (await response.json());
|
|
187
|
+
const choice = body.choices?.[0];
|
|
188
|
+
const calls = choice?.message?.tool_calls;
|
|
189
|
+
const round = request.messages.filter((m) => m.role === "assistant").length + 1;
|
|
190
|
+
const message = choice?.message;
|
|
191
|
+
const thought = message?.reasoning_content || message?.reasoning;
|
|
192
|
+
const reasoningTokens = body.usage?.completion_tokens_details?.reasoning_tokens;
|
|
193
|
+
return {
|
|
194
|
+
content: message?.content ?? "",
|
|
195
|
+
...(body.model && { model: body.model }),
|
|
196
|
+
...(choice?.finish_reason && { finishReason: choice.finish_reason }),
|
|
197
|
+
usage: {
|
|
198
|
+
inputTokens: body.usage?.prompt_tokens ?? 0,
|
|
199
|
+
outputTokens: body.usage?.completion_tokens ?? 0,
|
|
200
|
+
...(typeof reasoningTokens === "number" && { reasoningTokens }),
|
|
201
|
+
},
|
|
202
|
+
...(thought && { reasoning: [{ text: thought }] }),
|
|
203
|
+
...(calls?.length && { toolCalls: fromOpenAIToolCalls(calls, round) }),
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAOL,aAAa,EAIb,MAAM,GACP,MAAM,mBAAmB,CAAC;AAgC3B,8GAA8G;AAC9G,MAAM,OAAO,SAAU,SAAQ,KAAK;IAIvB,MAAM;IACN,GAAG;IAEH,YAAY;IANL,IAAI,GAAG,WAAW,CAAC;IACrC,YACE,OAAe,EACN,MAAc,EACd,GAAW;IACpB,qGAAqG;IAC5F,YAAgC;QAEzC,KAAK,CAAC,OAAO,CAAC,CAAC;sBALN,MAAM;mBACN,GAAG;4BAEH,YAAY;IAGvB,CAAC;CACF;AAED,kGAAkG;AAClG,SAAS,UAAU,CAAC,MAAqB;IACvC,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACtC,M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IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;gBACxC,GAAG,CAAC,MAAM,EAAE,aAAa,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;gBACpE,KAAK,EAAE;oBACL,WAAW,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,IAAI,CAAC;oBAC3C,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,IAAI,CAAC;oBAChD,GAAG,CAAC,OAAO,eAAe,KAAK,QAAQ,IAAI,EAAE,eAAe,EAAE,CAAC;iBAChE;gBACD,GAAG,CAAC,OAAO,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;gBAClD,GAAG,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,SAAS,EAAE,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;aACvE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taugraph",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Minimal typed agent graph harness: a graph + typed-state kernel with append-only traces and
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Minimal typed agent graph harness: a graph + typed-state kernel with append-only traces, replay and pause/resume. Zero runtime dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
7
7
|
"llm",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"trace",
|
|
13
13
|
"replay",
|
|
14
14
|
"standard-schema",
|
|
15
|
-
"zod"
|
|
15
|
+
"zod",
|
|
16
|
+
"human-in-the-loop",
|
|
17
|
+
"pause-resume"
|
|
16
18
|
],
|
|
17
19
|
"license": "MIT",
|
|
18
20
|
"author": "wangcao-hub (https://github.com/wangcao-hub)",
|
|
@@ -35,6 +37,18 @@
|
|
|
35
37
|
"types": "./dist/nodes/index.d.ts",
|
|
36
38
|
"import": "./dist/nodes/index.js"
|
|
37
39
|
},
|
|
40
|
+
"./agent": {
|
|
41
|
+
"types": "./dist/agent/index.d.ts",
|
|
42
|
+
"import": "./dist/agent/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./openai": {
|
|
45
|
+
"types": "./dist/openai/index.d.ts",
|
|
46
|
+
"import": "./dist/openai/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./file": {
|
|
49
|
+
"types": "./dist/file/index.d.ts",
|
|
50
|
+
"import": "./dist/file/index.js"
|
|
51
|
+
},
|
|
38
52
|
"./package.json": "./package.json"
|
|
39
53
|
},
|
|
40
54
|
"files": [
|
|
@@ -42,6 +56,7 @@
|
|
|
42
56
|
"src",
|
|
43
57
|
"README.md",
|
|
44
58
|
"README.zh-CN.md",
|
|
59
|
+
"CHANGELOG.md",
|
|
45
60
|
"LICENSE"
|
|
46
61
|
],
|
|
47
62
|
"engines": {
|
|
@@ -54,7 +69,7 @@
|
|
|
54
69
|
"packageManager": "pnpm@9.15.9",
|
|
55
70
|
"scripts": {
|
|
56
71
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
57
|
-
"typecheck": "tsc --noEmit",
|
|
72
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.core.json",
|
|
58
73
|
"lint": "biome check .",
|
|
59
74
|
"format": "biome check --write .",
|
|
60
75
|
"test": "vitest run",
|
|
@@ -63,6 +78,7 @@
|
|
|
63
78
|
"example:quickstart": "tsx examples/quickstart.ts",
|
|
64
79
|
"example:rag": "tsx examples/rag-retry.ts",
|
|
65
80
|
"example:checkout": "tsx examples/checkout.ts",
|
|
81
|
+
"example:agent": "tsx examples/agent.ts",
|
|
66
82
|
"prepublishOnly": "pnpm check && pnpm build"
|
|
67
83
|
},
|
|
68
84
|
"devDependencies": {
|