@triggerlink/sdk 0.4.1 → 0.4.2

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
@@ -78,7 +78,7 @@ npm install @triggerlink/sdk zod # zod is for tool schemas; ai + providers are
78
78
 
79
79
  ```ts
80
80
  import { createFunction } from "@triggerlink/sdk";
81
- import { createAgent, anthropic } from "@triggerlink/sdk/agent"; // subpath import, not the main entry
81
+ import { createAgent, createTool, anthropic } from "@triggerlink/sdk/agent"; // subpath import, not the main entry
82
82
  import { z } from "zod";
83
83
 
84
84
  // Built-in providers, zero extra installs: anthropic / openai / deepseek
@@ -86,17 +86,20 @@ import { z } from "zod";
86
86
  // Default instances read ANTHROPIC_API_KEY / OPENAI_API_KEY / DEEPSEEK_API_KEY from the env.
87
87
  // Any other AI SDK LanguageModel can still be passed as `model` directly.
88
88
 
89
+ // createTool is a generic factory: the zod schema's type flows into the handler's
90
+ // params — annotate nothing. Plain object literals also work; use createTool when
91
+ // sharing a tool across agents.
92
+ const searchKb = createTool({
93
+ description: "Search the knowledge base",
94
+ parameters: z.object({ query: z.string() }),
95
+ handler: async ({ query }) => kb.search(query), // query: string, inferred
96
+ });
97
+
89
98
  const researcher = createAgent({
90
99
  name: "researcher", // stable ID, used in memo keys — do not rename casually
91
100
  model: anthropic("claude-sonnet-4-5"), // any AI SDK LanguageModel
92
101
  system: "You are a research assistant. Answer concisely.",
93
- tools: {
94
- search: {
95
- description: "Search the knowledge base",
96
- parameters: z.object({ query: z.string() }),
97
- handler: async ({ query }) => kb.search(query),
98
- },
99
- },
102
+ tools: { search: searchKb },
100
103
  maxIterations: 10, // safety cap; the run fails when exceeded
101
104
  });
102
105
 
@@ -128,6 +131,7 @@ Notes:
128
131
  different `name`s; changing the tool set or loop structure between retries of the same run
129
132
  can misalign memo keys (changing prompt text is safe).
130
133
  - `ai` and the three built-in providers are regular dependencies of the SDK (bundled, no extra install); `zod` is an optional peer dependency — install it if you define tool schemas.
134
+ - **HTTP proxies**: if your environment routes external traffic through `http_proxy`/`https_proxy`, note that Node's global `fetch` ignores them by default — LLM calls will fail with `AI_APICallError: Cannot connect to API`. On Node 24+, start your app with `node --use-env-proxy`; on older Node, install `undici` and set `setGlobalDispatcher(new EnvHttpProxyAgent())` before serving.
131
135
 
132
136
  ## Sending events (any TS code, modeled after Inngest's `inngest.send`)
133
137
 
package/dist/agent.d.ts CHANGED
@@ -10,6 +10,11 @@ export interface AgentTool<P = unknown, R = unknown> {
10
10
  parameters: ZodType<P>;
11
11
  handler: (params: P) => Promise<R> | R;
12
12
  }
13
+ /**
14
+ * 定义一个 Agent 工具(泛型工厂):让 zod schema 的类型流到 handler 入参。
15
+ * 与直接写字面量等价,但获得完整的类型推断;跨 Agent 复用工具时也应使用它。
16
+ */
17
+ export declare function createTool<P, R>(def: AgentTool<P, R>): AgentTool<P, R>;
13
18
  /** redact 钩子的上下文(§5.7)。 */
14
19
  export interface RedactCtx {
15
20
  /** 产生输出的 step 类型 */
@@ -32,7 +37,7 @@ export interface AgentOpts {
32
37
  /** AI SDK 的 LanguageModel(用户自带 provider 包,如 @ai-sdk/anthropic) */
33
38
  model: LanguageModel;
34
39
  system?: string;
35
- tools?: Record<string, AgentTool>;
40
+ tools?: Record<string, AgentTool<any, any>>;
36
41
  /** 迭代上限(一次迭代 = 一次 LLM 调用 + 其全部工具执行),默认 10;超限抛错使 run 失败 */
37
42
  maxIterations?: number;
38
43
  redact?: RedactHook;
package/dist/agent.js CHANGED
@@ -10,6 +10,19 @@ import { generateText, tool, } from "ai";
10
10
  export { anthropic, createAnthropic } from "@ai-sdk/anthropic";
11
11
  export { openai, createOpenAI } from "@ai-sdk/openai";
12
12
  export { deepseek, createDeepSeek } from "@ai-sdk/deepseek";
13
+ /**
14
+ * 定义一个 Agent 工具(泛型工厂):让 zod schema 的类型流到 handler 入参。
15
+ * 与直接写字面量等价,但获得完整的类型推断;跨 Agent 复用工具时也应使用它。
16
+ */
17
+ export function createTool(def) {
18
+ if (!def.description)
19
+ throw new Error("createTool: description is required");
20
+ if (!def.parameters)
21
+ throw new Error("createTool: parameters is required");
22
+ if (typeof def.handler !== "function")
23
+ throw new Error("createTool: handler is required");
24
+ return def;
25
+ }
13
26
  /** redact 钩子可能破坏 llm memo 结构;此处 fail loud,不让坏 memo 落库或参与历史重建(§5.7)。 */
14
27
  function assertLlmMemoShape(m, name) {
15
28
  const o = m;
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.1";
3
+ export declare const sdkVersion = "triggerlink-ts/0.4.2";
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.1";
4
+ export const sdkVersion = "triggerlink-ts/0.4.2";
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.1",
3
+ "version": "0.4.2",
4
4
  "description": "TriggerLink TypeScript SDK: durable, crash-recoverable functions for Next.js / Node.js",
5
5
  "keywords": [
6
6
  "triggerlink",