@usestratus/sdk 1.2.0 → 1.5.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.
Files changed (57) hide show
  1. package/README.md +63 -27
  2. package/dist/azure/create-model.d.ts +15 -0
  3. package/dist/azure/create-model.d.ts.map +1 -0
  4. package/dist/azure/create-model.js +44 -0
  5. package/dist/azure/create-model.js.map +1 -0
  6. package/dist/azure/endpoint.d.ts +5 -0
  7. package/dist/azure/endpoint.d.ts.map +1 -1
  8. package/dist/azure/endpoint.js +22 -0
  9. package/dist/azure/endpoint.js.map +1 -1
  10. package/dist/azure/index.d.ts +3 -1
  11. package/dist/azure/index.d.ts.map +1 -1
  12. package/dist/azure/index.js +1 -0
  13. package/dist/azure/index.js.map +1 -1
  14. package/dist/azure/responses-model.d.ts +71 -0
  15. package/dist/azure/responses-model.d.ts.map +1 -1
  16. package/dist/azure/responses-model.js +243 -2
  17. package/dist/azure/responses-model.js.map +1 -1
  18. package/dist/core/agent.d.ts.map +1 -1
  19. package/dist/core/agent.js +2 -0
  20. package/dist/core/agent.js.map +1 -1
  21. package/dist/core/debug.d.ts +5 -0
  22. package/dist/core/debug.d.ts.map +1 -0
  23. package/dist/core/debug.js +36 -0
  24. package/dist/core/debug.js.map +1 -0
  25. package/dist/core/index.d.ts +2 -0
  26. package/dist/core/index.d.ts.map +1 -1
  27. package/dist/core/index.js +1 -0
  28. package/dist/core/index.js.map +1 -1
  29. package/dist/core/model.d.ts +2 -0
  30. package/dist/core/model.d.ts.map +1 -1
  31. package/dist/core/run.d.ts +2 -0
  32. package/dist/core/run.d.ts.map +1 -1
  33. package/dist/core/run.js +21 -0
  34. package/dist/core/run.js.map +1 -1
  35. package/dist/core/session.d.ts +6 -0
  36. package/dist/core/session.d.ts.map +1 -1
  37. package/dist/core/session.js +12 -0
  38. package/dist/core/session.js.map +1 -1
  39. package/dist/core/types.d.ts +4 -0
  40. package/dist/core/types.d.ts.map +1 -1
  41. package/dist/core/validate-agent.d.ts +14 -0
  42. package/dist/core/validate-agent.d.ts.map +1 -0
  43. package/dist/core/validate-agent.js +33 -0
  44. package/dist/core/validate-agent.js.map +1 -0
  45. package/dist/testing/index.d.ts +4 -0
  46. package/dist/testing/index.d.ts.map +1 -0
  47. package/dist/testing/index.js +3 -0
  48. package/dist/testing/index.js.map +1 -0
  49. package/dist/testing/mock-model.d.ts +12 -0
  50. package/dist/testing/mock-model.d.ts.map +1 -0
  51. package/dist/testing/mock-model.js +40 -0
  52. package/dist/testing/mock-model.js.map +1 -0
  53. package/dist/testing/response-builders.d.ts +15 -0
  54. package/dist/testing/response-builders.d.ts.map +1 -0
  55. package/dist/testing/response-builders.js +22 -0
  56. package/dist/testing/response-builders.js.map +1 -0
  57. package/package.json +5 -1
package/README.md CHANGED
@@ -18,11 +18,12 @@ A better TypeScript agent SDK for Azure OpenAI. Build multi-agent systems with t
18
18
  - **Built for Azure, not bolted on** — auto-endpoint detection, Entra ID auth, content filter errors as typed exceptions, and built-in retry. No 404 config spirals, no "which SDK do I use" confusion.
19
19
  - **Two API backends, one interface** — Chat Completions and Responses API through the same agent, tool, and session code. Start with one, switch with a single line.
20
20
  - **Multi-agent orchestration** — handoffs, subagents, guardrails, and hooks compose through a single run loop. Hooks can deny or modify tool calls at runtime.
21
- - **Client-side state you control** — save, resume, and fork conversations as portable JSON snapshots. No server-side threads, no opaque session IDs.
21
+ - **Human-in-the-loop** — `canUseTool` permission callbacks, `needsApproval` per tool, `allowedTools` glob filtering, and graceful `interrupt()` for stopping runs mid-flight.
22
+ - **Client-side state you control** — save, resume, and fork conversations as portable JSON snapshots. Hot-swap tools mid-session. No server-side threads, no opaque session IDs.
22
23
  - **Type-safe from schema to output** — Zod schemas drive tool parameters, structured output, and validation. Context types flow through agents, hooks, and guardrails at compile time.
23
24
  - **Zero dependencies** — only Zod as a peer dep. No transitive dependency sprawl, no framework lock-in.
24
25
 
25
- `agents` `tools` `streaming` `structured output` `handoffs` `subagents` `guardrails` `hooks` `tracing` `sessions` `abort signals` `code mode` `todo tracking` `cost tracking`
26
+ `agents` `tools` `streaming` `structured output` `handoffs` `subagents` `guardrails` `hooks` `tracing` `sessions` `abort signals` `code mode` `todo tracking` `cost tracking` `human-in-the-loop` `predicted output` `audio` `data sources` `context compaction` `background tasks` `testing utilities` `debug mode`
26
27
 
27
28
  ## Install
28
29
 
@@ -40,13 +41,9 @@ bun add zod
40
41
 
41
42
  ```ts
42
43
  import { z } from "zod";
43
- import { Agent, AzureResponsesModel, run, tool } from "@usestratus/sdk";
44
+ import { Agent, createModel, run, tool } from "@usestratus/sdk";
44
45
 
45
- const model = new AzureResponsesModel({
46
- endpoint: process.env.AZURE_OPENAI_ENDPOINT!,
47
- apiKey: process.env.AZURE_OPENAI_API_KEY!,
48
- deployment: "gpt-5.2",
49
- });
46
+ const model = createModel(); // reads AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEY, AZURE_OPENAI_DEPLOYMENT
50
47
 
51
48
  const getWeather = tool({
52
49
  name: "get_weather",
@@ -160,15 +157,15 @@ import { createSession } from "@usestratus/sdk";
160
157
 
161
158
  const session = createSession({ model, tools: [myTool] });
162
159
 
160
+ // Option 1: stream events
163
161
  session.send("Hello!");
164
162
  for await (const event of session.stream()) {
165
163
  // handle events
166
164
  }
167
165
 
166
+ // Option 2: just get the result
168
167
  session.send("Follow-up question");
169
- for await (const event of session.stream()) {
170
- // handle events
171
- }
168
+ const result = await session.wait();
172
169
 
173
170
  // Save and resume sessions
174
171
  const snapshot = session.save();
@@ -447,52 +444,91 @@ Implement the `Executor` interface for custom sandboxes (containers, Cloudflare
447
444
 
448
445
  ## Imports
449
446
 
450
- Stratus provides three export paths:
447
+ Stratus provides four export paths:
451
448
 
452
449
  ```ts
453
450
  // Everything (core + Azure)
454
- import { Agent, run, tool, AzureChatCompletionsModel, AzureResponsesModel } from "@usestratus/sdk";
451
+ import { Agent, run, tool, createModel } from "@usestratus/sdk";
455
452
 
456
453
  // Core only (provider-agnostic)
457
- import { Agent, run, tool } from "@usestratus/sdk/core";
454
+ import { Agent, run, tool, validateAgent } from "@usestratus/sdk/core";
458
455
 
459
456
  // Azure provider only
460
- import { AzureChatCompletionsModel, AzureResponsesModel } from "@usestratus/sdk/azure";
457
+ import { createModel, AzureResponsesModel } from "@usestratus/sdk/azure";
458
+
459
+ // Test utilities (keep out of production bundles)
460
+ import { createMockModel, textResponse, toolCallResponse } from "@usestratus/sdk/testing";
461
461
  ```
462
462
 
463
463
  ## Configuration
464
464
 
465
465
  ### Azure OpenAI
466
466
 
467
- Stratus includes two interchangeable Azure model implementations:
467
+ The fastest way `createModel()` reads from environment variables:
468
468
 
469
469
  ```ts
470
- // Chat Completions API
471
- const model = new AzureChatCompletionsModel({
472
- endpoint: process.env.AZURE_OPENAI_ENDPOINT!,
473
- apiKey: process.env.AZURE_OPENAI_API_KEY!,
474
- deployment: "gpt-5.2",
475
- apiVersion: "2025-03-01-preview", // optional, this is the default
476
- });
470
+ import { createModel } from "@usestratus/sdk";
471
+
472
+ const model = createModel(); // Responses API (default)
473
+ const model = createModel("chat-completions"); // Chat Completions API
474
+ ```
475
+
476
+ Or configure explicitly:
477
+
478
+ ```ts
479
+ import { AzureResponsesModel } from "@usestratus/sdk";
477
480
 
478
- // Responses API
479
481
  const model = new AzureResponsesModel({
480
- endpoint: process.env.AZURE_OPENAI_ENDPOINT!,
482
+ endpoint: "https://your-resource.openai.azure.com",
481
483
  apiKey: process.env.AZURE_OPENAI_API_KEY!,
482
484
  deployment: "gpt-5.2",
483
- apiVersion: "2025-04-01-preview", // optional, this is the default
484
485
  });
485
486
  ```
486
487
 
487
- Both implement the same `Model` interface — swap one for the other without changing any agent, tool, or session code.
488
+ Both models implement the same `Model` interface — swap one for the other without changing any agent, tool, or session code.
488
489
 
489
490
  ### Environment Variables
490
491
 
491
492
  ```
492
493
  AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
493
494
  AZURE_OPENAI_API_KEY=your-api-key
495
+ AZURE_OPENAI_DEPLOYMENT=gpt-5.2
494
496
  ```
495
497
 
498
+ ## Testing
499
+
500
+ Stratus ships test utilities as a separate entrypoint:
501
+
502
+ ```ts
503
+ import { createMockModel, textResponse, toolCallResponse } from "@usestratus/sdk/testing";
504
+
505
+ const model = createMockModel([
506
+ toolCallResponse([{ name: "search", args: { q: "test" } }]),
507
+ textResponse("Found 3 results"),
508
+ ]);
509
+
510
+ const agent = new Agent({ name: "test", model, tools: [searchTool] });
511
+ const result = await run(agent, "Search for test");
512
+ expect(result.output).toBe("Found 3 results");
513
+
514
+ // Capture requests for assertions
515
+ const model = createMockModel([textResponse("ok")], { capture: true });
516
+ await run(agent, "Hello");
517
+ expect(model.requests[0].messages[0].content).toBe("Hello");
518
+ ```
519
+
520
+ ## Debug Mode
521
+
522
+ Log model calls, tool executions, and handoffs to stderr:
523
+
524
+ ```ts
525
+ const result = await run(agent, "Hello", { debug: true });
526
+ // [stratus:model] 2026-04-02T... request to assistant {"messages":2,"tools":1,"turn":0}
527
+ // [stratus:model] 2026-04-02T... response from assistant {"content":"Hi!","toolCalls":[],...}
528
+ ```
529
+
530
+ Also works on sessions: `createSession({ model, debug: true })`.
531
+
496
532
  ## Error Handling
497
533
 
498
534
  All errors extend `StratusError`:
@@ -0,0 +1,15 @@
1
+ import type { Model } from "../core/model";
2
+ export type ModelType = "responses" | "chat-completions";
3
+ export interface CreateModelOptions {
4
+ endpoint?: string;
5
+ apiKey?: string;
6
+ azureAdTokenProvider?: () => Promise<string>;
7
+ deployment?: string;
8
+ apiVersion?: string;
9
+ maxRetries?: number;
10
+ /** Only for AzureResponsesModel */
11
+ store?: boolean;
12
+ }
13
+ export declare function createModel(type?: ModelType, options?: CreateModelOptions): Model;
14
+ export declare function createModel(options?: CreateModelOptions): Model;
15
+ //# sourceMappingURL=create-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-model.d.ts","sourceRoot":"","sources":["../../src/azure/create-model.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAI3C,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,kBAAkB,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,KAAK,CAAC;AACnF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,KAAK,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { StratusError } from "../core/errors";
2
+ import { AzureChatCompletionsModel } from "./chat-completions-model";
3
+ import { AzureResponsesModel } from "./responses-model";
4
+ export function createModel(typeOrOptions, maybeOptions) {
5
+ let type = "responses";
6
+ let options = {};
7
+ if (typeof typeOrOptions === "string") {
8
+ type = typeOrOptions;
9
+ options = maybeOptions ?? {};
10
+ }
11
+ else if (typeOrOptions) {
12
+ options = typeOrOptions;
13
+ }
14
+ const endpoint = options.endpoint ?? process.env.AZURE_OPENAI_ENDPOINT;
15
+ const apiKey = options.apiKey ?? process.env.AZURE_OPENAI_API_KEY;
16
+ const deployment = options.deployment ?? process.env.AZURE_OPENAI_DEPLOYMENT;
17
+ const apiVersion = options.apiVersion ?? process.env.AZURE_OPENAI_API_VERSION;
18
+ const tokenProvider = options.azureAdTokenProvider;
19
+ if (!endpoint) {
20
+ throw new StratusError("Missing Azure OpenAI endpoint. Set AZURE_OPENAI_ENDPOINT or pass options.endpoint.");
21
+ }
22
+ if (!deployment) {
23
+ throw new StratusError("Missing Azure OpenAI deployment. Set AZURE_OPENAI_DEPLOYMENT or pass options.deployment.");
24
+ }
25
+ if (!apiKey && !tokenProvider) {
26
+ throw new StratusError("Missing Azure OpenAI credentials. Set AZURE_OPENAI_API_KEY or pass options.apiKey / options.azureAdTokenProvider.");
27
+ }
28
+ const baseConfig = {
29
+ endpoint,
30
+ deployment,
31
+ ...(apiKey ? { apiKey } : {}),
32
+ ...(tokenProvider ? { azureAdTokenProvider: tokenProvider } : {}),
33
+ ...(apiVersion ? { apiVersion } : {}),
34
+ ...(options.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
35
+ };
36
+ if (type === "chat-completions") {
37
+ return new AzureChatCompletionsModel(baseConfig);
38
+ }
39
+ return new AzureResponsesModel({
40
+ ...baseConfig,
41
+ ...(options.store !== undefined ? { store: options.store } : {}),
42
+ });
43
+ }
44
+ //# sourceMappingURL=create-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-model.js","sourceRoot":"","sources":["../../src/azure/create-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAiBxD,MAAM,UAAU,WAAW,CAC1B,aAA8C,EAC9C,YAAiC;IAEjC,IAAI,IAAI,GAAc,WAAW,CAAC;IAClC,IAAI,OAAO,GAAuB,EAAE,CAAC;IAErC,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;QACvC,IAAI,GAAG,aAAa,CAAC;QACrB,OAAO,GAAG,YAAY,IAAI,EAAE,CAAC;IAC9B,CAAC;SAAM,IAAI,aAAa,EAAE,CAAC;QAC1B,OAAO,GAAG,aAAa,CAAC;IACzB,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,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AC;IACD,OAAO,IAAI,mBAAmB,CAAC;QAC9B,GAAG,UAAU;QACb,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChE,CAAC,CAAC;AACJ,CAAC"}
@@ -15,4 +15,9 @@ export declare function resolveChatCompletionsUrl(endpoint: string, deployment:
15
15
  * Resolve the full URL for Azure Responses API.
16
16
  */
17
17
  export declare function resolveResponsesUrl(endpoint: string, apiVersion: string): string;
18
+ /**
19
+ * Resolve the base URL prefix for Responses API sub-endpoints (compact, retrieve, delete, etc.).
20
+ * Returns the base without a trailing path so callers can append `/compact`, `/{id}`, etc.
21
+ */
22
+ export declare function resolveResponsesBaseUrl(endpoint: string, apiVersion: string): string;
18
23
  //# sourceMappingURL=endpoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/azure/endpoint.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAuBtE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GAChB,MAAM,CAWR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAYhF"}
1
+ {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/azure/endpoint.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAuBtE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GAChB,MAAM,CAWR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAYhF;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAkBpF"}
@@ -54,4 +54,26 @@ export function resolveResponsesUrl(endpoint, apiVersion) {
54
54
  return `${normalized}/openai/v1/responses`;
55
55
  }
56
56
  }
57
+ /**
58
+ * Resolve the base URL prefix for Responses API sub-endpoints (compact, retrieve, delete, etc.).
59
+ * Returns the base without a trailing path so callers can append `/compact`, `/{id}`, etc.
60
+ */
61
+ export function resolveResponsesBaseUrl(endpoint, apiVersion) {
62
+ const normalized = endpoint.replace(/\/$/, "");
63
+ const kind = detectEndpointKind(normalized);
64
+ switch (kind) {
65
+ case "full_url":
66
+ // If the URL contains /responses, strip everything after it.
67
+ // Otherwise it's a non-responses full_url (e.g. /openai/deployments/...) —
68
+ // fall through to standard format since sub-endpoints need the /responses base.
69
+ if (normalized.includes("/responses")) {
70
+ return normalized.replace(/\/responses.*$/, "/responses");
71
+ }
72
+ return `${new URL(normalized).origin}/openai/v1/responses`;
73
+ case "foundry":
74
+ return `${normalized}/openai/responses?api-version=${apiVersion}`;
75
+ case "standard":
76
+ return `${normalized}/openai/v1/responses`;
77
+ }
78
+ }
57
79
  //# sourceMappingURL=endpoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/azure/endpoint.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IAClD,IAAI,GAAQ,CAAC;IACb,IAAI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AzureChatCompletionsModel } from "./chat-completions-model";
2
4
  export type { AzureChatCompletionsModelConfig } from "./chat-completions-model";
3
5
  export { AzureResponsesModel } from "./responses-model";
4
- export type { AzureResponsesModelConfig } from "./responses-model";
6
+ export type { AzureResponsesModelConfig, CompactOptions, CompactResponse, InputItemList, McpApprovalResponseItem, RawResponse, ResponseStatus, RetrieveStreamOptions, } from "./responses-model";
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/azure/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,YAAY,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,YAAY,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/azure/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,YAAY,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,YAAY,EACX,yBAAyB,EACzB,cAAc,EACd,eAAe,EACf,aAAa,EACb,uBAAuB,EACvB,WAAW,EACX,cAAc,EACd,qBAAqB,GACrB,MAAM,mBAAmB,CAAC"}
@@ -1,3 +1,4 @@
1
+ export { createModel } from "./create-model";
1
2
  export { AzureChatCompletionsModel } from "./chat-completions-model";
2
3
  export { AzureResponsesModel } from "./responses-model";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/azure/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/azure/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -9,8 +9,58 @@ export interface AzureResponsesModelConfig {
9
9
  /** Maximum number of retries on 429 / network errors (default 3). */
10
10
  maxRetries?: number;
11
11
  }
12
+ export type ResponseStatus = "queued" | "in_progress" | "completed" | "failed" | "incomplete" | "cancelled";
13
+ export interface RawResponse {
14
+ id: string;
15
+ status: ResponseStatus;
16
+ output?: Record<string, unknown>[];
17
+ usage?: {
18
+ input_tokens: number;
19
+ output_tokens: number;
20
+ total_tokens: number;
21
+ };
22
+ incomplete_details?: {
23
+ reason?: string;
24
+ };
25
+ error?: {
26
+ message?: string;
27
+ type?: string;
28
+ code?: string;
29
+ };
30
+ [key: string]: unknown;
31
+ }
32
+ export interface CompactOptions {
33
+ model?: string;
34
+ input?: Record<string, unknown>[];
35
+ previousResponseId?: string;
36
+ signal?: AbortSignal;
37
+ }
38
+ export interface CompactResponse {
39
+ output: Record<string, unknown>[];
40
+ usage?: {
41
+ input_tokens: number;
42
+ output_tokens: number;
43
+ total_tokens: number;
44
+ };
45
+ }
46
+ export interface InputItemList {
47
+ data: Record<string, unknown>[];
48
+ hasMore: boolean;
49
+ firstId?: string;
50
+ lastId?: string;
51
+ }
52
+ export interface McpApprovalResponseItem {
53
+ type: "mcp_approval_response";
54
+ approval_request_id: string;
55
+ approve: boolean;
56
+ }
57
+ export interface RetrieveStreamOptions {
58
+ startingAfter?: number;
59
+ signal?: AbortSignal;
60
+ }
12
61
  export declare class AzureResponsesModel implements Model {
13
62
  private readonly url;
63
+ private readonly baseUrl;
14
64
  private readonly apiKey?;
15
65
  private readonly tokenProvider?;
16
66
  private readonly deployment;
@@ -20,6 +70,27 @@ export declare class AzureResponsesModel implements Model {
20
70
  private getAuthHeaders;
21
71
  getResponse(request: ModelRequest, options?: ModelRequestOptions): Promise<ModelResponse>;
22
72
  getStreamedResponse(request: ModelRequest, options?: ModelRequestOptions): AsyncGenerator<StreamEvent>;
73
+ compact(options: CompactOptions): Promise<CompactResponse>;
74
+ createBackgroundResponse(request: ModelRequest, options?: ModelRequestOptions & {
75
+ stream?: boolean;
76
+ }): Promise<RawResponse>;
77
+ streamBackgroundResponse(responseId: string, options?: RetrieveStreamOptions): AsyncGenerator<StreamEvent>;
78
+ retrieveResponse(responseId: string, options?: {
79
+ signal?: AbortSignal;
80
+ }): Promise<RawResponse>;
81
+ deleteResponse(responseId: string, options?: {
82
+ signal?: AbortSignal;
83
+ }): Promise<void>;
84
+ cancelResponse(responseId: string, options?: {
85
+ signal?: AbortSignal;
86
+ }): Promise<RawResponse>;
87
+ listInputItems(responseId: string, options?: {
88
+ signal?: AbortSignal;
89
+ }): Promise<InputItemList>;
90
+ private resolveSubEndpoint;
91
+ private urlHasQuery;
92
+ private doFetchUrl;
93
+ private mapSseEvent;
23
94
  private buildRequestBody;
24
95
  private doFetch;
25
96
  private handleErrorResponse;
@@ -1 +1 @@
1
- {"version":3,"file":"responses-model.d.ts","sourceRoot":"","sources":["../../src/azure/responses-model.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEX,KAAK,EACL,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,WAAW,EAEX,MAAM,eAAe,CAAC;AAcvB,MAAM,WAAW,yBAAyB;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C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