@economic/agents 2.9.1 → 2.10.0

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
@@ -4,8 +4,6 @@ Our agents SDK for building AI agents on Cloudflare Workers. Each agent is a Dur
4
4
 
5
5
  React client: [`@economic/agents-react`](../react/README.md).
6
6
 
7
- > The v1 (`@economic/agents/v1`) API (`ChatAgentHarness`, `buildLLMParams`) is deprecated and will be removed in v3.
8
-
9
7
  ## The three classes
10
8
 
11
9
  - **`Agent`** — the core. Runs the agent loop and keeps message history. Drive it over a WebSocket or programmatically (schedule, alarm, RPC). Most agents stop here.
@@ -562,11 +560,15 @@ When configured:
562
560
 
563
561
  ## Observability
564
562
 
565
- Emitted per turn from the `ai` SDK's OpenTelemetry spans, no setup beyond bindings:
563
+ AI telemetry is emitted per turn from the `ai` SDK's OpenTelemetry spans:
566
564
 
567
565
  - **Audit logs** → one JSON object per turn in `AGENTS_AUDIT_LOGS` (model, actor, IP, prompt, response, tool calls).
568
566
  - **Analytics** → per-turn and per-tool data points in `AGENTS_ANALYTICS`.
569
567
 
568
+ Separately, the SDK writes structured operational logs for completed/failed LLM and tool calls, turn duration, framework failures, and selected recovery warnings. Prompt, response, tool argument, and tool result content is excluded. These records use the stable fields `source`, `event`, `level`, `timestamp`, `agentName`, `agentClass`, `durableObjectName`, and `attributes`, while preserving Cloudflare's diagnostic events.
569
+
570
+ To send Worker logs through an existing Logpush job, enable `"logpush": true` in the Worker configuration; this does not create the Logpush job. Worker CPU, memory, and resource-limit metrics come from Cloudflare's platform telemetry rather than these SDK logs.
571
+
570
572
  ## API reference
571
573
 
572
574
  Imported from `@economic/agents` unless noted.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { n as JwtAuthConfig, r as createJwtAuthConfig, t as routeAgentRequest } from "./route-agent-request-9vqbi1bt.mjs";
2
- import { Agent as Agent$1, Connection, ConnectionContext, SubAgentClass } from "agents";
1
+ import { Agent as Agent$1, AgentOptions, Connection, ConnectionContext, SubAgentClass } from "agents";
3
2
  import { ChatResponseResult, PrepareStepContext, Session, Think, ToolCallContext, ToolCallDecision, TurnConfig, TurnContext, skills } from "@cloudflare/think";
4
3
  import { JSONValue, LanguageModel, ModelMessage, Tool as Tool$1, UIMessage } from "ai";
4
+ import { Observability } from "agents/observability";
5
5
  import { createCompactFunction } from "agents/experimental/memory/utils";
6
6
  import { SkillSource as SkillSource$1 } from "agents/skills";
7
7
 
@@ -22,9 +22,27 @@ interface AgentEnv {
22
22
  SKILLS_BUCKET: R2Bucket;
23
23
  LOCAL_AGENT_DB?: D1Database;
24
24
  }
25
- type AgentConnectionStatus = "connecting" | "connected" | "disconnected" | "unauthorized" | "error";
25
+ type AgentConnectionStatus = "connecting" | "reconnecting" | "connected" | "disconnected" | "unauthorized" | "error";
26
26
  type AgentConnectionType = "agent" | "chat" | "assistant";
27
27
  //#endregion
28
+ //#region src/server/features/auth/index.d.ts
29
+ interface JwtAuthConfig<TClaims extends Record<string, unknown> = Record<string, unknown>> {
30
+ /** Issuers whose tokens are accepted (exact string or RegExp). */
31
+ allowedIssuers: readonly (string | RegExp)[];
32
+ /** Expected `aud` claim. */
33
+ audience: string;
34
+ /** Required OAuth scopes; token `scope` must include all (empty = no scope check). */
35
+ requiredScopes?: readonly string[];
36
+ /**
37
+ * Extract the claims you need from the verified JWT payload.
38
+ * These will be stored and made available in the agent's tool context.
39
+ */
40
+ getClaims: (payload: Record<string, unknown>) => TClaims;
41
+ /** Derive the actor ID represented by the verified claims. */
42
+ getActorId(claims: TClaims): string;
43
+ }
44
+ declare function createJwtAuthConfig<TClaims extends Record<string, unknown>>(config: JwtAuthConfig<TClaims>): JwtAuthConfig<TClaims>;
45
+ //#endregion
28
46
  //#region src/server/features/auth/tokenExchange.d.ts
29
47
  interface TokenExchangeConfig {
30
48
  /** Identity server token endpoint, e.g. `${identityOrigin}/connect/token`. */
@@ -275,6 +293,7 @@ declare abstract class Agent<RequestContext extends Record<string, unknown> = Re
275
293
  * Best-effort and non-blocking — never allowed to interfere with a turn.
276
294
  */
277
295
  protected registerInstanceActivity(): Promise<void>;
296
+ observability?: Observability;
278
297
  /**
279
298
  * Resolves the analytics/telemetry agent name to the entry-point agent: the
280
299
  * top-level DO registered in the `agent` catalog table.
@@ -303,11 +322,11 @@ declare abstract class ChatAgent<RequestContext extends Record<string, unknown>
303
322
  onStart(): Promise<void>;
304
323
  configureSession(session: Session): Session;
305
324
  beforeTurn(ctx: TurnContext): Promise<void | TurnConfig>;
306
- onChatResponse(_result: ChatResponseResult): Promise<void>;
325
+ onChatResponse(result: ChatResponseResult): Promise<void>;
307
326
  /**
308
327
  * Submit feedback for a message by its id.
309
328
  * @param messageId - The id of the message to give feedback on.
310
- * @param rating - The rating to give the message. 1 = thumbs up, -1 = thumbs down.
329
+ * @param rating - The rating to give the message. 1 = thumbs up, -1 = thumbs down, 0 = clear.
311
330
  * @returns The message id and the rating.
312
331
  */
313
332
  submitMessageFeedback(messageId: string, rating: number, comment?: string): Promise<void>;
@@ -364,6 +383,7 @@ declare abstract class Assistant<State = unknown> extends Agent$1<Cloudflare.Env
364
383
  * Best-effort and non-blocking.
365
384
  */
366
385
  private touchInstance;
386
+ observability?: Observability;
367
387
  }
368
388
  //#endregion
369
389
  //#region src/server/util/skills.d.ts
@@ -380,6 +400,9 @@ interface SkillSource<Context extends Record<string, unknown> = Record<string, u
380
400
  }
381
401
  declare function skill<Context extends Record<string, unknown> = Record<string, unknown>>(definition: Skill<Context>): SkillSource<Context>;
382
402
  //#endregion
403
+ //#region src/server/route-agent-request.d.ts
404
+ declare function routeAgentRequest<Env>(request: Request, env: Env, options?: AgentOptions<Env>): Promise<Response | null>;
405
+ //#endregion
383
406
  //#region src/server/index.d.ts
384
407
  declare function getCurrentToolContext(): any;
385
408
  //#endregion