@positronic/client-vercel 0.0.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/src/index.js +217 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +25 -0
- package/src/index.ts +52 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _class_call_check(instance, Constructor) {
|
|
31
|
+
if (!(instance instanceof Constructor)) {
|
|
32
|
+
throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _defineProperties(target, props) {
|
|
36
|
+
for(var i = 0; i < props.length; i++){
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
41
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
45
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
46
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
47
|
+
return Constructor;
|
|
48
|
+
}
|
|
49
|
+
function _define_property(obj, key, value) {
|
|
50
|
+
if (key in obj) {
|
|
51
|
+
Object.defineProperty(obj, key, {
|
|
52
|
+
value: value,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
obj[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
function _ts_generator(thisArg, body) {
|
|
63
|
+
var f, y, t, _ = {
|
|
64
|
+
label: 0,
|
|
65
|
+
sent: function() {
|
|
66
|
+
if (t[0] & 1) throw t[1];
|
|
67
|
+
return t[1];
|
|
68
|
+
},
|
|
69
|
+
trys: [],
|
|
70
|
+
ops: []
|
|
71
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
72
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
73
|
+
return this;
|
|
74
|
+
}), g;
|
|
75
|
+
function verb(n) {
|
|
76
|
+
return function(v) {
|
|
77
|
+
return step([
|
|
78
|
+
n,
|
|
79
|
+
v
|
|
80
|
+
]);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function step(op) {
|
|
84
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
85
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
86
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
87
|
+
if (y = 0, t) op = [
|
|
88
|
+
op[0] & 2,
|
|
89
|
+
t.value
|
|
90
|
+
];
|
|
91
|
+
switch(op[0]){
|
|
92
|
+
case 0:
|
|
93
|
+
case 1:
|
|
94
|
+
t = op;
|
|
95
|
+
break;
|
|
96
|
+
case 4:
|
|
97
|
+
_.label++;
|
|
98
|
+
return {
|
|
99
|
+
value: op[1],
|
|
100
|
+
done: false
|
|
101
|
+
};
|
|
102
|
+
case 5:
|
|
103
|
+
_.label++;
|
|
104
|
+
y = op[1];
|
|
105
|
+
op = [
|
|
106
|
+
0
|
|
107
|
+
];
|
|
108
|
+
continue;
|
|
109
|
+
case 7:
|
|
110
|
+
op = _.ops.pop();
|
|
111
|
+
_.trys.pop();
|
|
112
|
+
continue;
|
|
113
|
+
default:
|
|
114
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
115
|
+
_ = 0;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
119
|
+
_.label = op[1];
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
123
|
+
_.label = t[1];
|
|
124
|
+
t = op;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
if (t && _.label < t[2]) {
|
|
128
|
+
_.label = t[2];
|
|
129
|
+
_.ops.push(op);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
if (t[2]) _.ops.pop();
|
|
133
|
+
_.trys.pop();
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
op = body.call(thisArg, _);
|
|
137
|
+
} catch (e) {
|
|
138
|
+
op = [
|
|
139
|
+
6,
|
|
140
|
+
e
|
|
141
|
+
];
|
|
142
|
+
y = 0;
|
|
143
|
+
} finally{
|
|
144
|
+
f = t = 0;
|
|
145
|
+
}
|
|
146
|
+
if (op[0] & 5) throw op[1];
|
|
147
|
+
return {
|
|
148
|
+
value: op[0] ? op[1] : void 0,
|
|
149
|
+
done: true
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
import { generateObject } from 'ai';
|
|
154
|
+
export var VercelClient = /*#__PURE__*/ function() {
|
|
155
|
+
"use strict";
|
|
156
|
+
function VercelClient(model) {
|
|
157
|
+
_class_call_check(this, VercelClient);
|
|
158
|
+
_define_property(this, "model", void 0);
|
|
159
|
+
this.model = model;
|
|
160
|
+
}
|
|
161
|
+
_create_class(VercelClient, [
|
|
162
|
+
{
|
|
163
|
+
key: "generateObject",
|
|
164
|
+
value: function generateObject1(params) {
|
|
165
|
+
return _async_to_generator(function() {
|
|
166
|
+
var schema, schemaName, schemaDescription, prompt, messages, system, coreMessages, object;
|
|
167
|
+
return _ts_generator(this, function(_state) {
|
|
168
|
+
switch(_state.label){
|
|
169
|
+
case 0:
|
|
170
|
+
schema = params.schema, schemaName = params.schemaName, schemaDescription = params.schemaDescription, prompt = params.prompt, messages = params.messages, system = params.system;
|
|
171
|
+
coreMessages = [];
|
|
172
|
+
if (system) {
|
|
173
|
+
coreMessages.push({
|
|
174
|
+
role: 'system',
|
|
175
|
+
content: system
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (messages) {
|
|
179
|
+
messages.forEach(function(msg) {
|
|
180
|
+
coreMessages.push({
|
|
181
|
+
role: msg.role,
|
|
182
|
+
content: msg.content
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (prompt) {
|
|
187
|
+
coreMessages.push({
|
|
188
|
+
role: 'user',
|
|
189
|
+
content: prompt
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return [
|
|
193
|
+
4,
|
|
194
|
+
generateObject({
|
|
195
|
+
model: this.model,
|
|
196
|
+
schema: schema,
|
|
197
|
+
schemaName: schemaName,
|
|
198
|
+
schemaDescription: schemaDescription,
|
|
199
|
+
messages: coreMessages.length > 0 ? coreMessages : undefined,
|
|
200
|
+
prompt: coreMessages.length === 0 && prompt ? prompt : undefined,
|
|
201
|
+
mode: 'auto'
|
|
202
|
+
})
|
|
203
|
+
];
|
|
204
|
+
case 1:
|
|
205
|
+
object = _state.sent().object;
|
|
206
|
+
return [
|
|
207
|
+
2,
|
|
208
|
+
object
|
|
209
|
+
];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}).call(this);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
]);
|
|
216
|
+
return VercelClient;
|
|
217
|
+
}();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ObjectGenerator, Message } from '@positronic/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { LanguageModel } from 'ai';
|
|
4
|
+
export declare class VercelClient implements ObjectGenerator {
|
|
5
|
+
private model;
|
|
6
|
+
constructor(model: LanguageModel);
|
|
7
|
+
generateObject<T extends z.AnyZodObject>(params: {
|
|
8
|
+
schema: T;
|
|
9
|
+
schemaName: string;
|
|
10
|
+
schemaDescription?: string;
|
|
11
|
+
prompt?: string;
|
|
12
|
+
messages?: Message[];
|
|
13
|
+
system?: string;
|
|
14
|
+
}): Promise<z.infer<T>>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,MAAM,EAAE;QACrD,MAAM,EAAE,CAAC,CAAC;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;QACrB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAgCxB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@positronic/client-vercel",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Vercel AI client for Positronic",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/src/index.js",
|
|
10
|
+
"types": "dist/types/index.d.ts",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"tsc": "tsc --project tsconfig.json",
|
|
14
|
+
"swc": "swc src -d dist",
|
|
15
|
+
"build": "npm run tsc && npm run swc",
|
|
16
|
+
"clean": "rm -rf tsconfig.tsbuildinfo dist node_modules"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"ai": "^4.3.4"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@positronic/core": "^0.0.1",
|
|
23
|
+
"zod": "^3.24.1"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ObjectGenerator, Message } from '@positronic/core';
|
|
2
|
+
import { generateObject } from 'ai';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import type { LanguageModel } from 'ai';
|
|
5
|
+
|
|
6
|
+
export class VercelClient implements ObjectGenerator {
|
|
7
|
+
private model: LanguageModel;
|
|
8
|
+
|
|
9
|
+
constructor(model: LanguageModel) {
|
|
10
|
+
this.model = model;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async generateObject<T extends z.AnyZodObject>(params: {
|
|
14
|
+
schema: T;
|
|
15
|
+
schemaName: string;
|
|
16
|
+
schemaDescription?: string;
|
|
17
|
+
prompt?: string;
|
|
18
|
+
messages?: Message[];
|
|
19
|
+
system?: string;
|
|
20
|
+
}): Promise<z.infer<T>> {
|
|
21
|
+
const { schema, schemaName, schemaDescription, prompt, messages, system } =
|
|
22
|
+
params;
|
|
23
|
+
|
|
24
|
+
const coreMessages: Message[] = [];
|
|
25
|
+
|
|
26
|
+
if (system) {
|
|
27
|
+
coreMessages.push({ role: 'system', content: system });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (messages) {
|
|
31
|
+
messages.forEach((msg) => {
|
|
32
|
+
coreMessages.push({ role: msg.role, content: msg.content });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (prompt) {
|
|
37
|
+
coreMessages.push({ role: 'user', content: prompt });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { object } = await generateObject({
|
|
41
|
+
model: this.model,
|
|
42
|
+
schema,
|
|
43
|
+
schemaName,
|
|
44
|
+
schemaDescription,
|
|
45
|
+
messages: coreMessages.length > 0 ? coreMessages : undefined,
|
|
46
|
+
prompt: coreMessages.length === 0 && prompt ? prompt : undefined,
|
|
47
|
+
mode: 'auto',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return object as z.infer<T>;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"emitDeclarationOnly": true,
|
|
7
|
+
"declarationDir": "./dist/types",
|
|
8
|
+
"declarationMap": true
|
|
9
|
+
},
|
|
10
|
+
"include": ["src/**/*"],
|
|
11
|
+
"exclude": ["dist", "node_modules", "**/*.test.ts"]
|
|
12
|
+
}
|