@economic/agents 2.3.23 → 2.3.25

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
@@ -49,6 +49,7 @@ declare abstract class Agent<RequestContext extends Record<string, unknown> = Re
49
49
  configureSession(session: Session): Session;
50
50
  onConnect(connection: Connection, ctx: ConnectionContext): Promise<void>;
51
51
  private _toolsForCurrentTurn;
52
+ private _authorizedToolsForCurrentTurn;
52
53
  private _toolContextForCurrentTurn?;
53
54
  private getToolContextForCurrentTurn;
54
55
  /**
@@ -128,7 +129,7 @@ declare abstract class Agent<RequestContext extends Record<string, unknown> = Re
128
129
  * `updated_at`, so instances can be ordered by recency of activity.
129
130
  * Best-effort and non-blocking — never allowed to interfere with a turn.
130
131
  */
131
- protected touchInstance(): Promise<void>;
132
+ protected registerInstanceActivity(): Promise<void>;
132
133
  /**
133
134
  * Resolves the analytics/telemetry agent name to the entry-point agent: the
134
135
  * top-level DO registered in the `agent` catalog table.
package/dist/index.mjs CHANGED
@@ -170,17 +170,19 @@ var Agent = class extends Think {
170
170
  return;
171
171
  }
172
172
  const token = extractTokenFromConnectRequest(ctx.request);
173
- if (token && this.getUserContext) this.userContext = await this.getUserContext(token);
173
+ if (token && this.getUserContext) connection.setState({ userContext: await this.getUserContext(token) });
174
174
  }
175
175
  }
176
176
  sendConnectionStatus(connection, "connected");
177
177
  }
178
178
  _toolsForCurrentTurn = {};
179
+ _authorizedToolsForCurrentTurn = {};
179
180
  _toolContextForCurrentTurn;
180
181
  getToolContextForCurrentTurn(requestContext = {}) {
182
+ const connectionState = getCurrentAgent().connection?.state;
181
183
  return {
182
184
  ...requestContext,
183
- _userContext: this.userContext
185
+ _userContext: connectionState?.userContext
184
186
  };
185
187
  }
186
188
  /**
@@ -191,7 +193,7 @@ var Agent = class extends Think {
191
193
  * `returned.tools` into your own `TurnConfig.tools` if you return tools.
192
194
  */
193
195
  async beforeTurn(ctx) {
194
- this.touchInstance();
196
+ this.registerInstanceActivity();
195
197
  this._toolContextForCurrentTurn = this.getToolContextForCurrentTurn(ctx.body);
196
198
  this._toolsForCurrentTurn = ctx.tools;
197
199
  const activeSkillName = this._getLastActivatedSkillName(ctx.messages);
@@ -246,12 +248,18 @@ var Agent = class extends Think {
246
248
  };
247
249
  }
248
250
  async beforeToolCall(ctx) {
251
+ const toolCtx = this._toolContextForCurrentTurn ?? {};
249
252
  if (ctx.toolName === "activate_skill") {
250
- if ((await this.getSkills()).find((source) => source.id === ctx.input["name"])?.authorize?.(this._toolContextForCurrentTurn ?? {}) === false) return {
253
+ if ((await this.getSkills()).find((source) => source.id === ctx.input["name"])?.authorize?.(toolCtx) === false) return {
251
254
  action: "block",
252
255
  reason: "Unauthorized skill"
253
256
  };
257
+ return;
254
258
  }
259
+ if (this._authorizedToolsForCurrentTurn[ctx.toolName]?.authorize?.(toolCtx) === false) return {
260
+ action: "block",
261
+ reason: `You do not have permission to use the "${ctx.toolName}" tool. Tell the user they don't have access to this capability, then stop -- do not try other tools to work around it.`
262
+ };
255
263
  }
256
264
  getTools() {
257
265
  return {};
@@ -270,16 +278,17 @@ var Agent = class extends Think {
270
278
  }
271
279
  async _getAuthorizedTools(availableTools, activeSkillName) {
272
280
  const tools = { ...availableTools };
273
- const activeTools = Object.keys(availableTools);
281
+ const activeTools = Object.keys(tools);
274
282
  const authorizedSkills = (await this.getSkills()).filter((skill) => !skill.authorize || skill.authorize?.(this._toolContextForCurrentTurn) !== false);
275
283
  for (const skill of authorizedSkills) {
276
284
  if (!skill.tools || Object.keys(skill.tools).length === 0) continue;
277
285
  Object.assign(tools, skill.tools);
278
286
  if (skill.id === activeSkillName) activeTools.push(...Object.keys(skill.tools));
279
287
  }
288
+ this._authorizedToolsForCurrentTurn = tools;
280
289
  return {
281
290
  tools,
282
- activeTools: activeTools.filter((toolName) => tools[toolName]?.authorize?.(this._toolContextForCurrentTurn) !== false)
291
+ activeTools
283
292
  };
284
293
  }
285
294
  _getLastActivatedSkillName(items = []) {
@@ -348,7 +357,7 @@ var Agent = class extends Think {
348
357
  * `updated_at`, so instances can be ordered by recency of activity.
349
358
  * Best-effort and non-blocking — never allowed to interfere with a turn.
350
359
  */
351
- async touchInstance() {
360
+ async registerInstanceActivity() {
352
361
  try {
353
362
  await touchAgentInstance(this.env.AGENTS_DB, {
354
363
  ...this.getRegisteredInstanceKey(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents",
3
- "version": "2.3.23",
3
+ "version": "2.3.25",
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.5",
29
- "@cloudflare/think": ">=0.9.0",
28
+ "@cloudflare/ai-chat": "^0.9.3",
29
+ "@cloudflare/think": "^0.12.1",
30
30
  "@opentelemetry/sdk-trace-base": "^2.8.0",
31
- "agents": ">=0.16.0 <1.0.0",
31
+ "agents": "^0.17.3",
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.20260616.1",
39
+ "@cloudflare/workers-types": "^4.20260701.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.9.0",
49
- "@cloudflare/vite-plugin": "^1.42.0",
50
- "@cloudflare/worker-bundler": ">=0.2.1",
51
- "agents": ">=0.16.0 <1.0.0",
48
+ "@cloudflare/think": "^0.12.1",
49
+ "@cloudflare/vite-plugin": "^1.42.4",
50
+ "@cloudflare/worker-bundler": "^0.2.1",
51
+ "agents": "^0.17.3",
52
52
  "vite": ">=8.0.0"
53
53
  }
54
54
  }