@positronic/client-vercel 0.0.37 → 0.0.39

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/src/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
1
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
10
  try {
3
11
  var info = gen[key](arg);
@@ -59,6 +67,44 @@ function _define_property(obj, key, value) {
59
67
  }
60
68
  return obj;
61
69
  }
70
+ function _iterable_to_array_limit(arr, i) {
71
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
72
+ if (_i == null) return;
73
+ var _arr = [];
74
+ var _n = true;
75
+ var _d = false;
76
+ var _s, _e;
77
+ try {
78
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
79
+ _arr.push(_s.value);
80
+ if (i && _arr.length === i) break;
81
+ }
82
+ } catch (err) {
83
+ _d = true;
84
+ _e = err;
85
+ } finally{
86
+ try {
87
+ if (!_n && _i["return"] != null) _i["return"]();
88
+ } finally{
89
+ if (_d) throw _e;
90
+ }
91
+ }
92
+ return _arr;
93
+ }
94
+ function _non_iterable_rest() {
95
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
96
+ }
97
+ function _sliced_to_array(arr, i) {
98
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
99
+ }
100
+ function _unsupported_iterable_to_array(o, minLen) {
101
+ if (!o) return;
102
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
103
+ var n = Object.prototype.toString.call(o).slice(8, -1);
104
+ if (n === "Object" && o.constructor) n = o.constructor.name;
105
+ if (n === "Map" || n === "Set") return Array.from(n);
106
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
107
+ }
62
108
  function _ts_generator(thisArg, body) {
63
109
  var f, y, t, _ = {
64
110
  label: 0,
@@ -150,7 +196,7 @@ function _ts_generator(thisArg, body) {
150
196
  };
151
197
  }
152
198
  }
153
- import { generateObject } from 'ai';
199
+ import { generateObject, generateText } from 'ai';
154
200
  export var VercelClient = /*#__PURE__*/ function() {
155
201
  "use strict";
156
202
  function VercelClient(model) {
@@ -236,6 +282,124 @@ export var VercelClient = /*#__PURE__*/ function() {
236
282
  });
237
283
  }).call(this);
238
284
  }
285
+ },
286
+ {
287
+ key: "generateText",
288
+ value: function generateText1(params) {
289
+ return _async_to_generator(function() {
290
+ var _result_toolCalls, _result_usage, system, messages, tools, modelMessages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, msg, aiTools, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, name, tool, result, _result_usage_totalTokens;
291
+ return _ts_generator(this, function(_state) {
292
+ switch(_state.label){
293
+ case 0:
294
+ system = params.system, messages = params.messages, tools = params.tools;
295
+ // Convert ToolMessage[] to ModelMessage[]
296
+ modelMessages = [];
297
+ if (system) {
298
+ modelMessages.push({
299
+ role: 'system',
300
+ content: system
301
+ });
302
+ }
303
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
304
+ try {
305
+ for(_iterator = messages[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
306
+ msg = _step.value;
307
+ if (msg.role === 'user') {
308
+ modelMessages.push({
309
+ role: 'user',
310
+ content: msg.content
311
+ });
312
+ } else if (msg.role === 'assistant') {
313
+ modelMessages.push({
314
+ role: 'assistant',
315
+ content: msg.content
316
+ });
317
+ } else if (msg.role === 'tool') {
318
+ modelMessages.push({
319
+ role: 'tool',
320
+ content: [
321
+ {
322
+ type: 'tool-result',
323
+ toolCallId: msg.toolCallId,
324
+ toolName: msg.toolName,
325
+ output: {
326
+ type: 'text',
327
+ value: msg.content
328
+ }
329
+ }
330
+ ]
331
+ });
332
+ }
333
+ }
334
+ } catch (err) {
335
+ _didIteratorError = true;
336
+ _iteratorError = err;
337
+ } finally{
338
+ try {
339
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
340
+ _iterator.return();
341
+ }
342
+ } finally{
343
+ if (_didIteratorError) {
344
+ throw _iteratorError;
345
+ }
346
+ }
347
+ }
348
+ // Convert our tool format to Vercel AI SDK format
349
+ aiTools = {};
350
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
351
+ try {
352
+ for(_iterator1 = Object.entries(tools)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
353
+ _step_value = _sliced_to_array(_step1.value, 2), name = _step_value[0], tool = _step_value[1];
354
+ aiTools[name] = {
355
+ description: tool.description,
356
+ inputSchema: tool.inputSchema
357
+ };
358
+ }
359
+ } catch (err) {
360
+ _didIteratorError1 = true;
361
+ _iteratorError1 = err;
362
+ } finally{
363
+ try {
364
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
365
+ _iterator1.return();
366
+ }
367
+ } finally{
368
+ if (_didIteratorError1) {
369
+ throw _iteratorError1;
370
+ }
371
+ }
372
+ }
373
+ return [
374
+ 4,
375
+ generateText({
376
+ model: this.model,
377
+ messages: modelMessages,
378
+ tools: aiTools
379
+ })
380
+ ];
381
+ case 1:
382
+ result = _state.sent();
383
+ return [
384
+ 2,
385
+ {
386
+ text: result.text || undefined,
387
+ toolCalls: (_result_toolCalls = result.toolCalls) === null || _result_toolCalls === void 0 ? void 0 : _result_toolCalls.map(function(tc) {
388
+ return {
389
+ toolCallId: tc.toolCallId,
390
+ toolName: tc.toolName,
391
+ args: tc.input
392
+ };
393
+ }),
394
+ usage: {
395
+ totalTokens: (_result_usage_totalTokens = (_result_usage = result.usage) === null || _result_usage === void 0 ? void 0 : _result_usage.totalTokens) !== null && _result_usage_totalTokens !== void 0 ? _result_usage_totalTokens : 0
396
+ }
397
+ }
398
+ ];
399
+ }
400
+ });
401
+ }).call(this);
402
+ }
239
403
  }
240
404
  ]);
241
405
  return VercelClient;
@@ -1,4 +1,4 @@
1
- import type { ObjectGenerator, Message } from '@positronic/core';
1
+ import type { ObjectGenerator, Message, ToolMessage } from '@positronic/core';
2
2
  import { z } from 'zod';
3
3
  import type { LanguageModel } from 'ai';
4
4
  export declare class VercelClient implements ObjectGenerator {
@@ -12,5 +12,23 @@ export declare class VercelClient implements ObjectGenerator {
12
12
  messages?: Message[];
13
13
  system?: string;
14
14
  }): Promise<z.infer<T>>;
15
+ generateText(params: {
16
+ system?: string;
17
+ messages: ToolMessage[];
18
+ tools: Record<string, {
19
+ description: string;
20
+ inputSchema: z.ZodSchema;
21
+ }>;
22
+ }): Promise<{
23
+ text?: string;
24
+ toolCalls?: Array<{
25
+ toolCallId: string;
26
+ toolName: string;
27
+ args: unknown;
28
+ }>;
29
+ usage: {
30
+ totalTokens: number;
31
+ };
32
+ }>;
15
33
  }
16
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAExC,qBAAa,YAAa,YAAW,eAAe;IAClD,OAAO,CAAC,KAAK,CAAgB;gBAEjB,KAAK,EAAE,aAAa;IAI1B,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,YAAY,EAAE,MA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1E,GAAG,OAAO,CAAC;QACV,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,KAAK,CAAC;YAAE,UAAU,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;QAC3E,KAAK,EAAE;YAAE,WAAW,EAAE,MAAM,CAAA;SAAE,CAAC;KAChC,CAAC;CA6DH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@positronic/client-vercel",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -23,7 +23,7 @@
23
23
  "ai": "^5.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@positronic/core": "^0.0.37",
26
+ "@positronic/core": "^0.0.39",
27
27
  "zod": "^3.24.1"
28
28
  }
29
29
  }