@economic/agents 0.0.1-alpha.7 → 0.0.1-alpha.9

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
@@ -136,17 +136,15 @@ interface SkillsConfig {
136
136
  /**
137
137
  * Skill context injected by the @withSkills decorator.
138
138
  *
139
- * Spread the skill fields into streamText and pass headers via
140
- * experimental_context so tools can read them from their second execute arg:
139
+ * Spread the skill fields into streamText:
141
140
  *
142
141
  * ```typescript
143
- * const { messages, headers, guidance, ...skillArgs } = ctx;
142
+ * const { messages, guidance, ...skillArgs } = ctx;
144
143
  * return streamText({
145
144
  * model: this.getModel(),
146
145
  * system: "Your base prompt — static, never includes guidance",
147
146
  * messages,
148
147
  * ...skillArgs,
149
- * experimental_context: { headers },
150
148
  * onFinish,
151
149
  * stopWhen: stepCountIs(20),
152
150
  * }).toUIMessageStreamResponse();
@@ -171,12 +169,6 @@ interface SkillContext {
171
169
  * Pass directly as the `messages` param of streamText.
172
170
  */
173
171
  messages: ai.ModelMessage[];
174
- /**
175
- * Headers captured from the WebSocket upgrade request, filtered to the
176
- * names returned by getTrackedHeaders(). Pass to tools via
177
- * experimental_context: `streamText({ experimental_context: { headers }, ... })`
178
- */
179
- headers: Record<string, string>;
180
172
  }
181
173
  /**
182
174
  * The object returned by createSkills().
@@ -251,21 +243,6 @@ declare abstract class AIChatAgentBase<Env extends Cloudflare.Env = Cloudflare.E
251
243
  * tail is maxPersistedMessages - 1 recent messages. Raise or lower per agent.
252
244
  */
253
245
  maxPersistedMessages: number;
254
- /**
255
- * Query parameter names to read from the WebSocket connection URL and
256
- * forward to tools via experimental_context.
257
- *
258
- * Browsers cannot set custom headers on WebSocket upgrade requests, so
259
- * auth tokens and other metadata must be passed as query parameters instead.
260
- *
261
- * ```typescript
262
- * passthroughRequestHeaders = ['authorization', 'x-user-id'];
263
- * ```
264
- *
265
- * Values are read from the URL at connect time and stored in _requestHeaders
266
- * for the lifetime of the Durable Object instance.
267
- */
268
- passthroughRequestHeaders: string[];
269
246
  /** Tools that are always active regardless of loaded skills */
270
247
  abstract getTools(): ToolSet;
271
248
  /** All skills available for on-demand loading */
@@ -298,8 +275,6 @@ declare abstract class AIChatAgentBase<Env extends Cloudflare.Env = Cloudflare.E
298
275
  * skill when activate_skill is called. Defaults to allow-all.
299
276
  */
300
277
  protected filterSkill(_skillName: string): Promise<boolean>;
301
- /** @internal Captured header values, keyed by lowercase name. */
302
- protected _requestHeaders: Record<string, string>;
303
278
  /**
304
279
  * Buffered skill state from the current turn.
305
280
  *
@@ -440,23 +415,6 @@ declare function withSkills(fn: WithSkillsFn, _context: ClassMethodDecoratorCont
440
415
  * }
441
416
  * ```
442
417
  *
443
- * ## Passing auth headers to tools
444
- *
445
- * Set `passthroughRequestHeaders` to capture headers from the WebSocket upgrade
446
- * request. They are forwarded automatically to every tool via `experimental_context`:
447
- *
448
- * ```typescript
449
- * passthroughRequestHeaders = ['authorization', 'x-user-id'];
450
- * ```
451
- *
452
- * Tools receive them as the second `execute` argument:
453
- *
454
- * ```typescript
455
- * execute: async (args, { experimental_context }) => {
456
- * const { authorization } = experimental_context?.headers ?? {};
457
- * }
458
- * ```
459
- *
460
418
  * If you need full control over the `streamText` call (custom model options,
461
419
  * streaming transforms, varying the model per request, etc.) use
462
420
  * `AIChatAgentBase` with the `@withSkills` decorator instead.
@@ -487,24 +445,6 @@ declare abstract class AIChatAgent<Env extends Cloudflare.Env = Cloudflare.Env>
487
445
  onChatMessage(onFinish: StreamTextOnFinishCallback<ToolSet>, options?: OnChatMessageOptions): Promise<Response | undefined>;
488
446
  }
489
447
  //#endregion
490
- //#region src/agents/chat/types.d.ts
491
- /**
492
- * The shape of experimental_context passed to tool execute functions.
493
- *
494
- * Cast experimental_context to this type to access forwarded request headers:
495
- *
496
- * ```typescript
497
- * import type { AgentToolContext } from '@economic/agents';
498
- *
499
- * execute: async (args, { experimental_context }) => {
500
- * const { authorization } = experimental_context as AgentToolContext;
501
- * }
502
- * ```
503
- */
504
- interface AgentToolContext {
505
- headers: Record<string, string>;
506
- }
507
- //#endregion
508
448
  //#region src/features/skills/index.d.ts
509
449
  /**
510
450
  * Creates a skill loading system for use with the Vercel AI SDK.
@@ -624,4 +564,4 @@ declare function compactMessages(messages: UIMessage[], model: LanguageModel, ta
624
564
  */
625
565
  declare function compactIfNeeded(messages: UIMessage[], model: LanguageModel | undefined, tailSize: number): Promise<UIMessage[]>;
626
566
  //#endregion
627
- export { AIChatAgent, AIChatAgentBase, type AgentToolContext, COMPACT_TOKEN_THRESHOLD, type Skill, type SkillContext, type SkillsConfig, type SkillsResult, compactIfNeeded, compactMessages, createSkills, estimateMessagesTokens, filterEphemeralMessages, injectGuidance, withSkills };
567
+ export { AIChatAgent, AIChatAgentBase, COMPACT_TOKEN_THRESHOLD, type Skill, type SkillContext, type SkillsConfig, type SkillsResult, compactIfNeeded, compactMessages, createSkills, estimateMessagesTokens, filterEphemeralMessages, injectGuidance, withSkills };
package/dist/index.mjs CHANGED
@@ -447,21 +447,6 @@ var AIChatAgentBase = class extends AIChatAgent$1 {
447
447
  */
448
448
  maxPersistedMessages = 50;
449
449
  /**
450
- * Query parameter names to read from the WebSocket connection URL and
451
- * forward to tools via experimental_context.
452
- *
453
- * Browsers cannot set custom headers on WebSocket upgrade requests, so
454
- * auth tokens and other metadata must be passed as query parameters instead.
455
- *
456
- * ```typescript
457
- * passthroughRequestHeaders = ['authorization', 'x-user-id'];
458
- * ```
459
- *
460
- * Values are read from the URL at connect time and stored in _requestHeaders
461
- * for the lifetime of the Durable Object instance.
462
- */
463
- passthroughRequestHeaders = [];
464
- /**
465
450
  * Return a LanguageModel to use for compaction summarisation.
466
451
  *
467
452
  * Return undefined (default) to disable compaction — messages are kept up
@@ -491,8 +476,6 @@ var AIChatAgentBase = class extends AIChatAgent$1 {
491
476
  async filterSkill(_skillName) {
492
477
  return true;
493
478
  }
494
- /** @internal Captured header values, keyed by lowercase name. */
495
- _requestHeaders = {};
496
479
  /**
497
480
  * Buffered skill state from the current turn.
498
481
  *
@@ -536,14 +519,6 @@ var AIChatAgentBase = class extends AIChatAgent$1 {
536
519
  * that case and replays in-progress chunks via its own protocol.
537
520
  */
538
521
  async onConnect(connection, ctx) {
539
- if (this.passthroughRequestHeaders.length > 0) {
540
- this._requestHeaders = {};
541
- const params = new URL(ctx.request.url).searchParams;
542
- for (const name of this.passthroughRequestHeaders) {
543
- const value = params.get(name);
544
- if (value !== null) this._requestHeaders[name] = value;
545
- }
546
- }
547
522
  await super.onConnect(connection, ctx);
548
523
  if (!this._activeStreamId && this.messages.length > 0) connection.send(JSON.stringify({
549
524
  type: "cf_agent_chat_messages",
@@ -618,8 +593,7 @@ var AIChatAgentBase = class extends AIChatAgent$1 {
618
593
  activeTools: skills.activeTools,
619
594
  prepareStep: skills.prepareStep,
620
595
  guidance: skills.getLoadedGuidance(),
621
- messages: await convertToModelMessages(this.messages),
622
- headers: this._requestHeaders
596
+ messages: await convertToModelMessages(this.messages)
623
597
  };
624
598
  }
625
599
  };
@@ -655,23 +629,6 @@ function withSkills(fn, _context) {
655
629
  * }
656
630
  * ```
657
631
  *
658
- * ## Passing auth headers to tools
659
- *
660
- * Set `passthroughRequestHeaders` to capture headers from the WebSocket upgrade
661
- * request. They are forwarded automatically to every tool via `experimental_context`:
662
- *
663
- * ```typescript
664
- * passthroughRequestHeaders = ['authorization', 'x-user-id'];
665
- * ```
666
- *
667
- * Tools receive them as the second `execute` argument:
668
- *
669
- * ```typescript
670
- * execute: async (args, { experimental_context }) => {
671
- * const { authorization } = experimental_context?.headers ?? {};
672
- * }
673
- * ```
674
- *
675
632
  * If you need full control over the `streamText` call (custom model options,
676
633
  * streaming transforms, varying the model per request, etc.) use
677
634
  * `AIChatAgentBase` with the `@withSkills` decorator instead.
@@ -708,7 +665,7 @@ var AIChatAgent = class extends AIChatAgentBase {
708
665
  tools: skills.tools,
709
666
  activeTools: skills.activeTools,
710
667
  prepareStep: skills.prepareStep,
711
- experimental_context: { headers: this._requestHeaders },
668
+ experimental_context: options?.body,
712
669
  stopWhen: stepCountIs(20),
713
670
  abortSignal: options?.abortSignal,
714
671
  onFinish
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents",
3
- "version": "0.0.1-alpha.7",
3
+ "version": "0.0.1-alpha.9",
4
4
  "description": "A starter for creating a TypeScript package.",
5
5
  "homepage": "https://github.com/author/library#readme",
6
6
  "bugs": {