@triggerlink/sdk 0.4.3 → 0.4.5

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 CHANGED
@@ -126,6 +126,10 @@ Notes:
126
126
  (`{ toolCallId, toolName, input, output }`, in order; rebuilt from memos on recovery).
127
127
  This covers the "done tool writes to shared state" pattern from agent frameworks like
128
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.
129
133
  - **`redact` hook** (optional): transforms each step's output inside `step.run` before
130
134
  persistence, e.g. to strip secrets or PII from memos. It must be deterministic and
131
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,6 +1,11 @@
1
- import { type LanguageModel } from "ai";
1
+ import { type AssistantModelMessage, type LanguageModel, type ToolModelMessage, type UserModelMessage } from "ai";
2
2
  import type { ZodType } from "zod";
3
3
  import type { StepTool } from "./step.js";
4
+ /**
5
+ * 对话消息:user / assistant / tool 三种(不含 system——system prompt 走
6
+ * AgentOpts.system 参数,不进消息列表)。AgentResult.output 的元素类型。
7
+ */
8
+ export type TextMessage = UserModelMessage | AssistantModelMessage | ToolModelMessage;
4
9
  export { anthropic, createAnthropic } from "@ai-sdk/anthropic";
5
10
  export { openai, createOpenAI } from "@ai-sdk/openai";
6
11
  export { deepseek, createDeepSeek } from "@ai-sdk/deepseek";
@@ -58,7 +63,15 @@ export interface AgentResult {
58
63
  * 工具产出,无需解析最终文本。恢复重放时 memo 命中路径同样重建该列表。
59
64
  */
60
65
  toolCalls: AgentToolCallRecord[];
66
+ /**
67
+ * 完整对话历史(user 输入 + 各轮 assistant 消息 + 工具结果),字段名与 AgentKit
68
+ * 的 result.output 对齐——可自行 findLastIndex 等遍历(元素含 role/content)。
69
+ * 恢复重放时由 memo 原样重建;启用 redact 时历史内容即脱敏后内容。
70
+ */
71
+ output: TextMessage[];
61
72
  }
73
+ /** 取最后一条 assistant 消息的文本内容(拼接所有 text part);没有则返回 undefined。 */
74
+ export declare function lastAssistantTextMessageContent(result: AgentResult): string | undefined;
62
75
  /** 一次工具执行的记录。 */
63
76
  export interface AgentToolCallRecord {
64
77
  toolCallId: 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;
@@ -106,7 +122,7 @@ export function createAgent(opts) {
106
122
  usage.outputTokens += llmMemo.usage.outputTokens ?? 0;
107
123
  messages.push(...llmMemo.responseMessages);
108
124
  if (llmMemo.toolCalls.length === 0) {
109
- return { text: llmMemo.text, iterations: i + 1, usage, toolCalls };
125
+ return { text: llmMemo.text, iterations: i + 1, usage, toolCalls, output: messages };
110
126
  }
111
127
  // 并行 tool call 顺序执行(数组序),每个一个 durable step(§5.3)
112
128
  for (const call of llmMemo.toolCalls) {
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";
3
+ export declare const sdkVersion = "triggerlink-ts/0.4.5";
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.3";
4
+ export const sdkVersion = "triggerlink-ts/0.4.5";
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triggerlink/sdk",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "TriggerLink TypeScript SDK: durable, crash-recoverable functions for Next.js / Node.js",
5
5
  "keywords": [
6
6
  "triggerlink",