@tanstack/ai 0.38.0 → 0.39.1

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.
Files changed (46) hide show
  1. package/dist/esm/activities/chat/index.js +32 -0
  2. package/dist/esm/activities/chat/index.js.map +1 -1
  3. package/dist/esm/activities/chat/middleware/compose.d.ts +7 -1
  4. package/dist/esm/activities/chat/middleware/compose.js +27 -0
  5. package/dist/esm/activities/chat/middleware/compose.js.map +1 -1
  6. package/dist/esm/activities/chat/middleware/index.d.ts +1 -1
  7. package/dist/esm/activities/chat/middleware/sandbox-runtime.d.ts +8 -0
  8. package/dist/esm/activities/chat/middleware/sandbox-runtime.js +9 -0
  9. package/dist/esm/activities/chat/middleware/sandbox-runtime.js.map +1 -0
  10. package/dist/esm/activities/chat/middleware/types.d.ts +22 -0
  11. package/dist/esm/activities/chat/stream/processor.d.ts +18 -0
  12. package/dist/esm/activities/chat/stream/processor.js +86 -4
  13. package/dist/esm/activities/chat/stream/processor.js.map +1 -1
  14. package/dist/esm/adapter-internals.d.ts +2 -0
  15. package/dist/esm/adapter-internals.js +4 -0
  16. package/dist/esm/adapter-internals.js.map +1 -1
  17. package/dist/esm/index.d.ts +3 -2
  18. package/dist/esm/index.js +3 -0
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/logger/internal-logger.d.ts +2 -0
  21. package/dist/esm/logger/internal-logger.js +6 -1
  22. package/dist/esm/logger/internal-logger.js.map +1 -1
  23. package/dist/esm/logger/resolve.js +6 -3
  24. package/dist/esm/logger/resolve.js.map +1 -1
  25. package/dist/esm/logger/types.d.ts +5 -0
  26. package/dist/esm/types.d.ts +40 -1
  27. package/dist/esm/utilities/provider-executed.d.ts +18 -0
  28. package/dist/esm/utilities/provider-executed.js +15 -0
  29. package/dist/esm/utilities/provider-executed.js.map +1 -0
  30. package/package.json +1 -1
  31. package/skills/ai-core/adapter-configuration/SKILL.md +25 -12
  32. package/skills/ai-core/adapter-configuration/references/anthropic-adapter.md +43 -12
  33. package/skills/ai-core/media-generation/SKILL.md +1 -1
  34. package/src/activities/chat/index.ts +47 -0
  35. package/src/activities/chat/middleware/compose.ts +34 -0
  36. package/src/activities/chat/middleware/index.ts +2 -0
  37. package/src/activities/chat/middleware/sandbox-runtime.ts +21 -0
  38. package/src/activities/chat/middleware/types.ts +37 -0
  39. package/src/activities/chat/stream/processor.ts +141 -3
  40. package/src/adapter-internals.ts +6 -0
  41. package/src/index.ts +9 -0
  42. package/src/logger/internal-logger.ts +6 -0
  43. package/src/logger/resolve.ts +3 -0
  44. package/src/logger/types.ts +5 -0
  45. package/src/types.ts +43 -1
  46. package/src/utilities/provider-executed.ts +32 -0
@@ -4,12 +4,14 @@ import { stripToSpecMiddleware } from "../../strip-to-spec-middleware.js";
4
4
  import { streamToText } from "../../stream-to-response.js";
5
5
  import { resolveDebugOption } from "../../logger/resolve.js";
6
6
  import { normalizeToolResult } from "../../utilities/tool-result.js";
7
+ import { isProviderExecutedToolCall } from "../../utilities/provider-executed.js";
7
8
  import { LazyToolManager } from "./tools/lazy-tool-manager.js";
8
9
  import { ToolCallManager, MiddlewareAbortError, executeToolCalls } from "./tools/tool-calls.js";
9
10
  import { convertSchemaForStructuredOutput, isStandardSchema, parseWithStandardSchema, convertSchemaToJsonSchema } from "./tools/schema-converter.js";
10
11
  import { maxIterations } from "./agent-loop-strategies.js";
11
12
  import { convertMessagesToModelMessages, generateMessageId } from "./messages.js";
12
13
  import { MiddlewareRunner } from "./middleware/compose.js";
14
+ import { provideSandboxRuntime } from "./middleware/sandbox-runtime.js";
13
15
  import { CapabilityRegistry } from "./middleware/capabilities.js";
14
16
  import { validateCapabilities } from "./middleware/validate.js";
15
17
  import { MCPManager } from "./mcp/manager.js";
@@ -70,6 +72,7 @@ class TextEngine {
70
72
  // Middleware support
71
73
  middlewareRunner;
72
74
  middlewareCtx;
75
+ sandboxFileQueue = [];
73
76
  deferredPromises = [];
74
77
  abortReason;
75
78
  middlewareAbortController;
@@ -185,6 +188,16 @@ class TextEngine {
185
188
  getOptional: (capability) => capability[0](this.middlewareCtx, { optional: true }),
186
189
  provide: (capability, value) => capability[1](this.middlewareCtx, value)
187
190
  };
191
+ provideSandboxRuntime(this.middlewareCtx, {
192
+ logger: this.logger,
193
+ emit: (event) => {
194
+ this.logger.sandbox(`file ${event.type} ${event.path}`, { event });
195
+ void this.middlewareRunner.runSandboxFile(this.middlewareCtx, event);
196
+ this.sandboxFileQueue.push(
197
+ this.createCustomEventChunk("sandbox.file", { ...event })
198
+ );
199
+ }
200
+ });
188
201
  }
189
202
  /** Get the accumulated content after the chat loop completes */
190
203
  getAccumulatedContent() {
@@ -399,6 +412,10 @@ class TextEngine {
399
412
  threadId: this.threadId,
400
413
  runId: this.runIdOverride,
401
414
  parentRunId: this.parentRunIdOverride,
415
+ // Expose provided capabilities (e.g. sandbox) to harness adapters.
416
+ capabilities: this.middlewareCtx,
417
+ // Client approval decisions, for harness interactive-approval resolution.
418
+ approvals: this.initialApprovals,
402
419
  ...combinedSchema ? { outputSchema: combinedSchema } : {}
403
420
  })) {
404
421
  if (this.isCancelled()) {
@@ -444,10 +461,12 @@ class TextEngine {
444
461
  if (chunk.type === "RUN_FINISHED" && chunk.usage) {
445
462
  await this.middlewareRunner.runOnUsage(this.middlewareCtx, chunk.usage);
446
463
  }
464
+ yield* this.drainSandboxFileQueue();
447
465
  if (this.earlyTermination) {
448
466
  break;
449
467
  }
450
468
  }
469
+ yield* this.drainSandboxFileQueue();
451
470
  }
452
471
  handleStreamChunk(chunk) {
453
472
  switch (chunk.type) {
@@ -996,6 +1015,9 @@ class TextEngine {
996
1015
  for (const message of this.messages) {
997
1016
  if (message.role === "assistant" && message.toolCalls) {
998
1017
  for (const toolCall of message.toolCalls) {
1018
+ if (isProviderExecutedToolCall(toolCall)) {
1019
+ continue;
1020
+ }
999
1021
  if (!completedToolIds.has(toolCall.id)) {
1000
1022
  pending.push(toolCall);
1001
1023
  }
@@ -1412,6 +1434,16 @@ class TextEngine {
1412
1434
  this.middlewareCtx.chunkIndex++;
1413
1435
  }
1414
1436
  }
1437
+ /**
1438
+ * Drain queued `sandbox.file` chunks (emitted via the SandboxRuntime sink)
1439
+ * through the middleware pipeline and into the public stream.
1440
+ */
1441
+ async *drainSandboxFileQueue() {
1442
+ while (this.sandboxFileQueue.length > 0) {
1443
+ const chunk = this.sandboxFileQueue.shift();
1444
+ if (chunk) yield* this.pipeThroughMiddleware(chunk);
1445
+ }
1446
+ }
1415
1447
  /**
1416
1448
  * Drain an executeToolCalls async generator, yielding any CustomEvent chunks
1417
1449
  * through the middleware pipeline and returning the final ExecuteToolCallsResult.