@arcadeai/arcadejs 1.2.1 → 1.4.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.
- package/CHANGELOG.md +53 -0
- package/README.md +2 -2
- package/_shims/index.d.ts +2 -0
- package/_shims/index.js +5 -1
- package/_shims/index.mjs +5 -1
- package/core.d.ts +12 -1
- package/core.d.ts.map +1 -1
- package/core.js +10 -7
- package/core.js.map +1 -1
- package/core.mjs +11 -8
- package/core.mjs.map +1 -1
- package/index.d.mts +6 -2
- package/index.d.ts +6 -2
- package/index.d.ts.map +1 -1
- package/index.js +8 -0
- package/index.js.map +1 -1
- package/index.mjs +8 -0
- package/index.mjs.map +1 -1
- package/internal/qs/formats.d.ts +6 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +11 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +8 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +280 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +276 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.ts +14 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +229 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +3 -0
- package/lib/index.mjs.map +1 -0
- package/lib/zod/types.d.ts +34 -0
- package/lib/zod/types.d.ts.map +1 -0
- package/lib/zod/types.js +3 -0
- package/lib/zod/types.js.map +1 -0
- package/lib/zod/types.mjs +2 -0
- package/lib/zod/types.mjs.map +1 -0
- package/lib/zod/zod.d.ts +55 -0
- package/lib/zod/zod.d.ts.map +1 -0
- package/lib/zod/zod.js +172 -0
- package/lib/zod/zod.js.map +1 -0
- package/lib/zod/zod.mjs +162 -0
- package/lib/zod/zod.mjs.map +1 -0
- package/package.json +10 -30
- package/resources/chat.d.ts +2 -0
- package/resources/chat.d.ts.map +1 -0
- package/resources/chat.js +19 -0
- package/resources/chat.js.map +1 -0
- package/resources/chat.mjs +3 -0
- package/resources/chat.mjs.map +1 -0
- package/resources/index.d.ts +2 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +4 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -0
- package/resources/index.mjs.map +1 -1
- package/resources/tools/index.d.ts +1 -1
- package/resources/tools/index.d.ts.map +1 -1
- package/resources/tools/index.js.map +1 -1
- package/resources/tools/index.mjs.map +1 -1
- package/resources/tools/tools.d.ts +21 -4
- package/resources/tools/tools.d.ts.map +1 -1
- package/resources/tools/tools.js +5 -5
- package/resources/tools/tools.js.map +1 -1
- package/resources/tools/tools.mjs +5 -5
- package/resources/tools/tools.mjs.map +1 -1
- package/resources/tools.d.ts +1 -0
- package/resources/tools.d.ts.map +1 -1
- package/resources/tools.js +17 -0
- package/resources/tools.js.map +1 -1
- package/resources/tools.mjs +2 -1
- package/resources/tools.mjs.map +1 -1
- package/resources/workers.d.ts +180 -0
- package/resources/workers.d.ts.map +1 -0
- package/resources/workers.js +65 -0
- package/resources/workers.js.map +1 -0
- package/resources/workers.mjs +60 -0
- package/resources/workers.mjs.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +18 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/_shims/index.d.ts +2 -0
- package/src/_shims/index.js +5 -1
- package/src/_shims/index.mjs +5 -1
- package/src/core.ts +27 -8
- package/src/index.ts +35 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +9 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +388 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/zod/types.ts +38 -0
- package/src/lib/zod/zod.ts +208 -0
- package/src/resources/chat.ts +3 -0
- package/src/resources/index.ts +13 -0
- package/src/resources/tools/index.ts +1 -0
- package/src/resources/tools/tools.ts +37 -5
- package/src/resources/tools.ts +3 -0
- package/src/resources/workers.ts +330 -0
- package/src/resources.ts +1 -0
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { RFC1738 } from "./formats.mjs";
|
|
2
|
+
const has = Object.prototype.hasOwnProperty;
|
|
3
|
+
const is_array = Array.isArray;
|
|
4
|
+
const hex_table = (() => {
|
|
5
|
+
const array = [];
|
|
6
|
+
for (let i = 0; i < 256; ++i) {
|
|
7
|
+
array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
|
|
8
|
+
}
|
|
9
|
+
return array;
|
|
10
|
+
})();
|
|
11
|
+
function compact_queue(queue) {
|
|
12
|
+
while (queue.length > 1) {
|
|
13
|
+
const item = queue.pop();
|
|
14
|
+
if (!item)
|
|
15
|
+
continue;
|
|
16
|
+
const obj = item.obj[item.prop];
|
|
17
|
+
if (is_array(obj)) {
|
|
18
|
+
const compacted = [];
|
|
19
|
+
for (let j = 0; j < obj.length; ++j) {
|
|
20
|
+
if (typeof obj[j] !== 'undefined') {
|
|
21
|
+
compacted.push(obj[j]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
item.obj[item.prop] = compacted;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function array_to_object(source, options) {
|
|
30
|
+
const obj = options && options.plainObjects ? Object.create(null) : {};
|
|
31
|
+
for (let i = 0; i < source.length; ++i) {
|
|
32
|
+
if (typeof source[i] !== 'undefined') {
|
|
33
|
+
obj[i] = source[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
export function merge(target, source, options = {}) {
|
|
39
|
+
if (!source) {
|
|
40
|
+
return target;
|
|
41
|
+
}
|
|
42
|
+
if (typeof source !== 'object') {
|
|
43
|
+
if (is_array(target)) {
|
|
44
|
+
target.push(source);
|
|
45
|
+
}
|
|
46
|
+
else if (target && typeof target === 'object') {
|
|
47
|
+
if ((options && (options.plainObjects || options.allowPrototypes)) ||
|
|
48
|
+
!has.call(Object.prototype, source)) {
|
|
49
|
+
target[source] = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return [target, source];
|
|
54
|
+
}
|
|
55
|
+
return target;
|
|
56
|
+
}
|
|
57
|
+
if (!target || typeof target !== 'object') {
|
|
58
|
+
return [target].concat(source);
|
|
59
|
+
}
|
|
60
|
+
let mergeTarget = target;
|
|
61
|
+
if (is_array(target) && !is_array(source)) {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
mergeTarget = array_to_object(target, options);
|
|
64
|
+
}
|
|
65
|
+
if (is_array(target) && is_array(source)) {
|
|
66
|
+
source.forEach(function (item, i) {
|
|
67
|
+
if (has.call(target, i)) {
|
|
68
|
+
const targetItem = target[i];
|
|
69
|
+
if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
|
|
70
|
+
target[i] = merge(targetItem, item, options);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
target.push(item);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
target[i] = item;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return target;
|
|
81
|
+
}
|
|
82
|
+
return Object.keys(source).reduce(function (acc, key) {
|
|
83
|
+
const value = source[key];
|
|
84
|
+
if (has.call(acc, key)) {
|
|
85
|
+
acc[key] = merge(acc[key], value, options);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
acc[key] = value;
|
|
89
|
+
}
|
|
90
|
+
return acc;
|
|
91
|
+
}, mergeTarget);
|
|
92
|
+
}
|
|
93
|
+
export function assign_single_source(target, source) {
|
|
94
|
+
return Object.keys(source).reduce(function (acc, key) {
|
|
95
|
+
acc[key] = source[key];
|
|
96
|
+
return acc;
|
|
97
|
+
}, target);
|
|
98
|
+
}
|
|
99
|
+
export function decode(str, _, charset) {
|
|
100
|
+
const strWithoutPlus = str.replace(/\+/g, ' ');
|
|
101
|
+
if (charset === 'iso-8859-1') {
|
|
102
|
+
// unescape never throws, no try...catch needed:
|
|
103
|
+
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
|
|
104
|
+
}
|
|
105
|
+
// utf-8
|
|
106
|
+
try {
|
|
107
|
+
return decodeURIComponent(strWithoutPlus);
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
return strWithoutPlus;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const limit = 1024;
|
|
114
|
+
export const encode = (str, _defaultEncoder, charset, _kind, format) => {
|
|
115
|
+
// This code was originally written by Brian White for the io.js core querystring library.
|
|
116
|
+
// It has been adapted here for stricter adherence to RFC 3986
|
|
117
|
+
if (str.length === 0) {
|
|
118
|
+
return str;
|
|
119
|
+
}
|
|
120
|
+
let string = str;
|
|
121
|
+
if (typeof str === 'symbol') {
|
|
122
|
+
string = Symbol.prototype.toString.call(str);
|
|
123
|
+
}
|
|
124
|
+
else if (typeof str !== 'string') {
|
|
125
|
+
string = String(str);
|
|
126
|
+
}
|
|
127
|
+
if (charset === 'iso-8859-1') {
|
|
128
|
+
return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
|
|
129
|
+
return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
let out = '';
|
|
133
|
+
for (let j = 0; j < string.length; j += limit) {
|
|
134
|
+
const segment = string.length >= limit ? string.slice(j, j + limit) : string;
|
|
135
|
+
const arr = [];
|
|
136
|
+
for (let i = 0; i < segment.length; ++i) {
|
|
137
|
+
let c = segment.charCodeAt(i);
|
|
138
|
+
if (c === 0x2d || // -
|
|
139
|
+
c === 0x2e || // .
|
|
140
|
+
c === 0x5f || // _
|
|
141
|
+
c === 0x7e || // ~
|
|
142
|
+
(c >= 0x30 && c <= 0x39) || // 0-9
|
|
143
|
+
(c >= 0x41 && c <= 0x5a) || // a-z
|
|
144
|
+
(c >= 0x61 && c <= 0x7a) || // A-Z
|
|
145
|
+
(format === RFC1738 && (c === 0x28 || c === 0x29)) // ( )
|
|
146
|
+
) {
|
|
147
|
+
arr[arr.length] = segment.charAt(i);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (c < 0x80) {
|
|
151
|
+
arr[arr.length] = hex_table[c];
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (c < 0x800) {
|
|
155
|
+
arr[arr.length] = hex_table[0xc0 | (c >> 6)] + hex_table[0x80 | (c & 0x3f)];
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (c < 0xd800 || c >= 0xe000) {
|
|
159
|
+
arr[arr.length] =
|
|
160
|
+
hex_table[0xe0 | (c >> 12)] + hex_table[0x80 | ((c >> 6) & 0x3f)] + hex_table[0x80 | (c & 0x3f)];
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
i += 1;
|
|
164
|
+
c = 0x10000 + (((c & 0x3ff) << 10) | (segment.charCodeAt(i) & 0x3ff));
|
|
165
|
+
arr[arr.length] =
|
|
166
|
+
hex_table[0xf0 | (c >> 18)] +
|
|
167
|
+
hex_table[0x80 | ((c >> 12) & 0x3f)] +
|
|
168
|
+
hex_table[0x80 | ((c >> 6) & 0x3f)] +
|
|
169
|
+
hex_table[0x80 | (c & 0x3f)];
|
|
170
|
+
}
|
|
171
|
+
out += arr.join('');
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
};
|
|
175
|
+
export function compact(value) {
|
|
176
|
+
const queue = [{ obj: { o: value }, prop: 'o' }];
|
|
177
|
+
const refs = [];
|
|
178
|
+
for (let i = 0; i < queue.length; ++i) {
|
|
179
|
+
const item = queue[i];
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
const obj = item.obj[item.prop];
|
|
182
|
+
const keys = Object.keys(obj);
|
|
183
|
+
for (let j = 0; j < keys.length; ++j) {
|
|
184
|
+
const key = keys[j];
|
|
185
|
+
const val = obj[key];
|
|
186
|
+
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
|
|
187
|
+
queue.push({ obj: obj, prop: key });
|
|
188
|
+
refs.push(val);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
compact_queue(queue);
|
|
193
|
+
return value;
|
|
194
|
+
}
|
|
195
|
+
export function is_regexp(obj) {
|
|
196
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
197
|
+
}
|
|
198
|
+
export function is_buffer(obj) {
|
|
199
|
+
if (!obj || typeof obj !== 'object') {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
|
|
203
|
+
}
|
|
204
|
+
export function combine(a, b) {
|
|
205
|
+
return [].concat(a, b);
|
|
206
|
+
}
|
|
207
|
+
export function maybe_map(val, fn) {
|
|
208
|
+
if (is_array(val)) {
|
|
209
|
+
const mapped = [];
|
|
210
|
+
for (let i = 0; i < val.length; i += 1) {
|
|
211
|
+
mapped.push(fn(val[i]));
|
|
212
|
+
}
|
|
213
|
+
return mapped;
|
|
214
|
+
}
|
|
215
|
+
return fn(val);
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/internal/qs/utils.ts"],"names":[],"mappings":"OAAO,EAAE,OAAO,EAAE;AAGlB,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AAC5C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC;AAE/B,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE;IACtB,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC,EAAE;QAC5B,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;KACxE;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,EAAE,CAAC;AAEL,SAAS,aAAa,CAAgC,KAAsC;IAC1F,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACvB,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI;YAAE,SAAS;QAEpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEhC,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE;YACjB,MAAM,SAAS,GAAc,EAAE,CAAC;YAEhC,KAAK,IAAI,CA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MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC;SAC1B;QACD,OAAO,MAAM,CAAC;KACf;IACD,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;AACjB,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./zod/types.js"), exports);
|
|
18
|
+
__exportStar(require("./zod/zod.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA4B;AAC5B,+CAA0B"}
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AuthorizationResponse } from "../../resources/shared.js";
|
|
2
|
+
import { ExecuteToolResponse } from "../../resources/tools/tools.js";
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* Response returned when a tool requires authorization before execution
|
|
6
|
+
*/
|
|
7
|
+
export interface ToolAuthorizationResponse {
|
|
8
|
+
authorization_required: true;
|
|
9
|
+
authorization_response: AuthorizationResponse;
|
|
10
|
+
url: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a tool with Zod schema validation and execution capabilities.
|
|
15
|
+
*/
|
|
16
|
+
export interface ZodTool {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string | undefined;
|
|
19
|
+
parameters: z.ZodType;
|
|
20
|
+
output: z.ZodType | undefined;
|
|
21
|
+
execute: <T extends unknown>(input: T) => Promise<ExecuteToolResponse>;
|
|
22
|
+
executeOrAuthorize: <T extends unknown>(input: T) => Promise<ExecuteToolResponse | ToolAuthorizationResponse>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Schema definition for an Arcade tool, containing the tool's name,
|
|
26
|
+
* description, and Zod-validated parameter structure.
|
|
27
|
+
*/
|
|
28
|
+
export interface ZodToolSchema {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string | undefined;
|
|
31
|
+
parameters: z.ZodType;
|
|
32
|
+
output: z.ZodType | undefined;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/zod/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,sBAAsB,EAAE,IAAI,CAAC;IAC7B,sBAAsB,EAAE,qBAAqB,CAAC;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC;IACtB,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,CAAC,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACvE,kBAAkB,EAAE,CAAC,CAAC,SAAS,OAAO,EACpC,KAAK,EAAE,CAAC,KACL,OAAO,CAAC,mBAAmB,GAAG,yBAAyB,CAAC,CAAC;CAC/D;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC;IACtB,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC;CAC/B"}
|
package/lib/zod/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/zod/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/lib/zod/types.ts"],"names":[],"mappings":""}
|
package/lib/zod/zod.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ToolDefinition } from "../../resources/tools/tools.js";
|
|
2
|
+
import { ZodTool, ZodToolSchema } from "./types.js";
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { type Arcade } from "../../index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Checks if an error indicates that authorization for the tool is required
|
|
7
|
+
*/
|
|
8
|
+
export declare function isAuthorizationRequiredError(error: Error): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Converts Arcade Tool Input to Zod schema
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertParametersToZodSchema(parameters: ToolDefinition.Input): z.ZodType;
|
|
13
|
+
/**
|
|
14
|
+
* Converts Arcade Tool Output to Zod schema
|
|
15
|
+
*/
|
|
16
|
+
export declare function convertOutputToZodSchema(output: ToolDefinition.Output): z.ZodType;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a single tool to a Zod-validated tool schema
|
|
19
|
+
* @param tool - The tool to convert
|
|
20
|
+
* @returns Zod-validated tool schema
|
|
21
|
+
* @throws ToolConversionError if the tool is invalid
|
|
22
|
+
*/
|
|
23
|
+
export declare function convertSingleToolToSchema(tool: ToolDefinition): ZodToolSchema;
|
|
24
|
+
/**
|
|
25
|
+
* Converts OpenAI formatted tools to Zod-validated tool schemas
|
|
26
|
+
* @param tools - Array of formatted tools
|
|
27
|
+
* @returns Array of Zod-validated tool schemas
|
|
28
|
+
*/
|
|
29
|
+
export declare function toZodSchema(tools: ToolDefinition[]): ZodToolSchema[];
|
|
30
|
+
/**
|
|
31
|
+
* Converts a single tool to a full tool with execution capabilities
|
|
32
|
+
* @param tool - The tool to convert
|
|
33
|
+
* @param client - Arcade client instance
|
|
34
|
+
* @param userId - User ID to use for the tool execution
|
|
35
|
+
* @returns Zod-validated tool with execution methods
|
|
36
|
+
* @throws ToolConversionError if the tool is invalid
|
|
37
|
+
*/
|
|
38
|
+
export declare function createZodTool({ tool, client, userId, }: {
|
|
39
|
+
tool: ToolDefinition;
|
|
40
|
+
client: Arcade;
|
|
41
|
+
userId: string;
|
|
42
|
+
}): ZodTool;
|
|
43
|
+
/**
|
|
44
|
+
* Converts formatted tools to full tools with execution capabilities
|
|
45
|
+
* @param tools - Array of formatted tools
|
|
46
|
+
* @param client - Arcade client instance
|
|
47
|
+
* @param userId - User ID to use for the tool execution
|
|
48
|
+
* @returns Array of Zod-validated tools with execution methods
|
|
49
|
+
*/
|
|
50
|
+
export declare function toZod({ tools, client, userId, }: {
|
|
51
|
+
tools: ToolDefinition[];
|
|
52
|
+
client: Arcade;
|
|
53
|
+
userId: string;
|
|
54
|
+
}): ZodTool[];
|
|
55
|
+
//# sourceMappingURL=zod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/lib/zod/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAA6B,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAMlE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,cAAc,CAAC,KAAK,GAAG,CAAC,CAAC,OAAO,CAmBxF;AAyCD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,OAAO,CAMjF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,cAAc,GAAG,aAAa,CAU7E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,aAAa,EAAE,CAEpE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,MAAM,EACN,MAAM,GACP,EAAE;IACD,IAAI,EAAE,cAAc,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAuDV;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,MAAM,EACN,MAAM,GACP,EAAE;IACD,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,EAAE,CAEZ"}
|
package/lib/zod/zod.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toZod = exports.createZodTool = exports.toZodSchema = exports.convertSingleToolToSchema = exports.convertOutputToZodSchema = exports.convertParametersToZodSchema = exports.isAuthorizationRequiredError = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Checks if an error indicates that authorization for the tool is required
|
|
7
|
+
*/
|
|
8
|
+
function isAuthorizationRequiredError(error) {
|
|
9
|
+
return (error?.name === 'PermissionDeniedError' ||
|
|
10
|
+
error?.message?.includes('permission denied') ||
|
|
11
|
+
error?.message?.includes('authorization required'));
|
|
12
|
+
}
|
|
13
|
+
exports.isAuthorizationRequiredError = isAuthorizationRequiredError;
|
|
14
|
+
/**
|
|
15
|
+
* Converts Arcade Tool Input to Zod schema
|
|
16
|
+
*/
|
|
17
|
+
function convertParametersToZodSchema(parameters) {
|
|
18
|
+
if (!parameters.parameters || !Array.isArray(parameters.parameters)) {
|
|
19
|
+
return zod_1.z.object({});
|
|
20
|
+
}
|
|
21
|
+
const schemaObj = {};
|
|
22
|
+
for (const param of parameters.parameters) {
|
|
23
|
+
const { name, required, value_schema } = param;
|
|
24
|
+
let zodType = convertValueSchemaToZod(value_schema);
|
|
25
|
+
if (!required) {
|
|
26
|
+
zodType = zodType.optional();
|
|
27
|
+
}
|
|
28
|
+
schemaObj[name] = zodType;
|
|
29
|
+
}
|
|
30
|
+
return zod_1.z.object(schemaObj);
|
|
31
|
+
}
|
|
32
|
+
exports.convertParametersToZodSchema = convertParametersToZodSchema;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a value schema to Zod type
|
|
35
|
+
*/
|
|
36
|
+
function convertValueSchemaToZod(schema) {
|
|
37
|
+
let baseType;
|
|
38
|
+
switch (schema.val_type) {
|
|
39
|
+
case 'string':
|
|
40
|
+
baseType = schema.enum ? zod_1.z.enum(schema.enum) : zod_1.z.string();
|
|
41
|
+
break;
|
|
42
|
+
case 'integer':
|
|
43
|
+
baseType = zod_1.z.number().int();
|
|
44
|
+
break;
|
|
45
|
+
case 'number':
|
|
46
|
+
baseType = zod_1.z.number();
|
|
47
|
+
break;
|
|
48
|
+
case 'boolean':
|
|
49
|
+
baseType = zod_1.z.boolean();
|
|
50
|
+
break;
|
|
51
|
+
case 'json':
|
|
52
|
+
baseType = zod_1.z.any();
|
|
53
|
+
break;
|
|
54
|
+
case 'array':
|
|
55
|
+
if (!schema.inner_val_type) {
|
|
56
|
+
throw new Error('Array type must have inner_val_type specified');
|
|
57
|
+
}
|
|
58
|
+
baseType = zod_1.z.array(convertValueSchemaToZod({ val_type: schema.inner_val_type }));
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
throw new Error(`Unsupported value type: ${schema.val_type}`);
|
|
62
|
+
}
|
|
63
|
+
return baseType;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Converts Arcade Tool Output to Zod schema
|
|
67
|
+
*/
|
|
68
|
+
function convertOutputToZodSchema(output) {
|
|
69
|
+
if (!output.value_schema) {
|
|
70
|
+
return zod_1.z.any();
|
|
71
|
+
}
|
|
72
|
+
return convertValueSchemaToZod(output.value_schema);
|
|
73
|
+
}
|
|
74
|
+
exports.convertOutputToZodSchema = convertOutputToZodSchema;
|
|
75
|
+
/**
|
|
76
|
+
* Converts a single tool to a Zod-validated tool schema
|
|
77
|
+
* @param tool - The tool to convert
|
|
78
|
+
* @returns Zod-validated tool schema
|
|
79
|
+
* @throws ToolConversionError if the tool is invalid
|
|
80
|
+
*/
|
|
81
|
+
function convertSingleToolToSchema(tool) {
|
|
82
|
+
const { qualified_name, description, input, output } = tool;
|
|
83
|
+
const zodParameters = convertParametersToZodSchema(input);
|
|
84
|
+
const zodOutput = output ? convertOutputToZodSchema(output) : undefined;
|
|
85
|
+
return {
|
|
86
|
+
name: qualified_name.replace(/\./g, '_'),
|
|
87
|
+
description,
|
|
88
|
+
parameters: zodParameters,
|
|
89
|
+
output: zodOutput,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
exports.convertSingleToolToSchema = convertSingleToolToSchema;
|
|
93
|
+
/**
|
|
94
|
+
* Converts OpenAI formatted tools to Zod-validated tool schemas
|
|
95
|
+
* @param tools - Array of formatted tools
|
|
96
|
+
* @returns Array of Zod-validated tool schemas
|
|
97
|
+
*/
|
|
98
|
+
function toZodSchema(tools) {
|
|
99
|
+
return tools.map(convertSingleToolToSchema);
|
|
100
|
+
}
|
|
101
|
+
exports.toZodSchema = toZodSchema;
|
|
102
|
+
/**
|
|
103
|
+
* Converts a single tool to a full tool with execution capabilities
|
|
104
|
+
* @param tool - The tool to convert
|
|
105
|
+
* @param client - Arcade client instance
|
|
106
|
+
* @param userId - User ID to use for the tool execution
|
|
107
|
+
* @returns Zod-validated tool with execution methods
|
|
108
|
+
* @throws ToolConversionError if the tool is invalid
|
|
109
|
+
*/
|
|
110
|
+
function createZodTool({ tool, client, userId, }) {
|
|
111
|
+
const schema = convertSingleToolToSchema(tool);
|
|
112
|
+
const { name, description, parameters, output } = schema;
|
|
113
|
+
return {
|
|
114
|
+
name,
|
|
115
|
+
description,
|
|
116
|
+
parameters,
|
|
117
|
+
output,
|
|
118
|
+
execute: async (input) => {
|
|
119
|
+
const validationResult = parameters.safeParse(input);
|
|
120
|
+
if (!validationResult.success) {
|
|
121
|
+
throw new Error(`Invalid input: ${validationResult.error.message}`);
|
|
122
|
+
}
|
|
123
|
+
return client.tools.execute({
|
|
124
|
+
tool_name: name,
|
|
125
|
+
input: validationResult.data,
|
|
126
|
+
user_id: userId,
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
executeOrAuthorize: async (input) => {
|
|
130
|
+
const validationResult = parameters.safeParse(input);
|
|
131
|
+
if (!validationResult.success) {
|
|
132
|
+
throw new Error(`Invalid input: ${validationResult.error.message}`);
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return await client.tools.execute({
|
|
136
|
+
tool_name: name,
|
|
137
|
+
input: validationResult.data,
|
|
138
|
+
user_id: userId,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (error instanceof Error && isAuthorizationRequiredError(error)) {
|
|
143
|
+
const response = (await client.tools.authorize({
|
|
144
|
+
tool_name: name,
|
|
145
|
+
user_id: userId,
|
|
146
|
+
}));
|
|
147
|
+
return {
|
|
148
|
+
authorization_required: true,
|
|
149
|
+
authorization_response: response,
|
|
150
|
+
url: response.url,
|
|
151
|
+
message: 'This tool requires authorization. Please visit the following URL to authorize the tool: ' +
|
|
152
|
+
response.url,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
exports.createZodTool = createZodTool;
|
|
161
|
+
/**
|
|
162
|
+
* Converts formatted tools to full tools with execution capabilities
|
|
163
|
+
* @param tools - Array of formatted tools
|
|
164
|
+
* @param client - Arcade client instance
|
|
165
|
+
* @param userId - User ID to use for the tool execution
|
|
166
|
+
* @returns Array of Zod-validated tools with execution methods
|
|
167
|
+
*/
|
|
168
|
+
function toZod({ tools, client, userId, }) {
|
|
169
|
+
return tools.map((tool) => createZodTool({ tool, client, userId }));
|
|
170
|
+
}
|
|
171
|
+
ex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