@triggerlink/sdk 0.4.2 → 0.4.4
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/README.md +8 -0
- package/dist/agent.d.ts +23 -1
- package/dist/agent.js +20 -1
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,6 +122,14 @@ Notes:
|
|
|
122
122
|
*L + T* platform callbacks (one per step). Each step appears in the dashboard run detail
|
|
123
123
|
with its output — per-call tracing and token usage for free.
|
|
124
124
|
- **Multi-tool responses** are executed sequentially in array order, one step each.
|
|
125
|
+
- **Structured tool outputs**: `AgentResult.toolCalls` lists every tool execution of the run
|
|
126
|
+
(`{ toolCallId, toolName, input, output }`, in order; rebuilt from memos on recovery).
|
|
127
|
+
This covers the "done tool writes to shared state" pattern from agent frameworks like
|
|
128
|
+
AgentKit — read the tool's output here instead of parsing the final text.
|
|
129
|
+
- **Message history**: `AgentResult.output` is the full conversation (user input, assistant
|
|
130
|
+
turns, tool results), each element carrying `role`/`content` — same field name and shape as
|
|
131
|
+
AgentKit's `result.output`, so helpers like `findLastIndex((m) => m.role === "assistant")`
|
|
132
|
+
port directly. `lastAssistantTextMessageContent(result)` is the built-in shortcut.
|
|
125
133
|
- **`redact` hook** (optional): transforms each step's output inside `step.run` before
|
|
126
134
|
persistence, e.g. to strip secrets or PII from memos. It must be deterministic and
|
|
127
135
|
replay-safe — the memo is what the model sees of its own prior turns after a crash-resume:
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LanguageModel } from "ai";
|
|
1
|
+
import { type LanguageModel, type ModelMessage } from "ai";
|
|
2
2
|
import type { ZodType } from "zod";
|
|
3
3
|
import type { StepTool } from "./step.js";
|
|
4
4
|
export { anthropic, createAnthropic } from "@ai-sdk/anthropic";
|
|
@@ -52,6 +52,28 @@ export interface AgentResult {
|
|
|
52
52
|
inputTokens: number;
|
|
53
53
|
outputTokens: number;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* 本次运行的全部工具执行记录(按执行顺序,含结构化输出)。
|
|
57
|
+
* 覆盖 AgentKit 的 "done 工具写 state.kv" 模式:函数代码从这里的 output 读取
|
|
58
|
+
* 工具产出,无需解析最终文本。恢复重放时 memo 命中路径同样重建该列表。
|
|
59
|
+
*/
|
|
60
|
+
toolCalls: AgentToolCallRecord[];
|
|
61
|
+
/**
|
|
62
|
+
* 完整对话历史(user 输入 + 各轮 assistant 消息 + 工具结果),字段名与 AgentKit
|
|
63
|
+
* 的 result.output 对齐——可自行 findLastIndex 等遍历(元素含 role/content)。
|
|
64
|
+
* 恢复重放时由 memo 原样重建;启用 redact 时历史内容即脱敏后内容。
|
|
65
|
+
*/
|
|
66
|
+
output: ModelMessage[];
|
|
67
|
+
}
|
|
68
|
+
/** 取最后一条 assistant 消息的文本内容(拼接所有 text part);没有则返回 undefined。 */
|
|
69
|
+
export declare function lastAssistantTextMessageContent(result: AgentResult): string | undefined;
|
|
70
|
+
/** 一次工具执行的记录。 */
|
|
71
|
+
export interface AgentToolCallRecord {
|
|
72
|
+
toolCallId: string;
|
|
73
|
+
toolName: string;
|
|
74
|
+
input: unknown;
|
|
75
|
+
/** 工具的返回值(redact 钩子启用时为脱敏后的值——与模型所见一致) */
|
|
76
|
+
output: unknown;
|
|
55
77
|
}
|
|
56
78
|
export interface Agent {
|
|
57
79
|
readonly name: string;
|
package/dist/agent.js
CHANGED
|
@@ -23,6 +23,22 @@ export function createTool(def) {
|
|
|
23
23
|
throw new Error("createTool: handler is required");
|
|
24
24
|
return def;
|
|
25
25
|
}
|
|
26
|
+
/** 取最后一条 assistant 消息的文本内容(拼接所有 text part);没有则返回 undefined。 */
|
|
27
|
+
export function lastAssistantTextMessageContent(result) {
|
|
28
|
+
// 不用 findLast:tsconfig lib 为 ES2022
|
|
29
|
+
for (let i = result.output.length - 1; i >= 0; i--) {
|
|
30
|
+
const msg = result.output[i];
|
|
31
|
+
if (msg.role !== "assistant")
|
|
32
|
+
continue;
|
|
33
|
+
if (typeof msg.content === "string")
|
|
34
|
+
return msg.content;
|
|
35
|
+
return msg.content
|
|
36
|
+
.filter((p) => p.type === "text")
|
|
37
|
+
.map((p) => p.text)
|
|
38
|
+
.join("");
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
26
42
|
/** redact 钩子可能破坏 llm memo 结构;此处 fail loud,不让坏 memo 落库或参与历史重建(§5.7)。 */
|
|
27
43
|
function assertLlmMemoShape(m, name) {
|
|
28
44
|
const o = m;
|
|
@@ -75,6 +91,7 @@ export function createAgent(opts) {
|
|
|
75
91
|
const toolStepId = `agent/${agent.name}/tool`;
|
|
76
92
|
const messages = [{ role: "user", content: input }];
|
|
77
93
|
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
94
|
+
const toolCalls = [];
|
|
78
95
|
for (let i = 0;; i++) {
|
|
79
96
|
if (i >= maxIterations) {
|
|
80
97
|
throw new Error(`agent "${agent.name}": maxIterations (${maxIterations}) exceeded`);
|
|
@@ -105,7 +122,7 @@ export function createAgent(opts) {
|
|
|
105
122
|
usage.outputTokens += llmMemo.usage.outputTokens ?? 0;
|
|
106
123
|
messages.push(...llmMemo.responseMessages);
|
|
107
124
|
if (llmMemo.toolCalls.length === 0) {
|
|
108
|
-
return { text: llmMemo.text, iterations: i + 1, usage };
|
|
125
|
+
return { text: llmMemo.text, iterations: i + 1, usage, toolCalls, output: messages };
|
|
109
126
|
}
|
|
110
127
|
// 并行 tool call 顺序执行(数组序),每个一个 durable step(§5.3)
|
|
111
128
|
for (const call of llmMemo.toolCalls) {
|
|
@@ -119,6 +136,8 @@ export function createAgent(opts) {
|
|
|
119
136
|
? redact(out, { kind: "tool", iteration: i, toolName: call.toolName })
|
|
120
137
|
: out;
|
|
121
138
|
});
|
|
139
|
+
// memo 命中时 step.run 直接返回缓存值,重放路径同样补全记录
|
|
140
|
+
toolCalls.push({ toolCallId: call.toolCallId, toolName: call.toolName, input: call.input, output });
|
|
122
141
|
const toolMsg = {
|
|
123
142
|
role: "tool",
|
|
124
143
|
content: [
|
package/dist/serve.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Client } from "./client.js";
|
|
2
2
|
import type { TriggerFunction } from "./function.js";
|
|
3
|
-
export declare const sdkVersion = "triggerlink-ts/0.4.
|
|
3
|
+
export declare const sdkVersion = "triggerlink-ts/0.4.4";
|
|
4
4
|
export declare const SIGNATURE_HEADER = "x-triggerlink-signature";
|
|
5
5
|
export interface ServeOptions {
|
|
6
6
|
client: Client;
|
package/dist/serve.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExecCtx, StepInterrupt } from "./execx.js";
|
|
2
2
|
import { createStepTool, errMessage } from "./step.js";
|
|
3
3
|
import { verifySignature } from "./sign.js";
|
|
4
|
-
export const sdkVersion = "triggerlink-ts/0.4.
|
|
4
|
+
export const sdkVersion = "triggerlink-ts/0.4.4";
|
|
5
5
|
export const SIGNATURE_HEADER = "x-triggerlink-signature";
|
|
6
6
|
const MAX_BODY = 10 << 20; // 10 MB,与平台一致
|
|
7
7
|
function json(data, status = 200) {
|