@economic/agents 2.3.16 → 2.3.18

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/dist/index.d.mts CHANGED
@@ -23,7 +23,7 @@ interface AgentEnv {
23
23
  LOCAL_AGENT_DB?: D1Database;
24
24
  }
25
25
  type SqlFn = InstanceType<typeof Agent$1>["sql"];
26
- type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized";
26
+ type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized" | "error";
27
27
  type AgentConnectionType = "agent" | "chat" | "assistant";
28
28
  //#endregion
29
29
  //#region src/server/util/tools.d.ts
package/dist/index.mjs CHANGED
@@ -56,6 +56,41 @@ function sendSubAgentName(connection, subAgentName) {
56
56
  }));
57
57
  }
58
58
  //#endregion
59
+ //#region src/server/util/llm.ts
60
+ /**
61
+ * Convention: tools can include a `sources` array in their return value to surface
62
+ * source URLs in the message stream. This transform detects it automatically.
63
+ *
64
+ * ```typescript
65
+ * // In any tool's execute function:
66
+ * return { myContent: "...", sources: [{ url: "https://...", title: "Page title" }] };
67
+ * ```
68
+ */
69
+ function buildSourcesTransform(additional) {
70
+ const sourcesTransform = () => new TransformStream({ transform(chunk, controller) {
71
+ controller.enqueue(chunk);
72
+ if (chunk.type !== "tool-result") return;
73
+ const output = chunk.output;
74
+ if (!output || typeof output !== "object" || Array.isArray(output)) return;
75
+ const sources = output.sources;
76
+ if (!Array.isArray(sources)) return;
77
+ for (const source of sources) {
78
+ if (!source || typeof source !== "object") continue;
79
+ const s = source;
80
+ if (typeof s.url !== "string") continue;
81
+ controller.enqueue({
82
+ type: "source",
83
+ sourceType: "url",
84
+ id: crypto.randomUUID(),
85
+ url: s.url,
86
+ ...typeof s.title === "string" ? { title: s.title } : {}
87
+ });
88
+ }
89
+ } });
90
+ if (!additional) return sourcesTransform;
91
+ return [sourcesTransform, ...Array.isArray(additional) ? additional : [additional]];
92
+ }
93
+ //#endregion
59
94
  //#region src/server/agents/Agent.ts
60
95
  var Agent = class extends Think {
61
96
  agentType = "agent";
@@ -116,11 +151,7 @@ var Agent = class extends Think {
116
151
  return;
117
152
  }
118
153
  const token = extractTokenFromConnectRequest(ctx.request);
119
- if (token && this.getUserContext) {
120
- this.userContext = await this.getUserContext(token);
121
- this._toolContextForCurrentTurn = this.getToolContextForCurrentTurn();
122
- await this.session.refreshSystemPrompt();
123
- }
154
+ if (token && this.getUserContext) this.userContext = await this.getUserContext(token);
124
155
  }
125
156
  }
126
157
  sendConnectionStatus(connection, "connected");
@@ -160,6 +191,7 @@ var Agent = class extends Think {
160
191
  }),
161
192
  tools,
162
193
  activeTools,
194
+ experimental_transform: buildSourcesTransform(),
163
195
  experimental_telemetry: {
164
196
  isEnabled: true,
165
197
  tracer: createAgentTracer(this.env.AGENTS_AUDIT_LOGS, this.env.AGENTS_ANALYTICS, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents",
3
- "version": "2.3.16",
3
+ "version": "2.3.18",
4
4
  "description": "A starter for creating a TypeScript package.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -25,10 +25,10 @@
25
25
  "dependencies": {
26
26
  "@ai-sdk/anthropic": "^3.0.77",
27
27
  "@ai-sdk/google": "^3.0.73",
28
- "@cloudflare/ai-chat": "^0.8.3",
29
- "@cloudflare/think": ">=0.8.4",
30
- "@opentelemetry/sdk-trace-base": "^2.7.1",
31
- "agents": ">=0.14.3 <1.0.0",
28
+ "@cloudflare/ai-chat": "^0.8.5",
29
+ "@cloudflare/think": "^0.9.0",
30
+ "@opentelemetry/sdk-trace-base": "^2.8.0",
31
+ "agents": "^0.16.0",
32
32
  "ai": "^6.0.197",
33
33
  "jose": "^6.2.3",
34
34
  "nanoid": "^5.1.11"
@@ -36,7 +36,7 @@
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.29.7",
38
38
  "@babel/plugin-proposal-decorators": "^7.29.7",
39
- "@cloudflare/workers-types": "^4.20260527.1",
39
+ "@cloudflare/workers-types": "^4.20260616.1",
40
40
  "@rolldown/plugin-babel": "^0.2.3",
41
41
  "@types/node": "^25.6.0",
42
42
  "@typescript/native-preview": "7.0.0-dev.20260412.1",
@@ -45,10 +45,10 @@
45
45
  "vitest": "^4.1.4"
46
46
  },
47
47
  "peerDependencies": {
48
- "@cloudflare/think": ">=0.8.4",
49
- "@cloudflare/vite-plugin": ">=1.40.0",
50
- "@cloudflare/worker-bundler": ">=0.2.0",
51
- "agents": ">=0.14.3 <1.0.0",
48
+ "@cloudflare/think": ">=0.9.0",
49
+ "@cloudflare/vite-plugin": ">=1.40.2",
50
+ "@cloudflare/worker-bundler": ">=0.2.1",
51
+ "agents": ">=0.16.0 <1.0.0",
52
52
  "vite": ">=8.0.0"
53
53
  }
54
54
  }