@triggerlink/sdk 0.4.0 → 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 +19 -11
- package/dist/agent.d.ts +9 -1
- package/dist/agent.js +20 -0
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -73,26 +73,33 @@ Built on the [Vercel AI SDK](https://github.com/vercel/ai) for multi-provider
|
|
|
73
73
|
support; design details in [`docs/agent-design.md`](../docs/agent-design.md).
|
|
74
74
|
|
|
75
75
|
```bash
|
|
76
|
-
npm install @triggerlink/sdk
|
|
76
|
+
npm install @triggerlink/sdk zod # zod is for tool schemas; ai + providers are bundled
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
```ts
|
|
80
80
|
import { createFunction } from "@triggerlink/sdk";
|
|
81
|
-
import { createAgent } from "@triggerlink/sdk/agent"; // subpath import, not the main entry
|
|
82
|
-
import { anthropic } from "@ai-sdk/anthropic";
|
|
81
|
+
import { createAgent, createTool, anthropic } from "@triggerlink/sdk/agent"; // subpath import, not the main entry
|
|
83
82
|
import { z } from "zod";
|
|
84
83
|
|
|
84
|
+
// Built-in providers, zero extra installs: anthropic / openai / deepseek
|
|
85
|
+
// (plus createAnthropic / createOpenAI / createDeepSeek for custom baseURL/apiKey).
|
|
86
|
+
// Default instances read ANTHROPIC_API_KEY / OPENAI_API_KEY / DEEPSEEK_API_KEY from the env.
|
|
87
|
+
// Any other AI SDK LanguageModel can still be passed as `model` directly.
|
|
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
|
+
|
|
85
98
|
const researcher = createAgent({
|
|
86
99
|
name: "researcher", // stable ID, used in memo keys — do not rename casually
|
|
87
100
|
model: anthropic("claude-sonnet-4-5"), // any AI SDK LanguageModel
|
|
88
101
|
system: "You are a research assistant. Answer concisely.",
|
|
89
|
-
tools: {
|
|
90
|
-
search: {
|
|
91
|
-
description: "Search the knowledge base",
|
|
92
|
-
parameters: z.object({ query: z.string() }),
|
|
93
|
-
handler: async ({ query }) => kb.search(query),
|
|
94
|
-
},
|
|
95
|
-
},
|
|
102
|
+
tools: { search: searchKb },
|
|
96
103
|
maxIterations: 10, // safety cap; the run fails when exceeded
|
|
97
104
|
});
|
|
98
105
|
|
|
@@ -123,7 +130,8 @@ Notes:
|
|
|
123
130
|
callback timeout (5 minutes by default); two different agents in one function must have
|
|
124
131
|
different `name`s; changing the tool set or loop structure between retries of the same run
|
|
125
132
|
can misalign memo keys (changing prompt text is safe).
|
|
126
|
-
-
|
|
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.
|
|
127
135
|
|
|
128
136
|
## Sending events (any TS code, modeled after Inngest's `inngest.send`)
|
|
129
137
|
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { type LanguageModel } from "ai";
|
|
2
2
|
import type { ZodType } from "zod";
|
|
3
3
|
import type { StepTool } from "./step.js";
|
|
4
|
+
export { anthropic, createAnthropic } from "@ai-sdk/anthropic";
|
|
5
|
+
export { openai, createOpenAI } from "@ai-sdk/openai";
|
|
6
|
+
export { deepseek, createDeepSeek } from "@ai-sdk/deepseek";
|
|
4
7
|
/** Agent 工具定义。parameters 为 zod schema;handler 入参是 schema parse 后的值。 */
|
|
5
8
|
export interface AgentTool<P = unknown, R = unknown> {
|
|
6
9
|
description: string;
|
|
7
10
|
parameters: ZodType<P>;
|
|
8
11
|
handler: (params: P) => Promise<R> | R;
|
|
9
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* 定义一个 Agent 工具(泛型工厂):让 zod schema 的类型流到 handler 入参。
|
|
15
|
+
* 与直接写字面量等价,但获得完整的类型推断;跨 Agent 复用工具时也应使用它。
|
|
16
|
+
*/
|
|
17
|
+
export declare function createTool<P, R>(def: AgentTool<P, R>): AgentTool<P, R>;
|
|
10
18
|
/** redact 钩子的上下文(§5.7)。 */
|
|
11
19
|
export interface RedactCtx {
|
|
12
20
|
/** 产生输出的 step 类型 */
|
|
@@ -29,7 +37,7 @@ export interface AgentOpts {
|
|
|
29
37
|
/** AI SDK 的 LanguageModel(用户自带 provider 包,如 @ai-sdk/anthropic) */
|
|
30
38
|
model: LanguageModel;
|
|
31
39
|
system?: string;
|
|
32
|
-
tools?: Record<string, AgentTool
|
|
40
|
+
tools?: Record<string, AgentTool<any, any>>;
|
|
33
41
|
/** 迭代上限(一次迭代 = 一次 LLM 调用 + 其全部工具执行),默认 10;超限抛错使 run 失败 */
|
|
34
42
|
maxIterations?: number;
|
|
35
43
|
redact?: RedactHook;
|
package/dist/agent.js
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
// 本模块只通过子路径 @triggerlink/sdk/agent 导出——ai/zod 是 optional peer 依赖,
|
|
4
4
|
// 主入口 index.ts 不得 import 本模块(§8.1),否则未装 ai 的普通用户会在 import 时崩溃。
|
|
5
5
|
import { generateText, tool, } from "ai";
|
|
6
|
+
// 内置 provider,开箱即用:默认实例从环境变量读 API key
|
|
7
|
+
// (ANTHROPIC_API_KEY / OPENAI_API_KEY / DEEPSEEK_API_KEY);
|
|
8
|
+
// 需要自定义 baseURL/apiKey/代理时用 createXxx 构造专属实例。
|
|
9
|
+
// 其余 provider 不受影响:createAgent 的 model 接受任意 AI SDK LanguageModel。
|
|
10
|
+
export { anthropic, createAnthropic } from "@ai-sdk/anthropic";
|
|
11
|
+
export { openai, createOpenAI } from "@ai-sdk/openai";
|
|
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
|
+
}
|
|
6
26
|
/** redact 钩子可能破坏 llm memo 结构;此处 fail loud,不让坏 memo 落库或参与历史重建(§5.7)。 */
|
|
7
27
|
function assertLlmMemoShape(m, name) {
|
|
8
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.
|
|
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.
|
|
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.
|
|
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",
|
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
"prepublishOnly": "npm run build"
|
|
37
37
|
},
|
|
38
38
|
"license": "MIT",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"registry": "https://registry.npmjs.org"
|
|
41
|
+
},
|
|
39
42
|
"repository": {
|
|
40
43
|
"type": "git",
|
|
41
44
|
"url": "git+https://github.com/bearalise/triggerlink.git",
|
|
@@ -43,20 +46,21 @@
|
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@types/node": "^22.0.0",
|
|
46
|
-
"ai": "^7.0.66",
|
|
47
49
|
"typescript": "^5.5.0",
|
|
48
50
|
"zod": "^4.4.3"
|
|
49
51
|
},
|
|
50
52
|
"peerDependencies": {
|
|
51
|
-
"ai": "^7.0.0",
|
|
52
53
|
"zod": "^3.25.76 || ^4.1.8"
|
|
53
54
|
},
|
|
54
55
|
"peerDependenciesMeta": {
|
|
55
|
-
"ai": {
|
|
56
|
-
"optional": true
|
|
57
|
-
},
|
|
58
56
|
"zod": {
|
|
59
57
|
"optional": true
|
|
60
58
|
}
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@ai-sdk/anthropic": "^4.0.39",
|
|
62
|
+
"@ai-sdk/deepseek": "^3.0.28",
|
|
63
|
+
"@ai-sdk/openai": "^4.0.42",
|
|
64
|
+
"ai": "^7.0.66"
|
|
61
65
|
}
|
|
62
66
|
}
|