@dreb/ai 2.64.1 → 2.64.3

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.
@@ -0,0 +1,25 @@
1
+ import type { Api, Model, StreamOptions } from "../types.js";
2
+ /**
3
+ * HTTP header OpenCode uses for per-conversation routing and optimization.
4
+ * Must be a stable identifier for the lifetime of one conversation (issue 500).
5
+ */
6
+ export declare const OPENCODE_SESSION_HEADER = "x-opencode-session";
7
+ /**
8
+ * Returns true when the model points at an OpenCode endpoint: either one of the
9
+ * built-in OpenCode providers, or a custom provider whose base URL parses to
10
+ * exactly the `opencode.ai` hostname. Hostname equality is exact (case-insensitive,
11
+ * no substring matching) so lookalike domains never receive session IDs.
12
+ */
13
+ export declare function isOpenCodeModel(model: Pick<Model<Api>, "provider" | "baseUrl">): boolean;
14
+ /**
15
+ * Returns options with `x-opencode-session` added for OpenCode models when a
16
+ * session ID is present. The input is never mutated; a new options object is
17
+ * returned when the header is added.
18
+ *
19
+ * Precedence: an explicit header in `model.headers` or `options.headers` wins
20
+ * case-insensitively, so no differently-cased duplicate of the generated header
21
+ * can be sent. OpenCode models without a session ID, missing options, and
22
+ * non-OpenCode models are returned unchanged.
23
+ */
24
+ export declare function withOpenCodeSessionHeader<TOptions extends StreamOptions | undefined>(model: Pick<Model<Api>, "provider" | "baseUrl" | "headers">, options: TOptions): TOptions;
25
+ //# sourceMappingURL=opencode-headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencode-headers.d.ts","sourceRoot":"","sources":["../../src/providers/opencode-headers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAK5D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,GAAG,OAAO,CASxF;AAQD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,SAAS,aAAa,GAAG,SAAS,EACnF,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC,EAC3D,OAAO,EAAE,QAAQ,GACf,QAAQ,CAYV","sourcesContent":["import type { Api, Model, StreamOptions } from \"../types.js\";\n\n/**\n * HTTP header OpenCode uses for per-conversation routing and optimization.\n * Must be a stable identifier for the lifetime of one conversation (issue 500).\n */\nexport const OPENCODE_SESSION_HEADER = \"x-opencode-session\";\n\n/** Provider IDs of the built-in OpenCode endpoints. */\nconst OPENCODE_PROVIDER_IDS = new Set([\"opencode\", \"opencode-go\"]);\n\n/**\n * Returns true when the model points at an OpenCode endpoint: either one of the\n * built-in OpenCode providers, or a custom provider whose base URL parses to\n * exactly the `opencode.ai` hostname. Hostname equality is exact (case-insensitive,\n * no substring matching) so lookalike domains never receive session IDs.\n */\nexport function isOpenCodeModel(model: Pick<Model<Api>, \"provider\" | \"baseUrl\">): boolean {\n\tif (OPENCODE_PROVIDER_IDS.has(model.provider)) {\n\t\treturn true;\n\t}\n\ttry {\n\t\treturn new URL(model.baseUrl).hostname.toLowerCase() === \"opencode.ai\";\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction hasHeader(headers: Record<string, string> | undefined, name: string): boolean {\n\tif (!headers) return false;\n\tconst wanted = name.toLowerCase();\n\treturn Object.keys(headers).some((key) => key.toLowerCase() === wanted);\n}\n\n/**\n * Returns options with `x-opencode-session` added for OpenCode models when a\n * session ID is present. The input is never mutated; a new options object is\n * returned when the header is added.\n *\n * Precedence: an explicit header in `model.headers` or `options.headers` wins\n * case-insensitively, so no differently-cased duplicate of the generated header\n * can be sent. OpenCode models without a session ID, missing options, and\n * non-OpenCode models are returned unchanged.\n */\nexport function withOpenCodeSessionHeader<TOptions extends StreamOptions | undefined>(\n\tmodel: Pick<Model<Api>, \"provider\" | \"baseUrl\" | \"headers\">,\n\toptions: TOptions,\n): TOptions {\n\tif (!options) return options;\n\tconst sessionId = options.sessionId;\n\tif (!sessionId) return options;\n\tif (!isOpenCodeModel(model)) return options;\n\tif (hasHeader(model.headers, OPENCODE_SESSION_HEADER) || hasHeader(options.headers, OPENCODE_SESSION_HEADER)) {\n\t\treturn options;\n\t}\n\treturn {\n\t\t...options,\n\t\theaders: { ...options.headers, [OPENCODE_SESSION_HEADER]: sessionId },\n\t} as TOptions;\n}\n"]}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * HTTP header OpenCode uses for per-conversation routing and optimization.
3
+ * Must be a stable identifier for the lifetime of one conversation (issue 500).
4
+ */
5
+ export const OPENCODE_SESSION_HEADER = "x-opencode-session";
6
+ /** Provider IDs of the built-in OpenCode endpoints. */
7
+ const OPENCODE_PROVIDER_IDS = new Set(["opencode", "opencode-go"]);
8
+ /**
9
+ * Returns true when the model points at an OpenCode endpoint: either one of the
10
+ * built-in OpenCode providers, or a custom provider whose base URL parses to
11
+ * exactly the `opencode.ai` hostname. Hostname equality is exact (case-insensitive,
12
+ * no substring matching) so lookalike domains never receive session IDs.
13
+ */
14
+ export function isOpenCodeModel(model) {
15
+ if (OPENCODE_PROVIDER_IDS.has(model.provider)) {
16
+ return true;
17
+ }
18
+ try {
19
+ return new URL(model.baseUrl).hostname.toLowerCase() === "opencode.ai";
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ function hasHeader(headers, name) {
26
+ if (!headers)
27
+ return false;
28
+ const wanted = name.toLowerCase();
29
+ return Object.keys(headers).some((key) => key.toLowerCase() === wanted);
30
+ }
31
+ /**
32
+ * Returns options with `x-opencode-session` added for OpenCode models when a
33
+ * session ID is present. The input is never mutated; a new options object is
34
+ * returned when the header is added.
35
+ *
36
+ * Precedence: an explicit header in `model.headers` or `options.headers` wins
37
+ * case-insensitively, so no differently-cased duplicate of the generated header
38
+ * can be sent. OpenCode models without a session ID, missing options, and
39
+ * non-OpenCode models are returned unchanged.
40
+ */
41
+ export function withOpenCodeSessionHeader(model, options) {
42
+ if (!options)
43
+ return options;
44
+ const sessionId = options.sessionId;
45
+ if (!sessionId)
46
+ return options;
47
+ if (!isOpenCodeModel(model))
48
+ return options;
49
+ if (hasHeader(model.headers, OPENCODE_SESSION_HEADER) || hasHeader(options.headers, OPENCODE_SESSION_HEADER)) {
50
+ return options;
51
+ }
52
+ return {
53
+ ...options,
54
+ headers: { ...options.headers, [OPENCODE_SESSION_HEADER]: sessionId },
55
+ };
56
+ }
57
+ //# sourceMappingURL=opencode-headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencode-headers.js","sourceRoot":"","sources":["../../src/providers/opencode-headers.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAE5D,uDAAuD;AACvD,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAA+C,EAAW;IACzF,IAAI,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,aAAa,CAAC;IACxE,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AAAA,CACD;AAED,SAAS,SAAS,CAAC,OAA2C,EAAE,IAAY,EAAW;IACtF,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAClC,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CAAC;AAAA,CACxE;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CACxC,KAA2D,EAC3D,OAAiB,EACN;IACX,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAC7B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACpC,IAAI,CAAC,SAAS;QAAE,OAAO,OAAO,CAAC;IAC/B,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAC5C,IAAI,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,uBAAuB,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,uBAAuB,CAAC,EAAE,CAAC;QAC9G,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,OAAO;QACN,GAAG,OAAO;QACV,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,uBAAuB,CAAC,EAAE,SAAS,EAAE;KACzD,CAAC;AAAA,CACd","sourcesContent":["import type { Api, Model, StreamOptions } from \"../types.js\";\n\n/**\n * HTTP header OpenCode uses for per-conversation routing and optimization.\n * Must be a stable identifier for the lifetime of one conversation (issue 500).\n */\nexport const OPENCODE_SESSION_HEADER = \"x-opencode-session\";\n\n/** Provider IDs of the built-in OpenCode endpoints. */\nconst OPENCODE_PROVIDER_IDS = new Set([\"opencode\", \"opencode-go\"]);\n\n/**\n * Returns true when the model points at an OpenCode endpoint: either one of the\n * built-in OpenCode providers, or a custom provider whose base URL parses to\n * exactly the `opencode.ai` hostname. Hostname equality is exact (case-insensitive,\n * no substring matching) so lookalike domains never receive session IDs.\n */\nexport function isOpenCodeModel(model: Pick<Model<Api>, \"provider\" | \"baseUrl\">): boolean {\n\tif (OPENCODE_PROVIDER_IDS.has(model.provider)) {\n\t\treturn true;\n\t}\n\ttry {\n\t\treturn new URL(model.baseUrl).hostname.toLowerCase() === \"opencode.ai\";\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction hasHeader(headers: Record<string, string> | undefined, name: string): boolean {\n\tif (!headers) return false;\n\tconst wanted = name.toLowerCase();\n\treturn Object.keys(headers).some((key) => key.toLowerCase() === wanted);\n}\n\n/**\n * Returns options with `x-opencode-session` added for OpenCode models when a\n * session ID is present. The input is never mutated; a new options object is\n * returned when the header is added.\n *\n * Precedence: an explicit header in `model.headers` or `options.headers` wins\n * case-insensitively, so no differently-cased duplicate of the generated header\n * can be sent. OpenCode models without a session ID, missing options, and\n * non-OpenCode models are returned unchanged.\n */\nexport function withOpenCodeSessionHeader<TOptions extends StreamOptions | undefined>(\n\tmodel: Pick<Model<Api>, \"provider\" | \"baseUrl\" | \"headers\">,\n\toptions: TOptions,\n): TOptions {\n\tif (!options) return options;\n\tconst sessionId = options.sessionId;\n\tif (!sessionId) return options;\n\tif (!isOpenCodeModel(model)) return options;\n\tif (hasHeader(model.headers, OPENCODE_SESSION_HEADER) || hasHeader(options.headers, OPENCODE_SESSION_HEADER)) {\n\t\treturn options;\n\t}\n\treturn {\n\t\t...options,\n\t\theaders: { ...options.headers, [OPENCODE_SESSION_HEADER]: sessionId },\n\t} as TOptions;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAG1C,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,2BAA2B,EAC3B,OAAO,EACP,KAAK,EACL,qBAAqB,EACrB,mBAAmB,EAEnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUjD,wBAAgB,MAAM,CAAC,IAAI,SAAS,GAAG,EACtC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,2BAA2B,CAG7B;AAED,wBAAsB,QAAQ,CAAC,IAAI,SAAS,GAAG,EAC9C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CAG3B;AAED,wBAAgB,YAAY,CAAC,IAAI,SAAS,GAAG,EAC5C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,2BAA2B,CAG7B;AAED,wBAAsB,cAAc,CAAC,IAAI,SAAS,GAAG,EACpD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAG3B","sourcesContent":["import \"./providers/register-builtins.js\";\n\nimport { getApiProvider } from \"./api-registry.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tProviderStreamOptions,\n\tSimpleStreamOptions,\n\tStreamOptions,\n} from \"./types.js\";\n\nexport { getEnvApiKey } from \"./env-api-keys.js\";\n\nfunction resolveApiProvider(api: Api) {\n\tconst provider = getApiProvider(api);\n\tif (!provider) {\n\t\tthrow new Error(`No API provider registered for api: ${api}`);\n\t}\n\treturn provider;\n}\n\nexport function stream<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): AssistantMessageEventStream {\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.stream(model, context, options as StreamOptions);\n}\n\nexport async function complete<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = stream(model, context, options);\n\treturn s.result();\n}\n\nexport function streamSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.streamSimple(model, context, options);\n}\n\nexport async function completeSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = streamSimple(model, context, options);\n\treturn s.result();\n}\n"]}
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAI1C,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,2BAA2B,EAC3B,OAAO,EACP,KAAK,EACL,qBAAqB,EACrB,mBAAmB,EAEnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUjD,wBAAgB,MAAM,CAAC,IAAI,SAAS,GAAG,EACtC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,2BAA2B,CAG7B;AAED,wBAAsB,QAAQ,CAAC,IAAI,SAAS,GAAG,EAC9C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CAG3B;AAED,wBAAgB,YAAY,CAAC,IAAI,SAAS,GAAG,EAC5C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,2BAA2B,CAG7B;AAED,wBAAsB,cAAc,CAAC,IAAI,SAAS,GAAG,EACpD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAG3B","sourcesContent":["import \"./providers/register-builtins.js\";\n\nimport { getApiProvider } from \"./api-registry.js\";\nimport { withOpenCodeSessionHeader } from \"./providers/opencode-headers.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tProviderStreamOptions,\n\tSimpleStreamOptions,\n\tStreamOptions,\n} from \"./types.js\";\n\nexport { getEnvApiKey } from \"./env-api-keys.js\";\n\nfunction resolveApiProvider(api: Api) {\n\tconst provider = getApiProvider(api);\n\tif (!provider) {\n\t\tthrow new Error(`No API provider registered for api: ${api}`);\n\t}\n\treturn provider;\n}\n\nexport function stream<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): AssistantMessageEventStream {\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.stream(model, context, withOpenCodeSessionHeader(model, options) as StreamOptions);\n}\n\nexport async function complete<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = stream(model, context, options);\n\treturn s.result();\n}\n\nexport function streamSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.streamSimple(model, context, withOpenCodeSessionHeader(model, options));\n}\n\nexport async function completeSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = streamSimple(model, context, options);\n\treturn s.result();\n}\n"]}
package/dist/stream.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./providers/register-builtins.js";
2
2
  import { getApiProvider } from "./api-registry.js";
3
+ import { withOpenCodeSessionHeader } from "./providers/opencode-headers.js";
3
4
  export { getEnvApiKey } from "./env-api-keys.js";
4
5
  function resolveApiProvider(api) {
5
6
  const provider = getApiProvider(api);
@@ -10,7 +11,7 @@ function resolveApiProvider(api) {
10
11
  }
11
12
  export function stream(model, context, options) {
12
13
  const provider = resolveApiProvider(model.api);
13
- return provider.stream(model, context, options);
14
+ return provider.stream(model, context, withOpenCodeSessionHeader(model, options));
14
15
  }
15
16
  export async function complete(model, context, options) {
16
17
  const s = stream(model, context, options);
@@ -18,7 +19,7 @@ export async function complete(model, context, options) {
18
19
  }
19
20
  export function streamSimple(model, context, options) {
20
21
  const provider = resolveApiProvider(model.api);
21
- return provider.streamSimple(model, context, options);
22
+ return provider.streamSimple(model, context, withOpenCodeSessionHeader(model, options));
22
23
  }
23
24
  export async function completeSimple(model, context, options) {
24
25
  const s = streamSimple(model, context, options);
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAYnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,SAAS,kBAAkB,CAAC,GAAQ,EAAE;IACrC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,GAAG,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,QAAQ,CAAC;AAAA,CAChB;AAED,MAAM,UAAU,MAAM,CACrB,KAAkB,EAClB,OAAgB,EAChB,OAA+B,EACD;IAC9B,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAwB,CAAC,CAAC;AAAA,CACjE;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,KAAkB,EAClB,OAAgB,EAChB,OAA+B,EACH;IAC5B,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1C,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;AAAA,CAClB;AAED,MAAM,UAAU,YAAY,CAC3B,KAAkB,EAClB,OAAgB,EAChB,OAA6B,EACC;IAC9B,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAAA,CACtD;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,KAAkB,EAClB,OAAgB,EAChB,OAA6B,EACD;IAC5B,MAAM,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;AAAA,CAClB","sourcesContent":["import \"./providers/register-builtins.js\";\n\nimport { getApiProvider } from \"./api-registry.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tProviderStreamOptions,\n\tSimpleStreamOptions,\n\tStreamOptions,\n} from \"./types.js\";\n\nexport { getEnvApiKey } from \"./env-api-keys.js\";\n\nfunction resolveApiProvider(api: Api) {\n\tconst provider = getApiProvider(api);\n\tif (!provider) {\n\t\tthrow new Error(`No API provider registered for api: ${api}`);\n\t}\n\treturn provider;\n}\n\nexport function stream<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): AssistantMessageEventStream {\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.stream(model, context, options as StreamOptions);\n}\n\nexport async function complete<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = stream(model, context, options);\n\treturn s.result();\n}\n\nexport function streamSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.streamSimple(model, context, options);\n}\n\nexport async function completeSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = streamSimple(model, context, options);\n\treturn s.result();\n}\n"]}
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAY5E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,SAAS,kBAAkB,CAAC,GAAQ,EAAE;IACrC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,GAAG,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,QAAQ,CAAC;AAAA,CAChB;AAED,MAAM,UAAU,MAAM,CACrB,KAAkB,EAClB,OAAgB,EAChB,OAA+B,EACD;IAC9B,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAkB,CAAC,CAAC;AAAA,CACnG;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,KAAkB,EAClB,OAAgB,EAChB,OAA+B,EACH;IAC5B,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1C,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;AAAA,CAClB;AAED,MAAM,UAAU,YAAY,CAC3B,KAAkB,EAClB,OAAgB,EAChB,OAA6B,EACC;IAC9B,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACxF;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,KAAkB,EAClB,OAAgB,EAChB,OAA6B,EACD;IAC5B,MAAM,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;AAAA,CAClB","sourcesContent":["import \"./providers/register-builtins.js\";\n\nimport { getApiProvider } from \"./api-registry.js\";\nimport { withOpenCodeSessionHeader } from \"./providers/opencode-headers.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tProviderStreamOptions,\n\tSimpleStreamOptions,\n\tStreamOptions,\n} from \"./types.js\";\n\nexport { getEnvApiKey } from \"./env-api-keys.js\";\n\nfunction resolveApiProvider(api: Api) {\n\tconst provider = getApiProvider(api);\n\tif (!provider) {\n\t\tthrow new Error(`No API provider registered for api: ${api}`);\n\t}\n\treturn provider;\n}\n\nexport function stream<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): AssistantMessageEventStream {\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.stream(model, context, withOpenCodeSessionHeader(model, options) as StreamOptions);\n}\n\nexport async function complete<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: ProviderStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = stream(model, context, options);\n\treturn s.result();\n}\n\nexport function streamSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst provider = resolveApiProvider(model.api);\n\treturn provider.streamSimple(model, context, withOpenCodeSessionHeader(model, options));\n}\n\nexport async function completeSimple<TApi extends Api>(\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): Promise<AssistantMessage> {\n\tconst s = streamSimple(model, context, options);\n\treturn s.result();\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreb/ai",
3
- "version": "2.64.1",
3
+ "version": "2.64.3",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",