taugraph 0.0.0-stage → 0.3.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 +62 -0
- package/LICENSE +21 -0
- package/README.md +447 -2
- package/README.zh-CN.md +448 -0
- package/dist/agent/index.d.ts +66 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +228 -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 +9 -0
- package/dist/agent/util.d.ts.map +1 -0
- package/dist/agent/util.js +28 -0
- package/dist/agent/util.js.map +1 -0
- package/dist/core/engine.d.ts +51 -0
- package/dist/core/engine.d.ts.map +1 -0
- package/dist/core/engine.js +412 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/errors.d.ts +48 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +30 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/graph.d.ts +11 -0
- package/dist/core/graph.d.ts.map +1 -0
- package/dist/core/graph.js +134 -0
- package/dist/core/graph.js.map +1 -0
- package/dist/core/node.d.ts +7 -0
- package/dist/core/node.d.ts.map +1 -0
- package/dist/core/node.js +22 -0
- package/dist/core/node.js.map +1 -0
- package/dist/core/standard-schema.d.ts +39 -0
- package/dist/core/standard-schema.d.ts.map +1 -0
- package/dist/core/standard-schema.js +2 -0
- package/dist/core/standard-schema.js.map +1 -0
- package/dist/core/trace.d.ts +90 -0
- package/dist/core/trace.d.ts.map +1 -0
- package/dist/core/trace.js +290 -0
- package/dist/core/trace.js.map +1 -0
- package/dist/core/types.d.ts +175 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/util.d.ts +19 -0
- package/dist/core/util.d.ts.map +1 -0
- package/dist/core/util.js +85 -0
- package/dist/core/util.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/code.d.ts +12 -0
- package/dist/nodes/code.d.ts.map +1 -0
- package/dist/nodes/code.js +9 -0
- package/dist/nodes/code.js.map +1 -0
- 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/human.d.ts +17 -0
- package/dist/nodes/human.d.ts.map +1 -0
- package/dist/nodes/human.js +18 -0
- package/dist/nodes/human.js.map +1 -0
- package/dist/nodes/index.d.ts +5 -0
- package/dist/nodes/index.d.ts.map +1 -0
- package/dist/nodes/index.js +7 -0
- package/dist/nodes/index.js.map +1 -0
- package/dist/nodes/llm.d.ts +157 -0
- package/dist/nodes/llm.d.ts.map +1 -0
- package/dist/nodes/llm.js +54 -0
- package/dist/nodes/llm.js.map +1 -0
- package/dist/nodes/util.d.ts +5 -0
- package/dist/nodes/util.d.ts.map +1 -0
- package/dist/nodes/util.js +11 -0
- package/dist/nodes/util.js.map +1 -0
- package/dist/openai/index.d.ts +39 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +178 -0
- package/dist/openai/index.js.map +1 -0
- package/package.json +86 -4
- package/src/agent/index.ts +315 -0
- package/src/agent/state.ts +147 -0
- package/src/agent/util.ts +35 -0
- package/src/core/engine.ts +552 -0
- package/src/core/errors.ts +70 -0
- package/src/core/graph.ts +166 -0
- package/src/core/node.ts +24 -0
- package/src/core/standard-schema.ts +47 -0
- package/src/core/trace.ts +346 -0
- package/src/core/types.ts +206 -0
- package/src/core/util.ts +81 -0
- package/src/index.ts +46 -0
- package/src/nodes/code.ts +18 -0
- package/src/nodes/content.ts +100 -0
- package/src/nodes/human.ts +33 -0
- package/src/nodes/index.ts +25 -0
- package/src/nodes/llm.ts +219 -0
- package/src/nodes/util.ts +13 -0
- package/src/openai/index.ts +246 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type MaybePromise, type Node, type RetryPolicy, type StandardSchemaV1 } from "../index.js";
|
|
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;
|
|
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
|
+
};
|
|
85
|
+
/** Everything in a request is recorded in the trace, so keep it plain JSON. */
|
|
86
|
+
export interface LLMRequest {
|
|
87
|
+
readonly messages: readonly ChatMessage[];
|
|
88
|
+
readonly temperature?: number;
|
|
89
|
+
readonly maxTokens?: number;
|
|
90
|
+
/** Hint for adapters that support JSON mode. */
|
|
91
|
+
readonly responseFormat?: "text" | "json";
|
|
92
|
+
/** Provider-specific options, passed through by the adapter. */
|
|
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;
|
|
99
|
+
}
|
|
100
|
+
export interface LLMResponse {
|
|
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`. */
|
|
103
|
+
readonly model?: string;
|
|
104
|
+
readonly finishReason?: string;
|
|
105
|
+
readonly usage?: {
|
|
106
|
+
readonly inputTokens?: number;
|
|
107
|
+
readonly outputTokens?: number;
|
|
108
|
+
/** Tokens spent thinking; already counted in `outputTokens`. */
|
|
109
|
+
readonly reasoningTokens?: number;
|
|
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[];
|
|
115
|
+
}
|
|
116
|
+
export interface LLMModel {
|
|
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
|
+
*/
|
|
121
|
+
readonly id: string;
|
|
122
|
+
complete(request: LLMRequest, options: {
|
|
123
|
+
readonly signal: AbortSignal;
|
|
124
|
+
}): MaybePromise<LLMResponse>;
|
|
125
|
+
}
|
|
126
|
+
interface LLMNodeBase<S> {
|
|
127
|
+
readonly model: LLMModel;
|
|
128
|
+
/** Builds the request from state. A string becomes a single user message. */
|
|
129
|
+
readonly prompt: (state: S) => LLMRequest | string;
|
|
130
|
+
/** Retries the whole call, including output parsing. */
|
|
131
|
+
readonly retry?: RetryPolicy;
|
|
132
|
+
}
|
|
133
|
+
export interface LLMTextNodeConfig<S> extends LLMNodeBase<S> {
|
|
134
|
+
/** Folds the reply into state. The return type does not drive inference; the graph does. */
|
|
135
|
+
readonly update: (state: S, text: string, response: LLMResponse) => NoInfer<S>;
|
|
136
|
+
}
|
|
137
|
+
export interface LLMStructuredNodeConfig<S, T> extends LLMNodeBase<S> {
|
|
138
|
+
/** Parses the response content as JSON (code fences allowed) and validates it. */
|
|
139
|
+
readonly output: StandardSchemaV1<unknown, T>;
|
|
140
|
+
readonly update: (state: S, data: T, response: LLMResponse) => NoInfer<S>;
|
|
141
|
+
}
|
|
142
|
+
/** Thrown when structured output is not JSON or fails its schema. Retryable. */
|
|
143
|
+
export declare class LLMOutputError extends Error {
|
|
144
|
+
readonly content: string;
|
|
145
|
+
readonly issues?: readonly StandardSchemaV1.Issue[] | undefined;
|
|
146
|
+
readonly name = "LLMOutputError";
|
|
147
|
+
constructor(message: string, content: string, issues?: readonly StandardSchemaV1.Issue[] | undefined);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Calls a model and folds the result into state. Every call is appended to the trace
|
|
151
|
+
* as an `llm_call` event (request in `input`, response in `output`).
|
|
152
|
+
* Stays synchronous when the model does, so mock models work with `runSync`.
|
|
153
|
+
*/
|
|
154
|
+
export declare function LLMNode<S, T>(config: LLMStructuredNodeConfig<S, T>): Node<S>;
|
|
155
|
+
export declare function LLMNode<S>(config: LLMTextNodeConfig<S>): Node<S>;
|
|
156
|
+
export {};
|
|
157
|
+
//# sourceMappingURL=llm.d.ts.map
|
|
@@ -0,0 +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,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,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,sGAAsG;IACtG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,mHAAmH;IACnH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,kFAAkF;AAClF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,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KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CAC3E;AAED,gFAAgF;AAChF,qBAAa,cAAe,SAAQ,KAAK;IAIrC,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,gBAAgB,CAAC,KAAK,EAAE;IAJrD,SAAkB,IAAI,oBAAoB;IAC1C,YACE,OAAO,EAAE,MAAM,EACN,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,SAAS,gBAAgB,CAAC,KAAK,EAAE,YAAA,EAGpD;CACF;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAC9E,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { defineNode } from "../index.js";
|
|
2
|
+
import { andThen, issuesMessage } from "./util.js";
|
|
3
|
+
/** Thrown when structured output is not JSON or fails its schema. Retryable. */
|
|
4
|
+
export class LLMOutputError extends Error {
|
|
5
|
+
content;
|
|
6
|
+
issues;
|
|
7
|
+
name = "LLMOutputError";
|
|
8
|
+
constructor(message, content, issues) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.content = content;
|
|
11
|
+
this.issues = issues;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function LLMNode(config) {
|
|
15
|
+
const { model, prompt } = config;
|
|
16
|
+
return defineNode((state, ctx) => {
|
|
17
|
+
const built = prompt(state);
|
|
18
|
+
const request = typeof built === "string" ? { messages: [{ role: "user", content: built }] } : built;
|
|
19
|
+
const startedAt = Date.now();
|
|
20
|
+
return andThen(model.complete(request, { signal: ctx.signal }), (response) => {
|
|
21
|
+
if (typeof response?.content !== "string") {
|
|
22
|
+
throw new TypeError(`Model "${model.id}" returned a response without a string \`content\``);
|
|
23
|
+
}
|
|
24
|
+
ctx.trace.append({
|
|
25
|
+
type: "llm_call",
|
|
26
|
+
input: request,
|
|
27
|
+
output: response,
|
|
28
|
+
meta: { model: model.id, durationMs: Date.now() - startedAt },
|
|
29
|
+
});
|
|
30
|
+
if (!("output" in config))
|
|
31
|
+
return config.update(state, response.content, response);
|
|
32
|
+
return andThen(parseStructured(config.output, response.content), (data) => config.update(state, data, response));
|
|
33
|
+
});
|
|
34
|
+
}, { kind: "llm", ...(config.retry && { retry: config.retry }) });
|
|
35
|
+
}
|
|
36
|
+
function parseStructured(schema, content) {
|
|
37
|
+
const fenced = /```(?:json)?\s*([\s\S]*?)```/i.exec(content);
|
|
38
|
+
const text = (fenced?.[1] ?? content).trim();
|
|
39
|
+
let json;
|
|
40
|
+
try {
|
|
41
|
+
json = JSON.parse(text);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw new LLMOutputError("Model output is not valid JSON", content);
|
|
45
|
+
}
|
|
46
|
+
return andThen(schema["~standard"].validate(json), (result) => {
|
|
47
|
+
if (result.issues) {
|
|
48
|
+
const detail = issuesMessage(result.issues);
|
|
49
|
+
throw new LLMOutputError(`Model output does not match the schema: ${detail}`, content, result.issues);
|
|
50
|
+
}
|
|
51
|
+
return result.value;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=llm.js.map
|
|
@@ -0,0 +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;AA0JnD,gFAAgF;AAChF,MAAM,OAAO,cAAe,SAAQ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OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MaybePromise, StandardSchemaV1 } from "../index.js";
|
|
2
|
+
/** Chains without introducing a Promise when the value is synchronous, so nodes stay `runSync`-friendly. */
|
|
3
|
+
export declare function andThen<A, B>(value: MaybePromise<A>, fn: (value: A) => MaybePromise<B>): MaybePromise<B>;
|
|
4
|
+
export declare function issuesMessage(issues: readonly StandardSchemaV1.Issue[]): string;
|
|
5
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/nodes/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAElE,4GAA4G;AAC5G,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAKxG;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,gBAAgB,CAAC,KAAK,EAAE,GAAG,MAAM,CAE/E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Chains without introducing a Promise when the value is synchronous, so nodes stay `runSync`-friendly. */
|
|
2
|
+
export function andThen(value, fn) {
|
|
3
|
+
if (value !== null && typeof value === "object" && typeof value.then === "function") {
|
|
4
|
+
return Promise.resolve(value).then(fn);
|
|
5
|
+
}
|
|
6
|
+
return fn(value);
|
|
7
|
+
}
|
|
8
|
+
export function issuesMessage(issues) {
|
|
9
|
+
return issues.map((issue) => issue.message).join("; ");
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/nodes/util.ts"],"names":[],"mappings":"AAEA,4GAA4G;AAC5G,MAAM,UAAU,OAAO,CAAO,KAAsB,EAAE,EAAiC;IACrF,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAQ,KAAwB,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACxG,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,CAAC,KAAU,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAyC;IACrE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
/** Used instead of the global `fetch`, e.g. for a proxy, retries or tests. */
|
|
17
|
+
readonly fetch?: typeof fetch | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** A tool call as OpenAI sends it: arguments are a JSON string. */
|
|
20
|
+
export interface OpenAIToolCall {
|
|
21
|
+
readonly id?: string;
|
|
22
|
+
readonly type?: string;
|
|
23
|
+
readonly function?: {
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
readonly arguments?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* taugraph messages in OpenAI's wire format. Images from tool results go into one user message right after the
|
|
30
|
+
* tool messages, since OpenAI's tool messages take text only. Image references must be read first (`resolveImage`).
|
|
31
|
+
* Pass the adapter's id as `modelId` to send that model's own reasoning back.
|
|
32
|
+
*/
|
|
33
|
+
export declare function toOpenAIMessages(messages: readonly ChatMessage[], modelId?: string): Record<string, unknown>[];
|
|
34
|
+
export declare function toOpenAITools(tools: readonly ToolSpec[]): Record<string, unknown>[];
|
|
35
|
+
export declare function toOpenAIToolChoice(choice: ToolChoice): unknown;
|
|
36
|
+
/** OpenAI's tool calls as taugraph's, arguments parsed. Unreadable arguments become `{}` with a `parseError`; missing ids become `call_<round>_<index>`. */
|
|
37
|
+
export declare function fromOpenAIToolCalls(calls: readonly OpenAIToolCall[], round?: number): ToolCall[];
|
|
38
|
+
export declare function openAICompatible(options: OpenAICompatibleOptions): LLMModel;
|
|
39
|
+
//# 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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,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,CAuD3E"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { resolveImages, textOf, } from "../nodes/index.js";
|
|
2
|
+
const defaultReasoningParams = (level) => ({
|
|
3
|
+
reasoning_effort: level === "off" ? "none" : level,
|
|
4
|
+
});
|
|
5
|
+
/** A model's own reasoning as `reasoning_content`, which DeepSeek V4 requires back in tool loops. Never another model's. */
|
|
6
|
+
function reasoningOf(m, modelId) {
|
|
7
|
+
if (modelId === undefined || m.model !== modelId || !m.reasoning?.length)
|
|
8
|
+
return {};
|
|
9
|
+
const text = m.reasoning
|
|
10
|
+
.filter((r) => !r.redacted)
|
|
11
|
+
.map((r) => r.text)
|
|
12
|
+
.join("\n");
|
|
13
|
+
return text === "" ? {} : { reasoning_content: text };
|
|
14
|
+
}
|
|
15
|
+
/** URLs OpenAI takes as they are. */
|
|
16
|
+
const SENDABLE = /^(https?|data):/i;
|
|
17
|
+
const shown = (url) => (url.length > 100 ? `${url.slice(0, 100)}…` : url);
|
|
18
|
+
function imageURL(image) {
|
|
19
|
+
if ("data" in image)
|
|
20
|
+
return `data:${image.mimeType};base64,${image.data}`;
|
|
21
|
+
if (!SENDABLE.test(image.url)) {
|
|
22
|
+
throw new TypeError(`Image "${shown(image.url)}" cannot be sent as a URL; make resolveImage return { data, mimeType } or an http(s) URL`);
|
|
23
|
+
}
|
|
24
|
+
return image.url;
|
|
25
|
+
}
|
|
26
|
+
const imageOf = (image) => ({ type: "image_url", image_url: { url: imageURL(image) } });
|
|
27
|
+
const imagesIn = (content) => typeof content === "string" ? [] : content.filter((p) => p.type === "image");
|
|
28
|
+
/** OpenAI's tool messages take text only, and have no error flag: errors say so in the text. */
|
|
29
|
+
function toolText(m) {
|
|
30
|
+
const text = textOf(m.content, { imagePlaceholder: "" }) || (imagesIn(m.content).length > 0 ? "(image)" : "");
|
|
31
|
+
return m.isError && !text.startsWith("Error") ? `Error: ${text}` : text;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* taugraph messages in OpenAI's wire format. Images from tool results go into one user message right after the
|
|
35
|
+
* tool messages, since OpenAI's tool messages take text only. Image references must be read first (`resolveImage`).
|
|
36
|
+
* Pass the adapter's id as `modelId` to send that model's own reasoning back.
|
|
37
|
+
*/
|
|
38
|
+
export function toOpenAIMessages(messages, modelId) {
|
|
39
|
+
const out = [];
|
|
40
|
+
let toolImages = [];
|
|
41
|
+
const flush = () => {
|
|
42
|
+
if (toolImages.length > 0)
|
|
43
|
+
out.push({ role: "user", content: toolImages });
|
|
44
|
+
toolImages = [];
|
|
45
|
+
};
|
|
46
|
+
for (const m of messages) {
|
|
47
|
+
if (m.role === "tool") {
|
|
48
|
+
out.push({ role: "tool", tool_call_id: m.toolCallId, content: toolText(m) });
|
|
49
|
+
const images = imagesIn(m.content);
|
|
50
|
+
if (images.length > 0) {
|
|
51
|
+
toolImages.push({ type: "text", text: `Images from tool call ${m.toolCallId}:` }, ...images.map(imageOf));
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
flush();
|
|
56
|
+
if (m.role === "assistant" && m.toolCalls?.length) {
|
|
57
|
+
out.push({
|
|
58
|
+
role: "assistant",
|
|
59
|
+
content: m.content === "" ? null : m.content,
|
|
60
|
+
tool_calls: m.toolCalls.map((c) => ({
|
|
61
|
+
id: c.id,
|
|
62
|
+
type: "function",
|
|
63
|
+
function: { name: c.name, arguments: JSON.stringify(c.arguments) },
|
|
64
|
+
})),
|
|
65
|
+
...reasoningOf(m, modelId),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else if (m.role === "user" && typeof m.content !== "string") {
|
|
69
|
+
out.push({
|
|
70
|
+
role: "user",
|
|
71
|
+
content: m.content.map((p) => (p.type === "text" ? { type: "text", text: p.text } : imageOf(p))),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
out.push({ role: m.role, content: m.content, ...(m.role === "assistant" && reasoningOf(m, modelId)) });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
flush();
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
export function toOpenAITools(tools) {
|
|
82
|
+
return tools.map((t) => ({
|
|
83
|
+
type: "function",
|
|
84
|
+
function: { name: t.name, ...(t.description && { description: t.description }), parameters: t.inputSchema },
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
export function toOpenAIToolChoice(choice) {
|
|
88
|
+
return typeof choice === "string" ? choice : { type: "function", function: { name: choice.name } };
|
|
89
|
+
}
|
|
90
|
+
/** OpenAI's tool calls as taugraph's, arguments parsed. Unreadable arguments become `{}` with a `parseError`; missing ids become `call_<round>_<index>`. */
|
|
91
|
+
export function fromOpenAIToolCalls(calls, round = 1) {
|
|
92
|
+
return calls.flatMap((c, i) => {
|
|
93
|
+
const name = c.function?.name;
|
|
94
|
+
if (!name)
|
|
95
|
+
return [];
|
|
96
|
+
const raw = c.function?.arguments ?? "";
|
|
97
|
+
let parsed = {};
|
|
98
|
+
let parseError;
|
|
99
|
+
if (raw.trim() !== "") {
|
|
100
|
+
try {
|
|
101
|
+
parsed = JSON.parse(raw);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
parseError = "arguments are not valid JSON";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const isObject = typeof parsed === "object" && parsed !== null && !Array.isArray(parsed);
|
|
108
|
+
if (!parseError && !isObject)
|
|
109
|
+
parseError = "arguments are not a JSON object";
|
|
110
|
+
return [
|
|
111
|
+
{
|
|
112
|
+
id: c.id || `call_${round}_${i}`,
|
|
113
|
+
name,
|
|
114
|
+
arguments: isObject && !parseError ? parsed : {},
|
|
115
|
+
...(parseError && { parseError }),
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
export function openAICompatible(options) {
|
|
121
|
+
const url = `${options.baseURL.replace(/\/+$/, "")}/chat/completions`;
|
|
122
|
+
const id = `openai-compatible:${options.model}`;
|
|
123
|
+
const readImage = (image) => {
|
|
124
|
+
if (/^https?:/i.test(image))
|
|
125
|
+
return { type: "image", url: image };
|
|
126
|
+
if (!options.resolveImage)
|
|
127
|
+
throw new TypeError(`Image "${shown(image)}" needs resolveImage to be read`);
|
|
128
|
+
return options.resolveImage(image);
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
id,
|
|
132
|
+
async complete(request, { signal }) {
|
|
133
|
+
const messages = await resolveImages(request.messages, readImage);
|
|
134
|
+
const response = await (options.fetch ?? fetch)(url, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
signal,
|
|
137
|
+
headers: {
|
|
138
|
+
"content-type": "application/json",
|
|
139
|
+
...(options.apiKey && { authorization: `Bearer ${options.apiKey}` }),
|
|
140
|
+
},
|
|
141
|
+
body: JSON.stringify({
|
|
142
|
+
model: options.model,
|
|
143
|
+
messages: toOpenAIMessages(messages, options.sendReasoning === false ? undefined : id),
|
|
144
|
+
temperature: request.temperature,
|
|
145
|
+
max_tokens: request.maxTokens,
|
|
146
|
+
...(request.responseFormat === "json" && { response_format: { type: "json_object" } }),
|
|
147
|
+
...(request.tools?.length && { tools: toOpenAITools(request.tools) }),
|
|
148
|
+
...(request.toolChoice && { tool_choice: toOpenAIToolChoice(request.toolChoice) }),
|
|
149
|
+
...(request.reasoning && (options.reasoningParams ?? defaultReasoningParams)(request.reasoning)),
|
|
150
|
+
...request.extra,
|
|
151
|
+
}),
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new Error(`${url} responded ${response.status}: ${(await response.text()).slice(0, 500)}`);
|
|
155
|
+
}
|
|
156
|
+
const body = (await response.json());
|
|
157
|
+
const choice = body.choices?.[0];
|
|
158
|
+
const calls = choice?.message?.tool_calls;
|
|
159
|
+
const round = request.messages.filter((m) => m.role === "assistant").length + 1;
|
|
160
|
+
const message = choice?.message;
|
|
161
|
+
const thought = message?.reasoning_content || message?.reasoning;
|
|
162
|
+
const reasoningTokens = body.usage?.completion_tokens_details?.reasoning_tokens;
|
|
163
|
+
return {
|
|
164
|
+
content: message?.content ?? "",
|
|
165
|
+
...(body.model && { model: body.model }),
|
|
166
|
+
...(choice?.finish_reason && { finishReason: choice.finish_reason }),
|
|
167
|
+
usage: {
|
|
168
|
+
inputTokens: body.usage?.prompt_tokens ?? 0,
|
|
169
|
+
outputTokens: body.usage?.completion_tokens ?? 0,
|
|
170
|
+
...(typeof reasoningTokens === "number" && { reasoningTokens }),
|
|
171
|
+
},
|
|
172
|
+
...(thought && { reasoning: [{ text: thought }] }),
|
|
173
|
+
...(calls?.length && { toolCalls: fromOpenAIToolCalls(calls, round) }),
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//# 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;AA+C3B,MAAM,sBAAsB,GAAG,CAAC,KAAqB,EAA2B,EAAE,CAAC,CAAC;IAClF,gBAAgB,EAAE,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;CACnD,CAAC,CAAC;AAEH,4HAA4H;AAC5H,SAAS,WAAW,CAClB,CAA8C,EAC9C,OAA2B;IAE3B,IAAI,OAAO,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM;QAAE,OAAO,EAAE,CAAC;IACpF,MAAM,IAAI,G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K,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,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taugraph",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.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
|
+
"keywords": [
|
|
6
|
+
"agent",
|
|
7
|
+
"llm",
|
|
8
|
+
"graph",
|
|
9
|
+
"orchestration",
|
|
10
|
+
"workflow",
|
|
11
|
+
"state-machine",
|
|
12
|
+
"trace",
|
|
13
|
+
"replay",
|
|
14
|
+
"standard-schema",
|
|
15
|
+
"zod",
|
|
16
|
+
"human-in-the-loop",
|
|
17
|
+
"pause-resume"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "wangcao-hub (https://github.com/wangcao-hub)",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/wangcao-hub/taugraph.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/wangcao-hub/taugraph#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/wangcao-hub/taugraph/issues"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./nodes": {
|
|
37
|
+
"types": "./dist/nodes/index.d.ts",
|
|
38
|
+
"import": "./dist/nodes/index.js"
|
|
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
|
+
"./package.json": "./package.json"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"src",
|
|
53
|
+
"README.md",
|
|
54
|
+
"README.zh-CN.md",
|
|
55
|
+
"CHANGELOG.md",
|
|
56
|
+
"LICENSE"
|
|
57
|
+
],
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=22"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public",
|
|
63
|
+
"registry": "https://registry.npmjs.org/"
|
|
64
|
+
},
|
|
65
|
+
"packageManager": "pnpm@9.15.9",
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
68
|
+
"typecheck": "tsc --noEmit",
|
|
69
|
+
"lint": "biome check .",
|
|
70
|
+
"format": "biome check --write .",
|
|
71
|
+
"test": "vitest run",
|
|
72
|
+
"test:watch": "vitest",
|
|
73
|
+
"check": "pnpm typecheck && pnpm lint && pnpm test",
|
|
74
|
+
"example:quickstart": "tsx examples/quickstart.ts",
|
|
75
|
+
"example:rag": "tsx examples/rag-retry.ts",
|
|
76
|
+
"example:checkout": "tsx examples/checkout.ts",
|
|
77
|
+
"example:agent": "tsx examples/agent.ts",
|
|
78
|
+
"prepublishOnly": "pnpm check && pnpm build"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@biomejs/biome": "^2",
|
|
82
|
+
"@types/node": "^24",
|
|
83
|
+
"tsx": "^4",
|
|
84
|
+
"typescript": "^7",
|
|
85
|
+
"vitest": "^5",
|
|
86
|
+
"zod": "^4"
|
|
87
|
+
}
|
|
88
|
+
}
|