@proposit/proposit-core 1.10.0 → 2.0.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 (116) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/commands/expressions.d.ts +29 -0
  3. package/dist/cli/commands/expressions.d.ts.map +1 -1
  4. package/dist/cli/commands/expressions.js +118 -92
  5. package/dist/cli/commands/expressions.js.map +1 -1
  6. package/dist/extensions/argument-ingestion/shared/finalize-response-v2.d.ts.map +1 -1
  7. package/dist/extensions/argument-ingestion/shared/finalize-response-v2.js +18 -2
  8. package/dist/extensions/argument-ingestion/shared/finalize-response-v2.js.map +1 -1
  9. package/dist/extensions/{ieee → citations/ieee}/citation-claim.d.ts +53 -59
  10. package/dist/extensions/{ieee → citations/ieee}/citation-claim.d.ts.map +1 -1
  11. package/dist/extensions/{ieee → citations/ieee}/citation-claim.js +2 -2
  12. package/dist/extensions/citations/ieee/citation-claim.js.map +1 -0
  13. package/dist/extensions/citations/ieee/formatting.d.ts.map +1 -0
  14. package/dist/extensions/{ieee → citations/ieee}/formatting.js +0 -1
  15. package/dist/extensions/citations/ieee/formatting.js.map +1 -0
  16. package/dist/extensions/citations/ieee/index.d.ts.map +1 -0
  17. package/dist/extensions/citations/ieee/index.js.map +1 -0
  18. package/dist/extensions/{ieee → citations/ieee}/references.d.ts +161 -181
  19. package/dist/extensions/citations/ieee/references.d.ts.map +1 -0
  20. package/dist/extensions/{ieee → citations/ieee}/references.js +48 -22
  21. package/dist/extensions/citations/ieee/references.js.map +1 -0
  22. package/dist/extensions/{ieee → citations/ieee}/relaxed.d.ts +159 -180
  23. package/dist/extensions/citations/ieee/relaxed.d.ts.map +1 -0
  24. package/dist/extensions/{ieee → citations/ieee}/relaxed.js +1 -4
  25. package/dist/extensions/{ieee → citations/ieee}/relaxed.js.map +1 -1
  26. package/dist/extensions/citations/ieee/segment-builder.d.ts.map +1 -0
  27. package/dist/extensions/citations/ieee/segment-builder.js.map +1 -0
  28. package/dist/extensions/{ieee → citations/ieee}/segment-templates.d.ts +0 -1
  29. package/dist/extensions/citations/ieee/segment-templates.d.ts.map +1 -0
  30. package/dist/extensions/{ieee → citations/ieee}/segment-templates.js +0 -27
  31. package/dist/extensions/citations/ieee/segment-templates.js.map +1 -0
  32. package/dist/extensions/citations/unparsed/index.d.ts +2 -0
  33. package/dist/extensions/citations/unparsed/index.d.ts.map +1 -0
  34. package/dist/extensions/citations/unparsed/index.js +2 -0
  35. package/dist/extensions/citations/unparsed/index.js.map +1 -0
  36. package/dist/extensions/citations/unparsed/unparsed-citation.d.ts +11 -0
  37. package/dist/extensions/citations/unparsed/unparsed-citation.d.ts.map +1 -0
  38. package/dist/extensions/citations/unparsed/unparsed-citation.js +22 -0
  39. package/dist/extensions/citations/unparsed/unparsed-citation.js.map +1 -0
  40. package/dist/extensions/openai/errors.d.ts +8 -0
  41. package/dist/extensions/openai/errors.d.ts.map +1 -1
  42. package/dist/extensions/openai/errors.js +58 -0
  43. package/dist/extensions/openai/errors.js.map +1 -1
  44. package/dist/extensions/openai/index.d.ts +4 -2
  45. package/dist/extensions/openai/index.d.ts.map +1 -1
  46. package/dist/extensions/openai/index.js +2 -1
  47. package/dist/extensions/openai/index.js.map +1 -1
  48. package/dist/extensions/openai/openai-http.d.ts +30 -0
  49. package/dist/extensions/openai/openai-http.d.ts.map +1 -0
  50. package/dist/extensions/openai/openai-http.js +310 -0
  51. package/dist/extensions/openai/openai-http.js.map +1 -0
  52. package/dist/extensions/openai/openai-parsing.d.ts +34 -0
  53. package/dist/extensions/openai/openai-parsing.d.ts.map +1 -0
  54. package/dist/extensions/openai/openai-parsing.js +226 -0
  55. package/dist/extensions/openai/openai-parsing.js.map +1 -0
  56. package/dist/extensions/openai/openai-retrieval.d.ts +150 -0
  57. package/dist/extensions/openai/openai-retrieval.d.ts.map +1 -0
  58. package/dist/extensions/openai/openai-retrieval.js +248 -0
  59. package/dist/extensions/openai/openai-retrieval.js.map +1 -0
  60. package/dist/extensions/openai/openai-tools.d.ts +9 -0
  61. package/dist/extensions/openai/openai-tools.d.ts.map +1 -0
  62. package/dist/extensions/openai/openai-tools.js +93 -0
  63. package/dist/extensions/openai/openai-tools.js.map +1 -0
  64. package/dist/extensions/openai/provider.d.ts +1 -100
  65. package/dist/extensions/openai/provider.d.ts.map +1 -1
  66. package/dist/extensions/openai/provider.js +5 -794
  67. package/dist/extensions/openai/provider.js.map +1 -1
  68. package/dist/extensions/openai/types.d.ts +1 -0
  69. package/dist/extensions/openai/types.d.ts.map +1 -1
  70. package/dist/extensions/openai/types.js +4 -1
  71. package/dist/extensions/openai/types.js.map +1 -1
  72. package/dist/lib/core/premise-engine.d.ts +15 -0
  73. package/dist/lib/core/premise-engine.d.ts.map +1 -1
  74. package/dist/lib/core/premise-engine.js +62 -127
  75. package/dist/lib/core/premise-engine.js.map +1 -1
  76. package/dist/lib/index.d.ts +3 -3
  77. package/dist/lib/index.d.ts.map +1 -1
  78. package/dist/lib/index.js +1 -1
  79. package/dist/lib/index.js.map +1 -1
  80. package/dist/lib/llm/index.d.ts +1 -1
  81. package/dist/lib/llm/index.d.ts.map +1 -1
  82. package/dist/lib/llm/types.d.ts +40 -0
  83. package/dist/lib/llm/types.d.ts.map +1 -1
  84. package/dist/lib/parsing/prompt-builder.d.ts.map +1 -1
  85. package/dist/lib/parsing/prompt-builder.js +14 -3
  86. package/dist/lib/parsing/prompt-builder.js.map +1 -1
  87. package/dist/lib/pipelines/execute.d.ts +175 -3
  88. package/dist/lib/pipelines/execute.d.ts.map +1 -1
  89. package/dist/lib/pipelines/execute.js +574 -219
  90. package/dist/lib/pipelines/execute.js.map +1 -1
  91. package/dist/lib/pipelines/index.d.ts +3 -3
  92. package/dist/lib/pipelines/index.d.ts.map +1 -1
  93. package/dist/lib/pipelines/index.js +2 -2
  94. package/dist/lib/pipelines/index.js.map +1 -1
  95. package/dist/lib/pipelines/stage-helpers.d.ts +89 -1
  96. package/dist/lib/pipelines/stage-helpers.d.ts.map +1 -1
  97. package/dist/lib/pipelines/stage-helpers.js +225 -31
  98. package/dist/lib/pipelines/stage-helpers.js.map +1 -1
  99. package/package.json +10 -5
  100. package/dist/extensions/ieee/citation-claim.js.map +0 -1
  101. package/dist/extensions/ieee/formatting.d.ts.map +0 -1
  102. package/dist/extensions/ieee/formatting.js.map +0 -1
  103. package/dist/extensions/ieee/index.d.ts.map +0 -1
  104. package/dist/extensions/ieee/index.js.map +0 -1
  105. package/dist/extensions/ieee/references.d.ts.map +0 -1
  106. package/dist/extensions/ieee/references.js.map +0 -1
  107. package/dist/extensions/ieee/relaxed.d.ts.map +0 -1
  108. package/dist/extensions/ieee/segment-builder.d.ts.map +0 -1
  109. package/dist/extensions/ieee/segment-builder.js.map +0 -1
  110. package/dist/extensions/ieee/segment-templates.d.ts.map +0 -1
  111. package/dist/extensions/ieee/segment-templates.js.map +0 -1
  112. /package/dist/extensions/{ieee → citations/ieee}/formatting.d.ts +0 -0
  113. /package/dist/extensions/{ieee → citations/ieee}/index.d.ts +0 -0
  114. /package/dist/extensions/{ieee → citations/ieee}/index.js +0 -0
  115. /package/dist/extensions/{ieee → citations/ieee}/segment-builder.d.ts +0 -0
  116. /package/dist/extensions/{ieee → citations/ieee}/segment-builder.js +0 -0
@@ -0,0 +1,150 @@
1
+ import type { TLlmRequest } from "../../lib/llm/types.js";
2
+ import { type TOpenAiFetch } from "./types.js";
3
+ /**
4
+ * The status values the OpenAI Responses API reports for a stored
5
+ * response. `completed` / `failed` / `incomplete` / `cancelled` are
6
+ * terminal; `queued` / `in_progress` are transient.
7
+ */
8
+ export type TResponseStatus = "queued" | "in_progress" | "completed" | "failed" | "incomplete" | "cancelled";
9
+ /**
10
+ * The structured result of a `retrieveResponse` call. All fields
11
+ * except `status` and `rawResponseId` are absent for non-terminal
12
+ * or failed responses.
13
+ */
14
+ export type TRetrievedResponse = {
15
+ /** Current status of the stored response. */
16
+ status: TResponseStatus;
17
+ /**
18
+ * Parsed text output, present when `status === "completed"` and
19
+ * the response carried a `message` output item.
20
+ */
21
+ output?: string;
22
+ /** Token usage reported by OpenAI, when available. */
23
+ tokenUsage?: import("../../lib/llm/types.js").TLlmTokenUsage;
24
+ /** The OpenAI response id that was retrieved. */
25
+ rawResponseId: string;
26
+ /**
27
+ * The envelope's `incomplete_details.reason`, present when
28
+ * `status === "incomplete"` (e.g. `max_output_tokens`,
29
+ * `content_filter`). Lets a completion-side consumer classify an
30
+ * incomplete response without re-deriving it. Additive (since
31
+ * v1.11.0).
32
+ */
33
+ incompleteReason?: string;
34
+ /**
35
+ * The envelope's `error.message`, present when `status === "failed"`.
36
+ * Additive (since v1.11.0).
37
+ */
38
+ errorMessage?: string;
39
+ };
40
+ /**
41
+ * Retrieve a stored OpenAI response by id. Surfaces the current
42
+ * status, output text (when completed), and token usage.
43
+ *
44
+ * Throws {@link ResponseNotFoundError} when the response is not found
45
+ * (HTTP 404), which typically means the ~10-minute retention window
46
+ * has elapsed. Callers should clear the stored id, settle the
47
+ * associated stage as failed, and surface a retry prompt.
48
+ *
49
+ * @param id - The OpenAI response id to retrieve.
50
+ * @param options - Provider configuration (apiKey, optional baseUrl and fetch).
51
+ */
52
+ export declare function retrieveResponse(id: string, options: {
53
+ apiKey: string;
54
+ baseUrl?: string;
55
+ fetch?: TOpenAiFetch;
56
+ signal?: AbortSignal;
57
+ }): Promise<TRetrievedResponse>;
58
+ /**
59
+ * Reconnect to a stored, still-generating background response and
60
+ * **stream it to completion**. This is what actually drives a dropped
61
+ * background response forward: a passive `retrieveResponse` GET only
62
+ * reads the current state and leaves a `queued` / `in_progress`
63
+ * response sitting where it is, whereas reconnecting with `stream=true`
64
+ * resumes consumption so the response reaches a terminal status.
65
+ *
66
+ * Issues `GET /responses/{id}?stream=true&starting_after=<cursor>` and
67
+ * consumes the SSE stream to its terminal event, returning the same
68
+ * {@link TRetrievedResponse} shape as {@link retrieveResponse}.
69
+ *
70
+ * Throws {@link ResponseNotFoundError} when the response is not found
71
+ * (HTTP 404 — typically the ~10-minute retention window elapsed).
72
+ * Honors `signal`: an abort propagates as an `AbortError` from the
73
+ * underlying stream read.
74
+ *
75
+ * @param id - The OpenAI response id to reconnect to.
76
+ * @param options - `apiKey`, optional `startingAfter` SSE cursor
77
+ * (defaults to 0 — replay from the start of the stored stream),
78
+ * optional `baseUrl`, `fetch`, and `signal`.
79
+ */
80
+ export declare function reconnectStream(id: string, options: {
81
+ apiKey: string;
82
+ startingAfter?: number;
83
+ baseUrl?: string;
84
+ fetch?: TOpenAiFetch;
85
+ signal?: AbortSignal;
86
+ }): Promise<TRetrievedResponse>;
87
+ /**
88
+ * Cancel a stored, in-flight OpenAI response. Issues
89
+ * `POST /responses/{id}/cancel` and returns the resulting
90
+ * {@link TRetrievedResponse} (typically `status: "cancelled"`).
91
+ *
92
+ * Cancel is **idempotent** per the Responses API: cancelling twice, or
93
+ * cancelling an already-terminal response, simply returns the final
94
+ * `Response` object rather than erroring — so callers do not need to
95
+ * guard against double-cancel.
96
+ *
97
+ * Throws {@link ResponseNotFoundError} when the response is not found
98
+ * (HTTP 404 — typically the ~10-minute retention window elapsed).
99
+ * Honors `signal` (an abort propagates as an `AbortError`).
100
+ *
101
+ * Use this to stop an in-flight background response when a stage is
102
+ * abandoned (resync timeout) or an import is cancelled, so generation
103
+ * does not keep running (and billing) server-side after the consumer
104
+ * has given up on it.
105
+ *
106
+ * @param id - The OpenAI response id to cancel.
107
+ * @param options - `apiKey`, optional `baseUrl`, `fetch`, and `signal`.
108
+ */
109
+ export declare function cancelResponse(id: string, options: {
110
+ apiKey: string;
111
+ baseUrl?: string;
112
+ fetch?: TOpenAiFetch;
113
+ signal?: AbortSignal;
114
+ }): Promise<TRetrievedResponse>;
115
+ /**
116
+ * Submit a background OpenAI response and return its `responseId` +
117
+ * submit-time `status` **without polling or streaming to completion**.
118
+ *
119
+ * This is the submit-only half of the existing `backgroundMode`
120
+ * (`runBackground`): it POSTs `{ background: true, store: true }`, parses
121
+ * the submit envelope, and returns immediately — the caller drives the
122
+ * response to completion later via {@link retrieveResponse} (typically
123
+ * after a durable suspend keyed on the returned `responseId`). It is the
124
+ * provider capability the pipeline's `launchStage` needs.
125
+ *
126
+ * **Terminal-on-submit fast-path:** a small/cached request can come back
127
+ * already terminal (`completed`/`failed`/`incomplete`/`cancelled`) on the
128
+ * submit POST. This function still returns `{ responseId, status }` for
129
+ * that case (no throw, no poll); the caller proceeds to
130
+ * `retrieveResponse(responseId)`, which sees the terminal state
131
+ * immediately.
132
+ *
133
+ * **No-tools precondition:** background mode does not support function
134
+ * tools in V1 — a tool-bearing request throws {@link NonRetryableLlmError},
135
+ * matching `respond`'s background guard.
136
+ *
137
+ * @param req - The structured-output request (system/user prompts +
138
+ * `outputSchema` + model knobs). Tools are rejected.
139
+ * @param options - `apiKey`, optional `baseUrl`, `fetch`, and `signal`.
140
+ */
141
+ export declare function submitBackgroundResponse<T>(req: TLlmRequest<T>, options: {
142
+ apiKey: string;
143
+ baseUrl?: string;
144
+ fetch?: TOpenAiFetch;
145
+ signal?: AbortSignal;
146
+ }): Promise<{
147
+ responseId: string;
148
+ status: TResponseStatus;
149
+ }>;
150
+ //# sourceMappingURL=openai-retrieval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-retrieval.d.ts","sourceRoot":"","sources":["../../../src/extensions/openai/openai-retrieval.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAqBzD,OAAO,EAEH,KAAK,YAAY,EAGpB,MAAM,YAAY,CAAA;AAInB;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACrB,QAAQ,GACR,aAAa,GACb,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,WAAW,CAAA;AAEjB;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B,6CAA6C;IAC7C,MAAM,EAAE,eAAe,CAAA;IACvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,sDAAsD;IACt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CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,WAAW,CAAA;CACvB,GACF,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC,CA+D1D"}
@@ -0,0 +1,248 @@
1
+ // Public retrieval API for stored OpenAI Responses: retrieve a stored
2
+ // response by id, reconnect-and-stream a dropped background response to
3
+ // completion, cancel an in-flight response, and submit a background
4
+ // response without polling. These are the resync surfaces a consumer
5
+ // drives after a durable suspend.
6
+ //
7
+ // Layering: this module sits alongside `provider.ts` (neither imports
8
+ // the other) and above `openai-http.ts` / `openai-parsing.ts`, from
9
+ // which it consumes the transport and parsing helpers.
10
+ import { callOnce, getResponseById, parseJsonOrThrowTransient, resolveFetch, } from "./openai-http.js";
11
+ import { extractAssistantText, extractUsage, isAbortError, readSseEnvelope, } from "./openai-parsing.js";
12
+ import { deriveSchemaName } from "./openai-tools.js";
13
+ import { typeboxToOpenAiSchema } from "./structured-output.js";
14
+ import { classifyHttpError, NonRetryableLlmError, ResponseNotFoundError, TransientLlmError, } from "./errors.js";
15
+ import { DEFAULT_BASE_URL, } from "./types.js";
16
+ /**
17
+ * Retrieve a stored OpenAI response by id. Surfaces the current
18
+ * status, output text (when completed), and token usage.
19
+ *
20
+ * Throws {@link ResponseNotFoundError} when the response is not found
21
+ * (HTTP 404), which typically means the ~10-minute retention window
22
+ * has elapsed. Callers should clear the stored id, settle the
23
+ * associated stage as failed, and surface a retry prompt.
24
+ *
25
+ * @param id - The OpenAI response id to retrieve.
26
+ * @param options - Provider configuration (apiKey, optional baseUrl and fetch).
27
+ */
28
+ export async function retrieveResponse(id, options) {
29
+ const fetchImpl = resolveFetch(options.fetch, "retrieveResponse");
30
+ const envelope = await getResponseById({
31
+ url: options.baseUrl ?? DEFAULT_BASE_URL,
32
+ id,
33
+ apiKey: options.apiKey,
34
+ fetchImpl,
35
+ signal: options.signal,
36
+ });
37
+ return envelopeToRetrievedResponse(envelope, id);
38
+ }
39
+ /**
40
+ * Reconnect to a stored, still-generating background response and
41
+ * **stream it to completion**. This is what actually drives a dropped
42
+ * background response forward: a passive `retrieveResponse` GET only
43
+ * reads the current state and leaves a `queued` / `in_progress`
44
+ * response sitting where it is, whereas reconnecting with `stream=true`
45
+ * resumes consumption so the response reaches a terminal status.
46
+ *
47
+ * Issues `GET /responses/{id}?stream=true&starting_after=<cursor>` and
48
+ * consumes the SSE stream to its terminal event, returning the same
49
+ * {@link TRetrievedResponse} shape as {@link retrieveResponse}.
50
+ *
51
+ * Throws {@link ResponseNotFoundError} when the response is not found
52
+ * (HTTP 404 — typically the ~10-minute retention window elapsed).
53
+ * Honors `signal`: an abort propagates as an `AbortError` from the
54
+ * underlying stream read.
55
+ *
56
+ * @param id - The OpenAI response id to reconnect to.
57
+ * @param options - `apiKey`, optional `startingAfter` SSE cursor
58
+ * (defaults to 0 — replay from the start of the stored stream),
59
+ * optional `baseUrl`, `fetch`, and `signal`.
60
+ */
61
+ export async function reconnectStream(id, options) {
62
+ const fetchImpl = resolveFetch(options.fetch, "reconnectStream");
63
+ const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
64
+ const startingAfter = options.startingAfter ?? 0;
65
+ const url = `${baseUrl}/${id}?stream=true&starting_after=${startingAfter.toString()}`;
66
+ let response;
67
+ try {
68
+ response = await fetchImpl(url, {
69
+ method: "GET",
70
+ headers: { Authorization: `Bearer ${options.apiKey}` },
71
+ signal: options.signal,
72
+ });
73
+ }
74
+ catch (err) {
75
+ if (isAbortError(err))
76
+ throw err;
77
+ throw new TransientLlmError({
78
+ message: `Network error reconnecting to OpenAI background response: ${err instanceof Error ? err.message : String(err)}`,
79
+ });
80
+ }
81
+ if (response.status === 404) {
82
+ throw new ResponseNotFoundError({ responseId: id });
83
+ }
84
+ if (!response.ok) {
85
+ const errorBody = await response.text().catch(() => "");
86
+ throw classifyHttpError(response.status, `OpenAI reconnect ${response.status.toString()}: ${errorBody || response.statusText}`);
87
+ }
88
+ const envelope = await readSseEnvelope(response);
89
+ return envelopeToRetrievedResponse(envelope, id);
90
+ }
91
+ /**
92
+ * Cancel a stored, in-flight OpenAI response. Issues
93
+ * `POST /responses/{id}/cancel` and returns the resulting
94
+ * {@link TRetrievedResponse} (typically `status: "cancelled"`).
95
+ *
96
+ * Cancel is **idempotent** per the Responses API: cancelling twice, or
97
+ * cancelling an already-terminal response, simply returns the final
98
+ * `Response` object rather than erroring — so callers do not need to
99
+ * guard against double-cancel.
100
+ *
101
+ * Throws {@link ResponseNotFoundError} when the response is not found
102
+ * (HTTP 404 — typically the ~10-minute retention window elapsed).
103
+ * Honors `signal` (an abort propagates as an `AbortError`).
104
+ *
105
+ * Use this to stop an in-flight background response when a stage is
106
+ * abandoned (resync timeout) or an import is cancelled, so generation
107
+ * does not keep running (and billing) server-side after the consumer
108
+ * has given up on it.
109
+ *
110
+ * @param id - The OpenAI response id to cancel.
111
+ * @param options - `apiKey`, optional `baseUrl`, `fetch`, and `signal`.
112
+ */
113
+ export async function cancelResponse(id, options) {
114
+ const fetchImpl = resolveFetch(options.fetch, "cancelResponse");
115
+ const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
116
+ let response;
117
+ try {
118
+ response = await fetchImpl(`${baseUrl}/${id}/cancel`, {
119
+ method: "POST",
120
+ headers: { Authorization: `Bearer ${options.apiKey}` },
121
+ signal: options.signal,
122
+ });
123
+ }
124
+ catch (err) {
125
+ if (isAbortError(err))
126
+ throw err;
127
+ throw new TransientLlmError({
128
+ message: `Network error cancelling OpenAI background response: ${err instanceof Error ? err.message : String(err)}`,
129
+ });
130
+ }
131
+ if (response.status === 404) {
132
+ throw new ResponseNotFoundError({ responseId: id });
133
+ }
134
+ if (!response.ok) {
135
+ const errorBody = await response.text().catch(() => "");
136
+ throw classifyHttpError(response.status, `OpenAI cancel ${response.status.toString()}: ${errorBody || response.statusText}`);
137
+ }
138
+ const envelope = await parseJsonOrThrowTransient(response, "OpenAI cancel body was not valid JSON");
139
+ return envelopeToRetrievedResponse(envelope, id);
140
+ }
141
+ /**
142
+ * Submit a background OpenAI response and return its `responseId` +
143
+ * submit-time `status` **without polling or streaming to completion**.
144
+ *
145
+ * This is the submit-only half of the existing `backgroundMode`
146
+ * (`runBackground`): it POSTs `{ background: true, store: true }`, parses
147
+ * the submit envelope, and returns immediately — the caller drives the
148
+ * response to completion later via {@link retrieveResponse} (typically
149
+ * after a durable suspend keyed on the returned `responseId`). It is the
150
+ * provider capability the pipeline's `launchStage` needs.
151
+ *
152
+ * **Terminal-on-submit fast-path:** a small/cached request can come back
153
+ * already terminal (`completed`/`failed`/`incomplete`/`cancelled`) on the
154
+ * submit POST. This function still returns `{ responseId, status }` for
155
+ * that case (no throw, no poll); the caller proceeds to
156
+ * `retrieveResponse(responseId)`, which sees the terminal state
157
+ * immediately.
158
+ *
159
+ * **No-tools precondition:** background mode does not support function
160
+ * tools in V1 — a tool-bearing request throws {@link NonRetryableLlmError},
161
+ * matching `respond`'s background guard.
162
+ *
163
+ * @param req - The structured-output request (system/user prompts +
164
+ * `outputSchema` + model knobs). Tools are rejected.
165
+ * @param options - `apiKey`, optional `baseUrl`, `fetch`, and `signal`.
166
+ */
167
+ export async function submitBackgroundResponse(req, options) {
168
+ if (req.tools && req.tools.length > 0) {
169
+ throw new NonRetryableLlmError({
170
+ message: "OpenAI background mode does not support function tools in V1. Disable backgroundMode / backgroundStreamMode for tool-using requests, or run the tools synchronously.",
171
+ });
172
+ }
173
+ const fetchImpl = resolveFetch(options.fetch, "submitBackgroundResponse");
174
+ const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
175
+ const schemaName = deriveSchemaName(req.outputSchema);
176
+ const convertedSchema = typeboxToOpenAiSchema(req.outputSchema);
177
+ const body = {
178
+ model: req.model,
179
+ input: [
180
+ { role: "system", content: req.systemPrompt },
181
+ { role: "user", content: req.userMessage },
182
+ ],
183
+ text: {
184
+ format: {
185
+ type: "json_schema",
186
+ name: schemaName,
187
+ strict: true,
188
+ schema: convertedSchema,
189
+ },
190
+ },
191
+ background: true,
192
+ store: true,
193
+ };
194
+ if (req.maxOutputTokens !== undefined) {
195
+ body.max_output_tokens = req.maxOutputTokens;
196
+ }
197
+ if (req.reasoningEffort) {
198
+ body.reasoning = { effort: req.reasoningEffort };
199
+ }
200
+ const submit = await callOnce({
201
+ url: baseUrl,
202
+ apiKey: options.apiKey,
203
+ body,
204
+ fetchImpl,
205
+ signal: req.signal ?? options.signal,
206
+ });
207
+ const submitEnvelope = await parseJsonOrThrowTransient(submit, "OpenAI background submit body was not valid JSON");
208
+ const id = submitEnvelope.id;
209
+ if (!id) {
210
+ throw new TransientLlmError({
211
+ message: "OpenAI background submit returned no response id.",
212
+ });
213
+ }
214
+ // Return at submit — including the terminal-on-submit fast-path. Unlike
215
+ // `runBackground`, a `cancelled` submit envelope is NOT thrown here: the
216
+ // submit-only contract returns every terminal status, and the caller's
217
+ // completion step classifies it (a cancelled response settles as a skip).
218
+ return {
219
+ responseId: id,
220
+ status: (submitEnvelope.status ?? "queued"),
221
+ };
222
+ }
223
+ function envelopeToRetrievedResponse(envelope, id) {
224
+ const output = extractAssistantText(envelope.output);
225
+ const usage = extractUsage(envelope);
226
+ const result = {
227
+ status: (envelope.status ?? "in_progress"),
228
+ rawResponseId: envelope.id ?? id,
229
+ };
230
+ if (output !== undefined) {
231
+ result.output = output;
232
+ }
233
+ if (usage.input > 0 || usage.output > 0) {
234
+ result.tokenUsage = usage;
235
+ }
236
+ // Surface the incomplete reason / error message so a completion-side
237
+ // consumer (e.g. `completeStage`) can classify the outcome.
238
+ const incompleteReason = envelope.incomplete_details?.reason;
239
+ if (incompleteReason !== undefined) {
240
+ result.incompleteReason = incompleteReason;
241
+ }
242
+ const errorMessage = envelope.error?.message;
243
+ if (errorMessage !== undefined) {
244
+ result.errorMessage = errorMessage;
245
+ }
246
+ return result;
247
+ }
248
+ //# sourceMappingURL=openai-retrieval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-retrieval.js","sourceRoot":"","sources":["../../../src/extensions/openai/openai-retrieval.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,wEAAwE;AACxE,oEAAoE;AACpE,qEAAqE;AACrE,kCAAkC;AAClC,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,uDAAuD;AAGvD,OAAO,EACH,QAAQ,EACR,eAAe,EACf,yBAAyB,EACzB,YAAY,GACf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACH,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,eAAe,GAClB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,GACpB,MAAM,aAAa,CAAA;AACpB,OAAO,EACH,gBAAgB,GAInB,MAAM,YAAY,CAAA;AAiDnB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAClC,EAAU,EACV,OAKC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAA;IACjE,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC;QACnC,GAAG,EAAE,OAAO,CAAC,OAAO,IAAI,gBAAgB;QACxC,EAAE;QACF,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,SAAS;QACT,MAAM,EAAE,OAAO,CAAC,MAAM;KACzB,CAAC,CAAA;IACF,OAAO,2BAA2B,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AACpD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACjC,EAAU,EACV,OAMC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,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7D,aAAa,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE;KACnC,CAAA;IACD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;IAC1B,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,CAAC,UAAU,GAAG,KAAK,CAAA;IAC7B,CAAC;IACD,qEAAqE;IACrE,4DAA4D;IAC5D,MAAM,gBAAgB,GAAG,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAA;IAC5D,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC9C,CAAC;IACD,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IAC5C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IACtC,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { TSchema } from "typebox";
2
+ import type { TToolSpec } from "../../lib/llm/types.js";
3
+ import type { TOpenAiTool } from "./types.js";
4
+ export declare function translateTools(tools: readonly TToolSpec[]): TOpenAiTool[];
5
+ export declare function findFunctionHandler(tools: readonly TToolSpec[] | undefined, name: string): Extract<TToolSpec, {
6
+ kind: "function";
7
+ }> | undefined;
8
+ export declare function deriveSchemaName(schema: TSchema): string;
9
+ //# sourceMappingURL=openai-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-tools.d.ts","sourceRoot":"","sources":["../../../src/extensions/openai/openai-tools.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAI7C,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,WAAW,EAAE,CAiCzE;AAED,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EACvC,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,GAAG,SAAS,CAQtD;AAID,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAOxD"}
@@ -0,0 +1,93 @@
1
+ // Translation of the framework's `TToolSpec` discriminated union into
2
+ // the OpenAI Responses-API tool wire format, plus the structured-output
3
+ // schema-name derivation (a stable, OpenAI-name-safe identifier for each
4
+ // response schema). These are pure helpers with no captured state.
5
+ import { typeboxToOpenAiSchema } from "./structured-output.js";
6
+ // -- tool translation --
7
+ export function translateTools(tools) {
8
+ return tools.map((tool) => {
9
+ switch (tool.kind) {
10
+ case "web_search":
11
+ return { type: "web_search" };
12
+ case "file_search":
13
+ return {
14
+ type: "file_search",
15
+ vector_store_ids: [tool.vectorStoreId],
16
+ };
17
+ case "mcp": {
18
+ const out = {
19
+ type: "mcp",
20
+ server_url: tool.serverUrl,
21
+ };
22
+ if (tool.toolName) {
23
+ return {
24
+ ...out,
25
+ allowed_tools: [tool.toolName],
26
+ };
27
+ }
28
+ return out;
29
+ }
30
+ case "function":
31
+ return {
32
+ type: "function",
33
+ name: tool.name,
34
+ description: tool.description,
35
+ parameters: typeboxToOpenAiSchema(tool.parameters),
36
+ strict: true,
37
+ };
38
+ }
39
+ });
40
+ }
41
+ export function findFunctionHandler(tools, name) {
42
+ if (!tools)
43
+ return undefined;
44
+ for (const tool of tools) {
45
+ if (tool.kind === "function" && tool.name === name) {
46
+ return tool;
47
+ }
48
+ }
49
+ return undefined;
50
+ }
51
+ // -- schema name derivation --
52
+ export function deriveSchemaName(schema) {
53
+ const id = schema.$id;
54
+ if (typeof id === "string" && id.length > 0) {
55
+ return sanitizeName(id);
56
+ }
57
+ const serialized = canonicalJson(schema);
58
+ return `schema_${shortHash(serialized)}`;
59
+ }
60
+ function sanitizeName(raw) {
61
+ // OpenAI requires schema names match `^[a-zA-Z0-9_-]{1,64}$`.
62
+ const cleaned = raw.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
63
+ return cleaned.length > 0 ? cleaned : "schema";
64
+ }
65
+ function canonicalJson(value) {
66
+ return JSON.stringify(value, (_key, v) => {
67
+ if (v !== null && typeof v === "object" && !Array.isArray(v)) {
68
+ const obj = v;
69
+ const sorted = {};
70
+ for (const key of Object.keys(obj).sort()) {
71
+ sorted[key] = obj[key];
72
+ }
73
+ return sorted;
74
+ }
75
+ return v;
76
+ });
77
+ }
78
+ function shortHash(input) {
79
+ // Stable 12-hex-char hash. We avoid pulling `crypto.subtle` because
80
+ // it's async and would force `deriveSchemaName` to be async too;
81
+ // FNV-1a is sufficient for naming uniqueness within a process.
82
+ let h1 = 0xcbf29ce4;
83
+ let h2 = 0x84222325;
84
+ for (let i = 0; i < input.length; i += 1) {
85
+ const c = input.charCodeAt(i);
86
+ h1 = Math.imul(h1 ^ c, 0x01000193) >>> 0;
87
+ h2 = Math.imul(h2 ^ c, 0x01000193) >>> 0;
88
+ }
89
+ const hex1 = h1.toString(16).padStart(8, "0");
90
+ const hex2 = h2.toString(16).padStart(8, "0");
91
+ return (hex1 + hex2).slice(0, 12);
92
+ }
93
+ //# sourceMappingURL=openai-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-tools.js","sourceRoot":"","sources":["../../../src/extensions/openai/openai-tools.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,wEAAwE;AACxE,yEAAyE;AACzE,mEAAmE;AAInE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAG9D,yBAAyB;AAEzB,MAAM,UAAU,cAAc,CAAC,KAA2B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AAoE;IACpE,iEAAiE;IACjE,+DAA+D;IAC/D,IAAI,EAAE,GAAG,UAAU,CAAA;IACnB,IAAI,EAAE,GAAG,UAAU,CAAA;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAC7B,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;QACxC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC7C,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC7C,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AACrC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { TLlmProvider } from "../../lib/llm/types.js";
2
- import type { TOpenAiFetch } from "./types.js";
2
+ import { type TOpenAiFetch } from "./types.js";
3
3
  export type TCreateOpenAiResponsesProviderOptions = {
4
4
  apiKey: string;
5
5
  /** Override the default `https://api.openai.com/v1/responses`. */
@@ -64,103 +64,4 @@ export type TCreateOpenAiResponsesProviderOptions = {
64
64
  backgroundPollIntervalMs?: number;
65
65
  };
66
66
  export declare function createOpenAiResponsesProvider(options: TCreateOpenAiResponsesProviderOptions): TLlmProvider;
67
- /**
68
- * The status values the OpenAI Responses API reports for a stored
69
- * response. `completed` / `failed` / `incomplete` / `cancelled` are
70
- * terminal; `queued` / `in_progress` are transient.
71
- */
72
- export type TResponseStatus = "queued" | "in_progress" | "completed" | "failed" | "incomplete" | "cancelled";
73
- /**
74
- * The structured result of a `retrieveResponse` call. All fields
75
- * except `status` and `rawResponseId` are absent for non-terminal
76
- * or failed responses.
77
- */
78
- export type TRetrievedResponse = {
79
- /** Current status of the stored response. */
80
- status: TResponseStatus;
81
- /**
82
- * Parsed text output, present when `status === "completed"` and
83
- * the response carried a `message` output item.
84
- */
85
- output?: string;
86
- /** Token usage reported by OpenAI, when available. */
87
- tokenUsage?: import("../../lib/llm/types.js").TLlmTokenUsage;
88
- /** The OpenAI response id that was retrieved. */
89
- rawResponseId: string;
90
- };
91
- /**
92
- * Retrieve a stored OpenAI response by id. Surfaces the current
93
- * status, output text (when completed), and token usage.
94
- *
95
- * Throws {@link ResponseNotFoundError} when the response is not found
96
- * (HTTP 404), which typically means the ~10-minute retention window
97
- * has elapsed. Callers should clear the stored id, settle the
98
- * associated stage as failed, and surface a retry prompt.
99
- *
100
- * @param id - The OpenAI response id to retrieve.
101
- * @param options - Provider configuration (apiKey, optional baseUrl and fetch).
102
- */
103
- export declare function retrieveResponse(id: string, options: {
104
- apiKey: string;
105
- baseUrl?: string;
106
- fetch?: TOpenAiFetch;
107
- signal?: AbortSignal;
108
- }): Promise<TRetrievedResponse>;
109
- /**
110
- * Reconnect to a stored, still-generating background response and
111
- * **stream it to completion**. This is what actually drives a dropped
112
- * background response forward: a passive `retrieveResponse` GET only
113
- * reads the current state and leaves a `queued` / `in_progress`
114
- * response sitting where it is, whereas reconnecting with `stream=true`
115
- * resumes consumption so the response reaches a terminal status.
116
- *
117
- * Issues `GET /responses/{id}?stream=true&starting_after=<cursor>` and
118
- * consumes the SSE stream to its terminal event, returning the same
119
- * {@link TRetrievedResponse} shape as {@link retrieveResponse}.
120
- *
121
- * Throws {@link ResponseNotFoundError} when the response is not found
122
- * (HTTP 404 — typically the ~10-minute retention window elapsed).
123
- * Honors `signal`: an abort propagates as an `AbortError` from the
124
- * underlying stream read.
125
- *
126
- * @param id - The OpenAI response id to reconnect to.
127
- * @param options - `apiKey`, optional `startingAfter` SSE cursor
128
- * (defaults to 0 — replay from the start of the stored stream),
129
- * optional `baseUrl`, `fetch`, and `signal`.
130
- */
131
- export declare function reconnectStream(id: string, options: {
132
- apiKey: string;
133
- startingAfter?: number;
134
- baseUrl?: string;
135
- fetch?: TOpenAiFetch;
136
- signal?: AbortSignal;
137
- }): Promise<TRetrievedResponse>;
138
- /**
139
- * Cancel a stored, in-flight OpenAI response. Issues
140
- * `POST /responses/{id}/cancel` and returns the resulting
141
- * {@link TRetrievedResponse} (typically `status: "cancelled"`).
142
- *
143
- * Cancel is **idempotent** per the Responses API: cancelling twice, or
144
- * cancelling an already-terminal response, simply returns the final
145
- * `Response` object rather than erroring — so callers do not need to
146
- * guard against double-cancel.
147
- *
148
- * Throws {@link ResponseNotFoundError} when the response is not found
149
- * (HTTP 404 — typically the ~10-minute retention window elapsed).
150
- * Honors `signal` (an abort propagates as an `AbortError`).
151
- *
152
- * Use this to stop an in-flight background response when a stage is
153
- * abandoned (resync timeout) or an import is cancelled, so generation
154
- * does not keep running (and billing) server-side after the consumer
155
- * has given up on it.
156
- *
157
- * @param id - The OpenAI response id to cancel.
158
- * @param options - `apiKey`, optional `baseUrl`, `fetch`, and `signal`.
159
- */
160
- export declare function cancelResponse(id: string, options: {
161
- apiKey: string;
162
- baseUrl?: string;
163
- fetch?: TOpenAiFetch;
164
- signal?: AbortSignal;
165
- }): Promise<TRetrievedResponse>;
166
67
  //# sourceMappingURL=provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/extensions/openai/provider.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EACR,YAAY,EAKf,MAAM,wBAAwB,CAAA;AAgB/B,OAAO,KAAK,EACR,YAAY,EAMf,MAAM,YAAY,CAAA;AAOnB,MAAM,MAAM,qCAAqC,GA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M,EACV,OAAO,EAAE;IACL,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,WAAW,CAAA;CACvB,GACF,OAAO,CAAC,kBAAkB,CAAC,CAmC7B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,cAAc,CAChC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE;IACL,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,WAAW,CAAA;CACvB,GACF,OAAO,CAAC,kBAAkB,CAAC,CAoC7B"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/extensions/openai/provider.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EACR,YAAY,EAIf,MAAM,wBAAwB,CAAA;AAmB/B,OAAO,EAEH,KAAK,YAAY,EAGpB,MAAM,YAAY,CAAA;AAYnB,MAAM,MAAM,qCAAqC,GAAG;IAChD,MAAM,EAAE,MAAM,CAAA;IACd,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;;;;;;;;;;;;;;OAiBG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CACpC,CAAA;AAED,wBAAgB,6BAA6B,CACzC,OAAO,EAAE,qCAAqC,GAC/C,YAAY,CA8Td"}