@odla-ai/ai 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -35,7 +35,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
35
35
  ));
36
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
37
 
38
- // src/shape/index.ts
38
+ // src/shape/blocks.ts
39
+ var init_blocks = __esm({
40
+ "src/shape/blocks.ts"() {
41
+ "use strict";
42
+ }
43
+ });
44
+
45
+ // src/shape/usage.ts
39
46
  function emptyUsage() {
40
47
  return { inputTokens: 0, outputTokens: 0 };
41
48
  }
@@ -49,39 +56,30 @@ function addUsage(into, more) {
49
56
  into.cacheReadTokens = (into.cacheReadTokens ?? 0) + more.cacheReadTokens;
50
57
  }
51
58
  }
52
- function isTextBlock(b) {
53
- return b.type === "text";
54
- }
55
- function isImageBlock(b) {
56
- return b.type === "image";
57
- }
58
- function isAudioBlock(b) {
59
- return b.type === "audio";
60
- }
61
- function isDocumentBlock(b) {
62
- return b.type === "document";
63
- }
64
- function isToolUseBlock(b) {
65
- return b.type === "tool_use";
66
- }
67
- function isToolResultBlock(b) {
68
- return b.type === "tool_result";
69
- }
70
- function isThinkingBlock(b) {
71
- return b.type === "thinking";
72
- }
73
- function blocksOf(content) {
74
- return typeof content === "string" ? [{ type: "text", text: content }] : content;
75
- }
76
- function extractText(content) {
77
- return content.filter(isTextBlock).map((b) => b.text).join("");
78
- }
79
- function extractToolUses(content) {
80
- return content.filter(isToolUseBlock);
81
- }
59
+ var init_usage = __esm({
60
+ "src/shape/usage.ts"() {
61
+ "use strict";
62
+ }
63
+ });
64
+
65
+ // src/shape/request.ts
66
+ var init_request = __esm({
67
+ "src/shape/request.ts"() {
68
+ "use strict";
69
+ }
70
+ });
71
+
72
+ // src/shape/events.ts
73
+ var init_events = __esm({
74
+ "src/shape/events.ts"() {
75
+ "use strict";
76
+ }
77
+ });
78
+
79
+ // src/shape/errors.ts
82
80
  var OdlaAIError, ConfigError, AuthError, RateLimitError, CapabilityError, ContextWindowError, InvalidRequestError, ProviderError;
83
- var init_shape = __esm({
84
- "src/shape/index.ts"() {
81
+ var init_errors = __esm({
82
+ "src/shape/errors.ts"() {
85
83
  "use strict";
86
84
  OdlaAIError = class extends Error {
87
85
  code;
@@ -141,6 +139,56 @@ var init_shape = __esm({
141
139
  }
142
140
  });
143
141
 
142
+ // src/shape/helpers.ts
143
+ function isTextBlock(b) {
144
+ return b.type === "text";
145
+ }
146
+ function isImageBlock(b) {
147
+ return b.type === "image";
148
+ }
149
+ function isAudioBlock(b) {
150
+ return b.type === "audio";
151
+ }
152
+ function isDocumentBlock(b) {
153
+ return b.type === "document";
154
+ }
155
+ function isToolUseBlock(b) {
156
+ return b.type === "tool_use";
157
+ }
158
+ function isToolResultBlock(b) {
159
+ return b.type === "tool_result";
160
+ }
161
+ function isThinkingBlock(b) {
162
+ return b.type === "thinking";
163
+ }
164
+ function blocksOf(content) {
165
+ return typeof content === "string" ? [{ type: "text", text: content }] : content;
166
+ }
167
+ function extractText(content) {
168
+ return content.filter(isTextBlock).map((b) => b.text).join("");
169
+ }
170
+ function extractToolUses(content) {
171
+ return content.filter(isToolUseBlock);
172
+ }
173
+ var init_helpers = __esm({
174
+ "src/shape/helpers.ts"() {
175
+ "use strict";
176
+ }
177
+ });
178
+
179
+ // src/shape/index.ts
180
+ var init_shape = __esm({
181
+ "src/shape/index.ts"() {
182
+ "use strict";
183
+ init_blocks();
184
+ init_usage();
185
+ init_request();
186
+ init_events();
187
+ init_errors();
188
+ init_helpers();
189
+ }
190
+ });
191
+
144
192
  // src/providers/errors.ts
145
193
  function statusOf(err) {
146
194
  if (err && typeof err === "object") {
@@ -188,18 +236,14 @@ function normalizeError(err, provider) {
188
236
  function mapProviderError(err, provider) {
189
237
  throw normalizeError(err, provider);
190
238
  }
191
- var init_errors = __esm({
239
+ var init_errors2 = __esm({
192
240
  "src/providers/errors.ts"() {
193
241
  "use strict";
194
242
  init_shape();
195
243
  }
196
244
  });
197
245
 
198
- // src/providers/anthropic.ts
199
- var anthropic_exports = {};
200
- __export(anthropic_exports, {
201
- AnthropicProvider: () => AnthropicProvider
202
- });
246
+ // src/providers/anthropic/request.ts
203
247
  function buildParams(spec, req, messages) {
204
248
  const params = {
205
249
  model: spec.nativeId,
@@ -287,6 +331,13 @@ function mapToolChoice(tc) {
287
331
  if (tc === "none") return { type: "none" };
288
332
  return { type: "tool", name: tc.name };
289
333
  }
334
+ var init_request2 = __esm({
335
+ "src/providers/anthropic/request.ts"() {
336
+ "use strict";
337
+ }
338
+ });
339
+
340
+ // src/providers/anthropic/response.ts
290
341
  function mapContent(blocks) {
291
342
  const out = [];
292
343
  for (const b of blocks) {
@@ -318,6 +369,13 @@ function mapStop(reason) {
318
369
  return "end_turn";
319
370
  }
320
371
  }
372
+ var init_response = __esm({
373
+ "src/providers/anthropic/response.ts"() {
374
+ "use strict";
375
+ }
376
+ });
377
+
378
+ // src/providers/anthropic/stream.ts
321
379
  function mapStreamEvent(raw, req) {
322
380
  switch (raw.type) {
323
381
  case "message_start":
@@ -359,13 +417,28 @@ function mapStartBlock(cb) {
359
417
  if (cb.type === "thinking") return { type: "thinking", thinking: cb.thinking, signature: cb.signature };
360
418
  return void 0;
361
419
  }
420
+ var init_stream = __esm({
421
+ "src/providers/anthropic/stream.ts"() {
422
+ "use strict";
423
+ init_response();
424
+ }
425
+ });
426
+
427
+ // src/providers/anthropic.ts
428
+ var anthropic_exports = {};
429
+ __export(anthropic_exports, {
430
+ AnthropicProvider: () => AnthropicProvider
431
+ });
362
432
  var import_sdk, AnthropicProvider;
363
433
  var init_anthropic = __esm({
364
434
  "src/providers/anthropic.ts"() {
365
435
  "use strict";
366
436
  import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
367
- init_errors();
437
+ init_errors2();
368
438
  init_shape();
439
+ init_request2();
440
+ init_response();
441
+ init_stream();
369
442
  AnthropicProvider = class {
370
443
  id = "anthropic";
371
444
  client;
@@ -416,14 +489,17 @@ var init_anthropic = __esm({
416
489
  }
417
490
  });
418
491
 
419
- // src/providers/openai.ts
420
- var openai_exports = {};
421
- __export(openai_exports, {
422
- OpenAIProvider: () => OpenAIProvider,
423
- mapResponse: () => mapResponse,
424
- parseArgs: () => parseArgs,
425
- toOpenAIMessages: () => toOpenAIMessages
492
+ // src/providers/blocks.ts
493
+ function stringifyBlocks(blocks) {
494
+ return blocks.map((b) => b.type === "text" ? b.text : `[${b.type}]`).join("");
495
+ }
496
+ var init_blocks2 = __esm({
497
+ "src/providers/blocks.ts"() {
498
+ "use strict";
499
+ }
426
500
  });
501
+
502
+ // src/providers/openai/request.ts
427
503
  function buildParams2(spec, req, stream) {
428
504
  const params = {
429
505
  model: spec.nativeId,
@@ -520,9 +596,6 @@ function audioFormat(m) {
520
596
  if (m === "audio/mp3" || m === "audio/mpeg") return "mp3";
521
597
  throw new CapabilityError(`OpenAI audio input supports wav and mp3, not "${m}".`);
522
598
  }
523
- function stringifyBlocks(blocks) {
524
- return blocks.map((b) => b.type === "text" ? b.text : `[${b.type}]`).join("");
525
- }
526
599
  function buildTools2(req) {
527
600
  if (!req.tools || req.tools.length === 0) return void 0;
528
601
  return req.tools.map((t) => ({
@@ -542,6 +615,15 @@ function reasoningEffort(e) {
542
615
  if (e === "medium") return "medium";
543
616
  return "high";
544
617
  }
618
+ var init_request3 = __esm({
619
+ "src/providers/openai/request.ts"() {
620
+ "use strict";
621
+ init_shape();
622
+ init_blocks2();
623
+ }
624
+ });
625
+
626
+ // src/providers/openai/response.ts
545
627
  function mapResponse(res, req) {
546
628
  const choice = res.choices[0];
547
629
  const content = [];
@@ -591,6 +673,13 @@ function mapUsage2(u) {
591
673
  if (cached != null) usage.cacheReadTokens = cached;
592
674
  return usage;
593
675
  }
676
+ var init_response2 = __esm({
677
+ "src/providers/openai/response.ts"() {
678
+ "use strict";
679
+ }
680
+ });
681
+
682
+ // src/providers/openai/stream.ts
594
683
  async function* mapStream(stream, req) {
595
684
  let started = false;
596
685
  let textOpen = false;
@@ -638,13 +727,31 @@ async function* mapStream(stream, req) {
638
727
  yield { type: "message_delta", delta: { stopReason }, usage };
639
728
  yield { type: "message_stop" };
640
729
  }
730
+ var init_stream2 = __esm({
731
+ "src/providers/openai/stream.ts"() {
732
+ "use strict";
733
+ init_shape();
734
+ init_response2();
735
+ }
736
+ });
737
+
738
+ // src/providers/openai.ts
739
+ var openai_exports = {};
740
+ __export(openai_exports, {
741
+ OpenAIProvider: () => OpenAIProvider,
742
+ mapResponse: () => mapResponse,
743
+ parseArgs: () => parseArgs,
744
+ toOpenAIMessages: () => toOpenAIMessages
745
+ });
641
746
  var import_openai2, OpenAIProvider;
642
747
  var init_openai = __esm({
643
748
  "src/providers/openai.ts"() {
644
749
  "use strict";
645
750
  import_openai2 = __toESM(require("openai"), 1);
646
- init_errors();
647
- init_shape();
751
+ init_errors2();
752
+ init_request3();
753
+ init_response2();
754
+ init_stream2();
648
755
  OpenAIProvider = class {
649
756
  id = "openai";
650
757
  client;
@@ -675,13 +782,7 @@ var init_openai = __esm({
675
782
  }
676
783
  });
677
784
 
678
- // src/providers/google.ts
679
- var google_exports = {};
680
- __export(google_exports, {
681
- GoogleProvider: () => GoogleProvider,
682
- mapResponse: () => mapResponse2,
683
- toContents: () => toContents
684
- });
785
+ // src/providers/google/request.ts
685
786
  function buildParams3(spec, req) {
686
787
  const config = { maxOutputTokens: req.maxTokens };
687
788
  if (req.system !== void 0) {
@@ -729,16 +830,13 @@ function toPart(b) {
729
830
  functionResponse: {
730
831
  // Gemini correlates by name; the canonical tool_use id is keyed to it.
731
832
  name: b.toolUseId,
732
- response: { result: typeof b.content === "string" ? b.content : stringifyBlocks2(b.content) }
833
+ response: { result: typeof b.content === "string" ? b.content : stringifyBlocks(b.content) }
733
834
  }
734
835
  };
735
836
  case "thinking":
736
837
  return { text: "" };
737
838
  }
738
839
  }
739
- function stringifyBlocks2(blocks) {
740
- return blocks.map((b) => b.type === "text" ? b.text : `[${b.type}]`).join("");
741
- }
742
840
  function buildTools3(req) {
743
841
  const tools = [];
744
842
  if (req.tools && req.tools.length > 0) {
@@ -759,6 +857,17 @@ function mapToolChoice3(tc) {
759
857
  if (tc === "any") return { functionCallingConfig: { mode: import_genai.FunctionCallingConfigMode.ANY } };
760
858
  return { functionCallingConfig: { mode: import_genai.FunctionCallingConfigMode.ANY, allowedFunctionNames: [tc.name] } };
761
859
  }
860
+ var import_genai;
861
+ var init_request4 = __esm({
862
+ "src/providers/google/request.ts"() {
863
+ "use strict";
864
+ import_genai = require("@google/genai");
865
+ init_shape();
866
+ init_blocks2();
867
+ }
868
+ });
869
+
870
+ // src/providers/google/response.ts
762
871
  function mapResponse2(res, req) {
763
872
  const candidate = res.candidates?.[0];
764
873
  const parts = candidate?.content?.parts ?? [];
@@ -807,6 +916,13 @@ function mapUsage3(res) {
807
916
  if (u?.cachedContentTokenCount != null) usage.cacheReadTokens = u.cachedContentTokenCount;
808
917
  return usage;
809
918
  }
919
+ var init_response3 = __esm({
920
+ "src/providers/google/response.ts"() {
921
+ "use strict";
922
+ }
923
+ });
924
+
925
+ // src/providers/google/stream.ts
810
926
  async function* mapStream2(iter, req) {
811
927
  let started = false;
812
928
  let textOpen = false;
@@ -850,18 +966,35 @@ async function* mapStream2(iter, req) {
850
966
  yield { type: "message_delta", delta: { stopReason }, usage };
851
967
  yield { type: "message_stop" };
852
968
  }
853
- var import_genai, GoogleProvider;
969
+ var init_stream3 = __esm({
970
+ "src/providers/google/stream.ts"() {
971
+ "use strict";
972
+ init_shape();
973
+ init_response3();
974
+ }
975
+ });
976
+
977
+ // src/providers/google.ts
978
+ var google_exports = {};
979
+ __export(google_exports, {
980
+ GoogleProvider: () => GoogleProvider,
981
+ mapResponse: () => mapResponse2,
982
+ toContents: () => toContents
983
+ });
984
+ var import_genai2, GoogleProvider;
854
985
  var init_google = __esm({
855
986
  "src/providers/google.ts"() {
856
987
  "use strict";
857
- import_genai = require("@google/genai");
858
- init_errors();
859
- init_shape();
988
+ import_genai2 = require("@google/genai");
989
+ init_errors2();
990
+ init_request4();
991
+ init_response3();
992
+ init_stream3();
860
993
  GoogleProvider = class {
861
994
  id = "google";
862
995
  client;
863
996
  constructor(apiKey, client) {
864
- this.client = client ?? new import_genai.GoogleGenAI({ apiKey });
997
+ this.client = client ?? new import_genai2.GoogleGenAI({ apiKey });
865
998
  }
866
999
  async create(spec, req) {
867
1000
  try {
@@ -1328,6 +1461,10 @@ function generateLlmsTxt(catalog = DEFAULT_CATALOG) {
1328
1461
  const models = Object.values(catalog).map((s) => `- \`${s.id}\` (${s.provider}) \u2014 ${capsSummary(s.capabilities)}`).join("\n");
1329
1462
  return `# @odla-ai/ai \u2014 LLM context
1330
1463
 
1464
+ > EXPERIMENTAL \u2014 an agentic-coding experiment. This package is built and operated
1465
+ > by autonomous coding agents as an experiment in agentic loops. APIs change
1466
+ > without notice and nothing here is production-hardened. Use at your own risk.
1467
+
1331
1468
  One general-purpose interface for AI inference across Anthropic (Claude), OpenAI
1332
1469
  (GPT), and Google (Gemini) \u2014 text, image, and audio \u2014 plus a tool-use agent
1333
1470
  engine and an eval harness. Library-only: import in-process, bring your own keys.
@@ -1451,7 +1588,7 @@ via buildCatalog / init({ catalog }).
1451
1588
  }
1452
1589
 
1453
1590
  // src/index.ts
1454
- init_errors();
1591
+ init_errors2();
1455
1592
 
1456
1593
  // src/agent/loop.ts
1457
1594
  init_shape();