@plucky-ai/node 0.2.0 → 0.2.1
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 +1001 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +357 -2
- package/dist/index.d.mts +407 -0
- package/dist/index.mjs +1107 -0
- package/dist/index.mjs.map +1 -0
- package/dist/package.json +3 -3
- package/package.json +31 -31
- package/dist/index.d.ts +0 -51
- package/dist/index.js +0 -135
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
Object.
|
|
2
|
-
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
3
6
|
var __create = Object.create;
|
|
4
7
|
var __defProp = Object.defineProperty;
|
|
5
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,18 +23,947 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
23
|
value: mod,
|
|
21
24
|
enumerable: true
|
|
22
25
|
}) : target, mod));
|
|
23
|
-
|
|
24
26
|
//#endregion
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
let __orpc_contract = require("@orpc/contract");
|
|
28
|
-
__orpc_contract = __toESM(__orpc_contract);
|
|
27
|
+
let _plucky_ai_api_contracts_client = require("@plucky-ai/api-contracts/client");
|
|
28
|
+
let _orpc_contract = require("@orpc/contract");
|
|
29
29
|
let zod = require("zod");
|
|
30
30
|
zod = __toESM(zod);
|
|
31
|
-
|
|
32
|
-
//#region ../
|
|
31
|
+
let _orpc_client = require("@orpc/client");
|
|
32
|
+
//#region ../llm-schemas/dist/index.mjs
|
|
33
|
+
const TextContentBlockSchema = zod.z.object({
|
|
34
|
+
type: zod.z.literal("text"),
|
|
35
|
+
text: zod.z.string()
|
|
36
|
+
});
|
|
37
|
+
const ToolUseContentBlockSchema = zod.z.object({
|
|
38
|
+
type: zod.z.literal("tool_use"),
|
|
39
|
+
id: zod.z.string(),
|
|
40
|
+
name: zod.z.string(),
|
|
41
|
+
input: zod.z.unknown(),
|
|
42
|
+
defaultLoadingText: zod.z.string().nullable().optional(),
|
|
43
|
+
defaultSuccessText: zod.z.string().nullable().optional(),
|
|
44
|
+
partial_json: zod.z.string().nullable().optional()
|
|
45
|
+
});
|
|
46
|
+
const ToolResultContentBlockSchema = zod.z.object({
|
|
47
|
+
type: zod.z.literal("tool_result"),
|
|
48
|
+
toolUseId: zod.z.string(),
|
|
49
|
+
content: zod.z.string(),
|
|
50
|
+
successText: zod.z.string().nullish()
|
|
51
|
+
});
|
|
52
|
+
const ContentBlockSchema = zod.z.union([
|
|
53
|
+
TextContentBlockSchema,
|
|
54
|
+
ToolUseContentBlockSchema,
|
|
55
|
+
ToolResultContentBlockSchema
|
|
56
|
+
]);
|
|
57
|
+
const ContentFieldSchema = zod.z.union([zod.z.string(), zod.z.array(ContentBlockSchema)]);
|
|
58
|
+
const InputMessageSchema = zod.z.object({
|
|
59
|
+
role: zod.z.enum(["user", "assistant"]),
|
|
60
|
+
content: ContentFieldSchema
|
|
61
|
+
});
|
|
62
|
+
InputMessageSchema.extend({ content: zod.z.array(ContentBlockSchema) });
|
|
63
|
+
const SavedInputMessageSchema = InputMessageSchema.extend({
|
|
64
|
+
id: zod.z.string(),
|
|
65
|
+
content: zod.z.array(ContentBlockSchema),
|
|
66
|
+
createdAt: zod.z.coerce.date()
|
|
67
|
+
});
|
|
68
|
+
const UsageSchema = zod.z.object({
|
|
69
|
+
inputTokens: zod.z.number(),
|
|
70
|
+
outputTokens: zod.z.number(),
|
|
71
|
+
cacheReadInputTokens: zod.z.number().optional(),
|
|
72
|
+
cacheCreationInputTokens: zod.z.number().optional()
|
|
73
|
+
});
|
|
74
|
+
const OutputMessageSchema = InputMessageSchema.extend({
|
|
75
|
+
id: zod.z.string(),
|
|
76
|
+
content: zod.z.array(ContentBlockSchema),
|
|
77
|
+
usage: UsageSchema
|
|
78
|
+
});
|
|
79
|
+
const SavedOutputMessageSchema = OutputMessageSchema.extend({ createdAt: zod.z.coerce.date() });
|
|
80
|
+
const SavedMessageSchema = zod.z.union([SavedInputMessageSchema, SavedOutputMessageSchema]);
|
|
81
|
+
zod.z.union([
|
|
82
|
+
InputMessageSchema,
|
|
83
|
+
OutputMessageSchema,
|
|
84
|
+
SavedInputMessageSchema,
|
|
85
|
+
SavedOutputMessageSchema
|
|
86
|
+
]);
|
|
87
|
+
zod.z.object({ messages: zod.z.array(SavedMessageSchema) });
|
|
88
|
+
const MessageStartEventSchema = zod.z.object({
|
|
89
|
+
type: zod.z.literal("message_start"),
|
|
90
|
+
data: zod.z.object({
|
|
91
|
+
type: zod.z.literal("message_start"),
|
|
92
|
+
message: zod.z.object({
|
|
93
|
+
id: zod.z.string(),
|
|
94
|
+
role: zod.z.enum(["user", "assistant"]),
|
|
95
|
+
content: zod.z.array(ContentBlockSchema)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
const MessageDeltaEventSchema = zod.z.object({
|
|
100
|
+
type: zod.z.literal("message_delta"),
|
|
101
|
+
data: zod.z.object({
|
|
102
|
+
type: zod.z.literal("message_delta"),
|
|
103
|
+
delta: zod.z.object({
|
|
104
|
+
stop_reason: zod.z.enum(["end_turn", "tool_use"]),
|
|
105
|
+
stop_sequence: zod.z.string().nullable()
|
|
106
|
+
}),
|
|
107
|
+
usage: UsageSchema.optional()
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
const MessageStopEventSchema = zod.z.object({
|
|
111
|
+
type: zod.z.literal("message_stop"),
|
|
112
|
+
data: zod.z.object({ type: zod.z.literal("message_stop") })
|
|
113
|
+
});
|
|
114
|
+
const ContentBlockStartEventSchema = zod.z.object({
|
|
115
|
+
type: zod.z.literal("content_block_start"),
|
|
116
|
+
data: zod.z.object({
|
|
117
|
+
type: zod.z.literal("content_block_start"),
|
|
118
|
+
index: zod.z.number(),
|
|
119
|
+
contentBlock: ContentBlockSchema
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
const ContentBlockDeltaEventSchema = zod.z.object({
|
|
123
|
+
type: zod.z.literal("content_block_delta"),
|
|
124
|
+
data: zod.z.object({
|
|
125
|
+
type: zod.z.literal("content_block_delta"),
|
|
126
|
+
index: zod.z.number(),
|
|
127
|
+
delta: zod.z.union([zod.z.object({
|
|
128
|
+
type: zod.z.literal("text_delta"),
|
|
129
|
+
text: zod.z.string()
|
|
130
|
+
}), zod.z.object({
|
|
131
|
+
type: zod.z.literal("input_json_delta"),
|
|
132
|
+
partial_json: zod.z.string()
|
|
133
|
+
})])
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
const ContentBlockStopEventSchema = zod.z.object({
|
|
137
|
+
type: zod.z.literal("content_block_stop"),
|
|
138
|
+
data: zod.z.object({
|
|
139
|
+
type: zod.z.literal("content_block_stop"),
|
|
140
|
+
index: zod.z.number()
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
const ErrorEventSchema = zod.z.object({
|
|
144
|
+
type: zod.z.literal("error"),
|
|
145
|
+
data: zod.z.object({
|
|
146
|
+
type: zod.z.literal("error"),
|
|
147
|
+
error: zod.z.object({
|
|
148
|
+
code: zod.z.string(),
|
|
149
|
+
message: zod.z.string()
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
const PingEventSchema = zod.z.object({
|
|
154
|
+
type: zod.z.literal("ping"),
|
|
155
|
+
data: zod.z.object({
|
|
156
|
+
type: zod.z.literal("ping"),
|
|
157
|
+
timestamp: zod.z.number()
|
|
158
|
+
})
|
|
159
|
+
});
|
|
160
|
+
const MessageStreamEventSchema = zod.z.union([
|
|
161
|
+
MessageStartEventSchema,
|
|
162
|
+
MessageDeltaEventSchema,
|
|
163
|
+
MessageStopEventSchema,
|
|
164
|
+
ContentBlockStartEventSchema,
|
|
165
|
+
ContentBlockDeltaEventSchema,
|
|
166
|
+
ContentBlockStopEventSchema,
|
|
167
|
+
ErrorEventSchema,
|
|
168
|
+
PingEventSchema
|
|
169
|
+
]);
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region ../../node_modules/.pnpm/@orpc+shared@1.13.6_@opentelemetry+api@1.9.0/node_modules/@orpc/shared/dist/index.mjs
|
|
172
|
+
function resolveMaybeOptionalOptions(rest) {
|
|
173
|
+
return rest[0] ?? {};
|
|
174
|
+
}
|
|
175
|
+
function toArray(value) {
|
|
176
|
+
return Array.isArray(value) ? value : value === void 0 || value === null ? [] : [value];
|
|
177
|
+
}
|
|
178
|
+
const ORPC_SHARED_PACKAGE_NAME = "@orpc/shared";
|
|
179
|
+
const ORPC_SHARED_PACKAGE_VERSION = "1.13.6";
|
|
180
|
+
function sequential(fn) {
|
|
181
|
+
let lastOperationPromise = Promise.resolve();
|
|
182
|
+
return (...args) => {
|
|
183
|
+
return lastOperationPromise = lastOperationPromise.catch(() => {}).then(() => {
|
|
184
|
+
return fn(...args);
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const SPAN_ERROR_STATUS = 2;
|
|
189
|
+
const GLOBAL_OTEL_CONFIG_KEY = `__${ORPC_SHARED_PACKAGE_NAME}@${ORPC_SHARED_PACKAGE_VERSION}/otel/config__`;
|
|
190
|
+
function getGlobalOtelConfig() {
|
|
191
|
+
return globalThis[GLOBAL_OTEL_CONFIG_KEY];
|
|
192
|
+
}
|
|
193
|
+
function startSpan(name, options = {}, context) {
|
|
194
|
+
return (getGlobalOtelConfig()?.tracer)?.startSpan(name, options, context);
|
|
195
|
+
}
|
|
196
|
+
function setSpanError(span, error, options = {}) {
|
|
197
|
+
if (!span) return;
|
|
198
|
+
const exception = toOtelException(error);
|
|
199
|
+
span.recordException(exception);
|
|
200
|
+
if (!options.signal?.aborted || options.signal.reason !== error) span.setStatus({
|
|
201
|
+
code: SPAN_ERROR_STATUS,
|
|
202
|
+
message: exception.message
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function toOtelException(error) {
|
|
206
|
+
if (error instanceof Error) {
|
|
207
|
+
const exception = {
|
|
208
|
+
message: error.message,
|
|
209
|
+
name: error.name,
|
|
210
|
+
stack: error.stack
|
|
211
|
+
};
|
|
212
|
+
if ("code" in error && (typeof error.code === "string" || typeof error.code === "number")) exception.code = error.code;
|
|
213
|
+
return exception;
|
|
214
|
+
}
|
|
215
|
+
return { message: String(error) };
|
|
216
|
+
}
|
|
217
|
+
async function runWithSpan({ name, context, ...options }, fn) {
|
|
218
|
+
const tracer = getGlobalOtelConfig()?.tracer;
|
|
219
|
+
if (!tracer) return fn();
|
|
220
|
+
const callback = async (span) => {
|
|
221
|
+
try {
|
|
222
|
+
return await fn(span);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
setSpanError(span, e, options);
|
|
225
|
+
throw e;
|
|
226
|
+
} finally {
|
|
227
|
+
span.end();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
if (context) return tracer.startActiveSpan(name, options, context, callback);
|
|
231
|
+
else return tracer.startActiveSpan(name, options, callback);
|
|
232
|
+
}
|
|
233
|
+
async function runInSpanContext(span, fn) {
|
|
234
|
+
const otelConfig = getGlobalOtelConfig();
|
|
235
|
+
if (!span || !otelConfig) return fn();
|
|
236
|
+
const ctx = otelConfig.trace.setSpan(otelConfig.context.active(), span);
|
|
237
|
+
return otelConfig.context.with(ctx, fn);
|
|
238
|
+
}
|
|
239
|
+
function isAsyncIteratorObject(maybe) {
|
|
240
|
+
if (!maybe || typeof maybe !== "object") return false;
|
|
241
|
+
return "next" in maybe && typeof maybe.next === "function" && Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
|
|
242
|
+
}
|
|
243
|
+
const fallbackAsyncDisposeSymbol = Symbol.for("asyncDispose");
|
|
244
|
+
const asyncDisposeSymbol = Symbol.asyncDispose ?? fallbackAsyncDisposeSymbol;
|
|
245
|
+
var AsyncIteratorClass = class {
|
|
246
|
+
#isDone = false;
|
|
247
|
+
#isExecuteComplete = false;
|
|
248
|
+
#cleanup;
|
|
249
|
+
#next;
|
|
250
|
+
constructor(next, cleanup) {
|
|
251
|
+
this.#cleanup = cleanup;
|
|
252
|
+
this.#next = sequential(async () => {
|
|
253
|
+
if (this.#isDone) return {
|
|
254
|
+
done: true,
|
|
255
|
+
value: void 0
|
|
256
|
+
};
|
|
257
|
+
try {
|
|
258
|
+
const result = await next();
|
|
259
|
+
if (result.done) this.#isDone = true;
|
|
260
|
+
return result;
|
|
261
|
+
} catch (err) {
|
|
262
|
+
this.#isDone = true;
|
|
263
|
+
throw err;
|
|
264
|
+
} finally {
|
|
265
|
+
if (this.#isDone && !this.#isExecuteComplete) {
|
|
266
|
+
this.#isExecuteComplete = true;
|
|
267
|
+
await this.#cleanup("next");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
next() {
|
|
273
|
+
return this.#next();
|
|
274
|
+
}
|
|
275
|
+
async return(value) {
|
|
276
|
+
this.#isDone = true;
|
|
277
|
+
if (!this.#isExecuteComplete) {
|
|
278
|
+
this.#isExecuteComplete = true;
|
|
279
|
+
await this.#cleanup("return");
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
done: true,
|
|
283
|
+
value
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
async throw(err) {
|
|
287
|
+
this.#isDone = true;
|
|
288
|
+
if (!this.#isExecuteComplete) {
|
|
289
|
+
this.#isExecuteComplete = true;
|
|
290
|
+
await this.#cleanup("throw");
|
|
291
|
+
}
|
|
292
|
+
throw err;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* asyncDispose symbol only available in esnext, we should fallback to Symbol.for('asyncDispose')
|
|
296
|
+
*/
|
|
297
|
+
async [asyncDisposeSymbol]() {
|
|
298
|
+
this.#isDone = true;
|
|
299
|
+
if (!this.#isExecuteComplete) {
|
|
300
|
+
this.#isExecuteComplete = true;
|
|
301
|
+
await this.#cleanup("dispose");
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
[Symbol.asyncIterator]() {
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
function asyncIteratorWithSpan({ name, ...options }, iterator) {
|
|
309
|
+
let span;
|
|
310
|
+
return new AsyncIteratorClass(async () => {
|
|
311
|
+
span ??= startSpan(name);
|
|
312
|
+
try {
|
|
313
|
+
const result = await runInSpanContext(span, () => iterator.next());
|
|
314
|
+
span?.addEvent(result.done ? "completed" : "yielded");
|
|
315
|
+
return result;
|
|
316
|
+
} catch (err) {
|
|
317
|
+
setSpanError(span, err, options);
|
|
318
|
+
throw err;
|
|
319
|
+
}
|
|
320
|
+
}, async (reason) => {
|
|
321
|
+
try {
|
|
322
|
+
if (reason !== "next") await runInSpanContext(span, () => iterator.return?.());
|
|
323
|
+
} catch (err) {
|
|
324
|
+
setSpanError(span, err, options);
|
|
325
|
+
throw err;
|
|
326
|
+
} finally {
|
|
327
|
+
span?.end();
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function intercept(interceptors, options, main) {
|
|
332
|
+
const next = (options2, index) => {
|
|
333
|
+
const interceptor = interceptors[index];
|
|
334
|
+
if (!interceptor) return main(options2);
|
|
335
|
+
return interceptor({
|
|
336
|
+
...options2,
|
|
337
|
+
next: (newOptions = options2) => next(newOptions, index + 1)
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
return next(options, 0);
|
|
341
|
+
}
|
|
342
|
+
function isObject(value) {
|
|
343
|
+
if (!value || typeof value !== "object") return false;
|
|
344
|
+
const proto = Object.getPrototypeOf(value);
|
|
345
|
+
return proto === Object.prototype || !proto || !proto.constructor;
|
|
346
|
+
}
|
|
347
|
+
function value(value2, ...args) {
|
|
348
|
+
if (typeof value2 === "function") return value2(...args);
|
|
349
|
+
return value2;
|
|
350
|
+
}
|
|
351
|
+
function overlayProxy(target, partial) {
|
|
352
|
+
return new Proxy(typeof target === "function" ? partial : target, {
|
|
353
|
+
get(_, prop) {
|
|
354
|
+
const targetValue = prop in partial ? partial : value(target);
|
|
355
|
+
const v = Reflect.get(targetValue, prop);
|
|
356
|
+
return typeof v === "function" ? v.bind(targetValue) : v;
|
|
357
|
+
},
|
|
358
|
+
has(_, prop) {
|
|
359
|
+
return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region ../../node_modules/.pnpm/@orpc+standard-server@1.13.6_@opentelemetry+api@1.9.0/node_modules/@orpc/standard-server/dist/index.mjs
|
|
365
|
+
var HibernationEventIterator = class extends AsyncIteratorClass {
|
|
366
|
+
/**
|
|
367
|
+
* this property is not transferred to the client, so it should be optional for type safety
|
|
368
|
+
*/
|
|
369
|
+
hibernationCallback;
|
|
370
|
+
constructor(hibernationCallback) {
|
|
371
|
+
super(async () => {
|
|
372
|
+
throw new Error("Cannot iterate over hibernating iterator directly");
|
|
373
|
+
}, async (reason) => {
|
|
374
|
+
if (reason !== "next") throw new Error("Cannot cleanup hibernating iterator directly");
|
|
375
|
+
});
|
|
376
|
+
this.hibernationCallback = hibernationCallback;
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region ../../node_modules/.pnpm/@orpc+server@1.13.6_@opentelemetry+api@1.9.0_crossws@0.3.5_ws@8.19.0/node_modules/@orpc/server/dist/shared/server.Ds4HPpvH.mjs
|
|
381
|
+
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
|
382
|
+
function lazy(loader, meta = {}) {
|
|
383
|
+
return { [LAZY_SYMBOL]: {
|
|
384
|
+
loader,
|
|
385
|
+
meta
|
|
386
|
+
} };
|
|
387
|
+
}
|
|
388
|
+
function isLazy(item) {
|
|
389
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
|
|
390
|
+
}
|
|
391
|
+
function getLazyMeta(lazied) {
|
|
392
|
+
return lazied[LAZY_SYMBOL].meta;
|
|
393
|
+
}
|
|
394
|
+
function unlazy(lazied) {
|
|
395
|
+
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
|
|
396
|
+
}
|
|
397
|
+
function isStartWithMiddlewares(middlewares, compare) {
|
|
398
|
+
if (compare.length > middlewares.length) return false;
|
|
399
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
400
|
+
if (compare[i] === void 0) return true;
|
|
401
|
+
if (middlewares[i] !== compare[i]) return false;
|
|
402
|
+
}
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
function mergeMiddlewares(first, second, options) {
|
|
406
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) return second;
|
|
407
|
+
return [...first, ...second];
|
|
408
|
+
}
|
|
409
|
+
function addMiddleware(middlewares, addition) {
|
|
410
|
+
return [...middlewares, addition];
|
|
411
|
+
}
|
|
412
|
+
var Procedure = class {
|
|
413
|
+
/**
|
|
414
|
+
* This property holds the defined options.
|
|
415
|
+
*/
|
|
416
|
+
"~orpc";
|
|
417
|
+
constructor(def) {
|
|
418
|
+
this["~orpc"] = def;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
function isProcedure(item) {
|
|
422
|
+
if (item instanceof Procedure) return true;
|
|
423
|
+
return (0, _orpc_contract.isContractProcedure)(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
|
424
|
+
}
|
|
425
|
+
function mergeCurrentContext(context, other) {
|
|
426
|
+
return {
|
|
427
|
+
...context,
|
|
428
|
+
...other
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
function createORPCErrorConstructorMap(errors) {
|
|
432
|
+
return new Proxy(errors, { get(target, code) {
|
|
433
|
+
if (typeof code !== "string") return Reflect.get(target, code);
|
|
434
|
+
const item = (...rest) => {
|
|
435
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
436
|
+
const config = errors[code];
|
|
437
|
+
return new _orpc_client.ORPCError(code, {
|
|
438
|
+
defined: Boolean(config),
|
|
439
|
+
status: config?.status,
|
|
440
|
+
message: options.message ?? config?.message,
|
|
441
|
+
data: options.data,
|
|
442
|
+
cause: options.cause
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
return item;
|
|
446
|
+
} });
|
|
447
|
+
}
|
|
448
|
+
function middlewareOutputFn(output) {
|
|
449
|
+
return {
|
|
450
|
+
output,
|
|
451
|
+
context: {}
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function createProcedureClient(lazyableProcedure, ...rest) {
|
|
455
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
456
|
+
return async (...[input, callerOptions]) => {
|
|
457
|
+
const path = toArray(options.path);
|
|
458
|
+
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
459
|
+
const clientContext = callerOptions?.context ?? {};
|
|
460
|
+
const context = await value(options.context ?? {}, clientContext);
|
|
461
|
+
const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
|
|
462
|
+
const validateError = async (e) => {
|
|
463
|
+
if (e instanceof _orpc_client.ORPCError) return await (0, _orpc_contract.validateORPCError)(procedure["~orpc"].errorMap, e);
|
|
464
|
+
return e;
|
|
465
|
+
};
|
|
466
|
+
try {
|
|
467
|
+
const output = await runWithSpan({
|
|
468
|
+
name: "call_procedure",
|
|
469
|
+
signal: callerOptions?.signal
|
|
470
|
+
}, (span) => {
|
|
471
|
+
span?.setAttribute("procedure.path", [...path]);
|
|
472
|
+
return intercept(toArray(options.interceptors), {
|
|
473
|
+
context,
|
|
474
|
+
input,
|
|
475
|
+
errors,
|
|
476
|
+
path,
|
|
477
|
+
procedure,
|
|
478
|
+
signal: callerOptions?.signal,
|
|
479
|
+
lastEventId: callerOptions?.lastEventId
|
|
480
|
+
}, (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions));
|
|
481
|
+
});
|
|
482
|
+
if (isAsyncIteratorObject(output)) {
|
|
483
|
+
if (output instanceof HibernationEventIterator) return output;
|
|
484
|
+
return overlayProxy(output, (0, _orpc_client.mapEventIterator)(asyncIteratorWithSpan({
|
|
485
|
+
name: "consume_event_iterator_output",
|
|
486
|
+
signal: callerOptions?.signal
|
|
487
|
+
}, output), {
|
|
488
|
+
value: (v) => v,
|
|
489
|
+
error: (e) => validateError(e)
|
|
490
|
+
}));
|
|
491
|
+
}
|
|
492
|
+
return output;
|
|
493
|
+
} catch (e) {
|
|
494
|
+
throw await validateError(e);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
async function validateInput(procedure, input) {
|
|
499
|
+
const schema = procedure["~orpc"].inputSchema;
|
|
500
|
+
if (!schema) return input;
|
|
501
|
+
return runWithSpan({ name: "validate_input" }, async () => {
|
|
502
|
+
const result = await schema["~standard"].validate(input);
|
|
503
|
+
if (result.issues) throw new _orpc_client.ORPCError("BAD_REQUEST", {
|
|
504
|
+
message: "Input validation failed",
|
|
505
|
+
data: { issues: result.issues },
|
|
506
|
+
cause: new _orpc_contract.ValidationError({
|
|
507
|
+
message: "Input validation failed",
|
|
508
|
+
issues: result.issues,
|
|
509
|
+
data: input
|
|
510
|
+
})
|
|
511
|
+
});
|
|
512
|
+
return result.value;
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
async function validateOutput(procedure, output) {
|
|
516
|
+
const schema = procedure["~orpc"].outputSchema;
|
|
517
|
+
if (!schema) return output;
|
|
518
|
+
return runWithSpan({ name: "validate_output" }, async () => {
|
|
519
|
+
const result = await schema["~standard"].validate(output);
|
|
520
|
+
if (result.issues) throw new _orpc_client.ORPCError("INTERNAL_SERVER_ERROR", {
|
|
521
|
+
message: "Output validation failed",
|
|
522
|
+
cause: new _orpc_contract.ValidationError({
|
|
523
|
+
message: "Output validation failed",
|
|
524
|
+
issues: result.issues,
|
|
525
|
+
data: output
|
|
526
|
+
})
|
|
527
|
+
});
|
|
528
|
+
return result.value;
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
async function executeProcedureInternal(procedure, options) {
|
|
532
|
+
const middlewares = procedure["~orpc"].middlewares;
|
|
533
|
+
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
|
534
|
+
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
|
535
|
+
const next = async (index, context, input) => {
|
|
536
|
+
let currentInput = input;
|
|
537
|
+
if (index === inputValidationIndex) currentInput = await validateInput(procedure, currentInput);
|
|
538
|
+
const mid = middlewares[index];
|
|
539
|
+
const output = mid ? await runWithSpan({
|
|
540
|
+
name: `middleware.${mid.name}`,
|
|
541
|
+
signal: options.signal
|
|
542
|
+
}, async (span) => {
|
|
543
|
+
span?.setAttribute("middleware.index", index);
|
|
544
|
+
span?.setAttribute("middleware.name", mid.name);
|
|
545
|
+
return (await mid({
|
|
546
|
+
...options,
|
|
547
|
+
context,
|
|
548
|
+
next: async (...[nextOptions]) => {
|
|
549
|
+
const nextContext = nextOptions?.context ?? {};
|
|
550
|
+
return {
|
|
551
|
+
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
|
|
552
|
+
context: nextContext
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
}, currentInput, middlewareOutputFn)).output;
|
|
556
|
+
}) : await runWithSpan({
|
|
557
|
+
name: "handler",
|
|
558
|
+
signal: options.signal
|
|
559
|
+
}, () => procedure["~orpc"].handler({
|
|
560
|
+
...options,
|
|
561
|
+
context,
|
|
562
|
+
input: currentInput
|
|
563
|
+
}));
|
|
564
|
+
if (index === outputValidationIndex) return await validateOutput(procedure, output);
|
|
565
|
+
return output;
|
|
566
|
+
};
|
|
567
|
+
return next(0, options.context, options.input);
|
|
568
|
+
}
|
|
569
|
+
function getRouter(router, path) {
|
|
570
|
+
let current = router;
|
|
571
|
+
for (let i = 0; i < path.length; i++) {
|
|
572
|
+
const segment = path[i];
|
|
573
|
+
if (!current) return;
|
|
574
|
+
if (isProcedure(current)) return;
|
|
575
|
+
if (!isLazy(current)) {
|
|
576
|
+
current = current[segment];
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
const lazied = current;
|
|
580
|
+
const rest = path.slice(i);
|
|
581
|
+
return lazy(async () => {
|
|
582
|
+
return unlazy(getRouter((await unlazy(lazied)).default, rest));
|
|
583
|
+
}, getLazyMeta(lazied));
|
|
584
|
+
}
|
|
585
|
+
return current;
|
|
586
|
+
}
|
|
587
|
+
function createAccessibleLazyRouter(lazied) {
|
|
588
|
+
return new Proxy(lazied, { get(target, key) {
|
|
589
|
+
if (typeof key !== "string") return Reflect.get(target, key);
|
|
590
|
+
return createAccessibleLazyRouter(getRouter(lazied, [key]));
|
|
591
|
+
} });
|
|
592
|
+
}
|
|
593
|
+
function enhanceRouter(router, options) {
|
|
594
|
+
if (isLazy(router)) {
|
|
595
|
+
const laziedMeta = getLazyMeta(router);
|
|
596
|
+
const enhancedPrefix = laziedMeta?.prefix ? (0, _orpc_contract.mergePrefix)(options.prefix, laziedMeta?.prefix) : options.prefix;
|
|
597
|
+
return createAccessibleLazyRouter(lazy(async () => {
|
|
598
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
|
599
|
+
return unlazy(enhanceRouter(unlaziedRouter, options));
|
|
600
|
+
}, {
|
|
601
|
+
...laziedMeta,
|
|
602
|
+
prefix: enhancedPrefix
|
|
603
|
+
}));
|
|
604
|
+
}
|
|
605
|
+
if (isProcedure(router)) {
|
|
606
|
+
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
|
|
607
|
+
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
608
|
+
return new Procedure({
|
|
609
|
+
...router["~orpc"],
|
|
610
|
+
route: (0, _orpc_contract.enhanceRoute)(router["~orpc"].route, options),
|
|
611
|
+
errorMap: (0, _orpc_contract.mergeErrorMap)(options.errorMap, router["~orpc"].errorMap),
|
|
612
|
+
middlewares: newMiddlewares,
|
|
613
|
+
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
614
|
+
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
const enhanced = {};
|
|
618
|
+
for (const key in router) enhanced[key] = enhanceRouter(router[key], options);
|
|
619
|
+
return enhanced;
|
|
620
|
+
}
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region ../../node_modules/.pnpm/@orpc+server@1.13.6_@opentelemetry+api@1.9.0_crossws@0.3.5_ws@8.19.0/node_modules/@orpc/server/dist/index.mjs
|
|
623
|
+
const DEFAULT_CONFIG = {
|
|
624
|
+
initialInputValidationIndex: 0,
|
|
625
|
+
initialOutputValidationIndex: 0,
|
|
626
|
+
dedupeLeadingMiddlewares: true
|
|
627
|
+
};
|
|
628
|
+
function fallbackConfig(key, value) {
|
|
629
|
+
if (value === void 0) return DEFAULT_CONFIG[key];
|
|
630
|
+
return value;
|
|
631
|
+
}
|
|
632
|
+
function decorateMiddleware(middleware) {
|
|
633
|
+
const decorated = ((...args) => middleware(...args));
|
|
634
|
+
decorated.mapInput = (mapInput) => {
|
|
635
|
+
return decorateMiddleware((options, input, ...rest) => middleware(options, mapInput(input), ...rest));
|
|
636
|
+
};
|
|
637
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
|
638
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
|
639
|
+
return decorateMiddleware((options, input, output, ...rest) => {
|
|
640
|
+
return middleware({
|
|
641
|
+
...options,
|
|
642
|
+
next: (...[nextOptions1]) => mapped({
|
|
643
|
+
...options,
|
|
644
|
+
context: {
|
|
645
|
+
...options.context,
|
|
646
|
+
...nextOptions1?.context
|
|
647
|
+
},
|
|
648
|
+
next: (...[nextOptions2]) => options.next({ context: {
|
|
649
|
+
...nextOptions1?.context,
|
|
650
|
+
...nextOptions2?.context
|
|
651
|
+
} })
|
|
652
|
+
}, input, output, ...rest)
|
|
653
|
+
}, input, output, ...rest);
|
|
654
|
+
});
|
|
655
|
+
};
|
|
656
|
+
return decorated;
|
|
657
|
+
}
|
|
658
|
+
function createActionableClient(client) {
|
|
659
|
+
const action = async (input) => {
|
|
660
|
+
try {
|
|
661
|
+
return [null, await client(input)];
|
|
662
|
+
} catch (error) {
|
|
663
|
+
if (error instanceof Error && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_")) throw error;
|
|
664
|
+
if (error instanceof Response && "options" in error && isObject(error.options) || isObject(error) && error.isNotFound === true) throw error;
|
|
665
|
+
return [(0, _orpc_client.toORPCError)(error).toJSON(), void 0];
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
return action;
|
|
669
|
+
}
|
|
670
|
+
var DecoratedProcedure = class DecoratedProcedure extends Procedure {
|
|
671
|
+
/**
|
|
672
|
+
* Adds type-safe custom errors.
|
|
673
|
+
* The provided errors are spared-merged with any existing errors.
|
|
674
|
+
*
|
|
675
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
676
|
+
*/
|
|
677
|
+
errors(errors) {
|
|
678
|
+
return new DecoratedProcedure({
|
|
679
|
+
...this["~orpc"],
|
|
680
|
+
errorMap: (0, _orpc_contract.mergeErrorMap)(this["~orpc"].errorMap, errors)
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Sets or updates the metadata.
|
|
685
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
686
|
+
*
|
|
687
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
688
|
+
*/
|
|
689
|
+
meta(meta) {
|
|
690
|
+
return new DecoratedProcedure({
|
|
691
|
+
...this["~orpc"],
|
|
692
|
+
meta: (0, _orpc_contract.mergeMeta)(this["~orpc"].meta, meta)
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Sets or updates the route definition.
|
|
697
|
+
* The provided route is spared-merged with any existing route.
|
|
698
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
699
|
+
*
|
|
700
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
701
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
702
|
+
*/
|
|
703
|
+
route(route) {
|
|
704
|
+
return new DecoratedProcedure({
|
|
705
|
+
...this["~orpc"],
|
|
706
|
+
route: (0, _orpc_contract.mergeRoute)(this["~orpc"].route, route)
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
use(middleware, mapInput) {
|
|
710
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
|
711
|
+
return new DecoratedProcedure({
|
|
712
|
+
...this["~orpc"],
|
|
713
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
|
718
|
+
*
|
|
719
|
+
* @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
|
|
720
|
+
*/
|
|
721
|
+
callable(...rest) {
|
|
722
|
+
const client = createProcedureClient(this, ...rest);
|
|
723
|
+
return new Proxy(client, {
|
|
724
|
+
get: (target, key) => {
|
|
725
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
|
726
|
+
},
|
|
727
|
+
has: (target, key) => {
|
|
728
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Make this procedure compatible with server action.
|
|
734
|
+
*
|
|
735
|
+
* @see {@link https://orpc.dev/docs/server-action Server Action Docs}
|
|
736
|
+
*/
|
|
737
|
+
actionable(...rest) {
|
|
738
|
+
const action = createActionableClient(createProcedureClient(this, ...rest));
|
|
739
|
+
return new Proxy(action, {
|
|
740
|
+
get: (target, key) => {
|
|
741
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
|
742
|
+
},
|
|
743
|
+
has: (target, key) => {
|
|
744
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
new class Builder {
|
|
750
|
+
/**
|
|
751
|
+
* This property holds the defined options.
|
|
752
|
+
*/
|
|
753
|
+
"~orpc";
|
|
754
|
+
constructor(def) {
|
|
755
|
+
this["~orpc"] = def;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Sets or overrides the config.
|
|
759
|
+
*
|
|
760
|
+
* @see {@link https://orpc.dev/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
|
761
|
+
* @see {@link https://orpc.dev/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
|
762
|
+
*/
|
|
763
|
+
$config(config) {
|
|
764
|
+
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
|
765
|
+
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
|
766
|
+
return new Builder({
|
|
767
|
+
...this["~orpc"],
|
|
768
|
+
config,
|
|
769
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
|
|
770
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
|
771
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Set or override the initial context.
|
|
776
|
+
*
|
|
777
|
+
* @see {@link https://orpc.dev/docs/context Context Docs}
|
|
778
|
+
*/
|
|
779
|
+
$context() {
|
|
780
|
+
return new Builder({
|
|
781
|
+
...this["~orpc"],
|
|
782
|
+
middlewares: [],
|
|
783
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
|
784
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Sets or overrides the initial meta.
|
|
789
|
+
*
|
|
790
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
791
|
+
*/
|
|
792
|
+
$meta(initialMeta) {
|
|
793
|
+
return new Builder({
|
|
794
|
+
...this["~orpc"],
|
|
795
|
+
meta: initialMeta
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Sets or overrides the initial route.
|
|
800
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
801
|
+
*
|
|
802
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
803
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
804
|
+
*/
|
|
805
|
+
$route(initialRoute) {
|
|
806
|
+
return new Builder({
|
|
807
|
+
...this["~orpc"],
|
|
808
|
+
route: initialRoute
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Sets or overrides the initial input schema.
|
|
813
|
+
*
|
|
814
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
815
|
+
*/
|
|
816
|
+
$input(initialInputSchema) {
|
|
817
|
+
return new Builder({
|
|
818
|
+
...this["~orpc"],
|
|
819
|
+
inputSchema: initialInputSchema
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Creates a middleware.
|
|
824
|
+
*
|
|
825
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
826
|
+
*/
|
|
827
|
+
middleware(middleware) {
|
|
828
|
+
return decorateMiddleware(middleware);
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Adds type-safe custom errors.
|
|
832
|
+
* The provided errors are spared-merged with any existing errors.
|
|
833
|
+
*
|
|
834
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
835
|
+
*/
|
|
836
|
+
errors(errors) {
|
|
837
|
+
return new Builder({
|
|
838
|
+
...this["~orpc"],
|
|
839
|
+
errorMap: (0, _orpc_contract.mergeErrorMap)(this["~orpc"].errorMap, errors)
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
use(middleware, mapInput) {
|
|
843
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
|
844
|
+
return new Builder({
|
|
845
|
+
...this["~orpc"],
|
|
846
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Sets or updates the metadata.
|
|
851
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
852
|
+
*
|
|
853
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
854
|
+
*/
|
|
855
|
+
meta(meta) {
|
|
856
|
+
return new Builder({
|
|
857
|
+
...this["~orpc"],
|
|
858
|
+
meta: (0, _orpc_contract.mergeMeta)(this["~orpc"].meta, meta)
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Sets or updates the route definition.
|
|
863
|
+
* The provided route is spared-merged with any existing route.
|
|
864
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
865
|
+
*
|
|
866
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
867
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
868
|
+
*/
|
|
869
|
+
route(route) {
|
|
870
|
+
return new Builder({
|
|
871
|
+
...this["~orpc"],
|
|
872
|
+
route: (0, _orpc_contract.mergeRoute)(this["~orpc"].route, route)
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Defines the input validation schema.
|
|
877
|
+
*
|
|
878
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
879
|
+
*/
|
|
880
|
+
input(schema) {
|
|
881
|
+
return new Builder({
|
|
882
|
+
...this["~orpc"],
|
|
883
|
+
inputSchema: schema,
|
|
884
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Defines the output validation schema.
|
|
889
|
+
*
|
|
890
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
891
|
+
*/
|
|
892
|
+
output(schema) {
|
|
893
|
+
return new Builder({
|
|
894
|
+
...this["~orpc"],
|
|
895
|
+
outputSchema: schema,
|
|
896
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Defines the handler of the procedure.
|
|
901
|
+
*
|
|
902
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
903
|
+
*/
|
|
904
|
+
handler(handler) {
|
|
905
|
+
return new DecoratedProcedure({
|
|
906
|
+
...this["~orpc"],
|
|
907
|
+
handler
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Prefixes all procedures in the router.
|
|
912
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
913
|
+
*
|
|
914
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
915
|
+
*
|
|
916
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
917
|
+
*/
|
|
918
|
+
prefix(prefix) {
|
|
919
|
+
return new Builder({
|
|
920
|
+
...this["~orpc"],
|
|
921
|
+
prefix: (0, _orpc_contract.mergePrefix)(this["~orpc"].prefix, prefix)
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Adds tags to all procedures in the router.
|
|
926
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
927
|
+
*
|
|
928
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
929
|
+
*/
|
|
930
|
+
tag(...tags) {
|
|
931
|
+
return new Builder({
|
|
932
|
+
...this["~orpc"],
|
|
933
|
+
tags: (0, _orpc_contract.mergeTags)(this["~orpc"].tags, tags)
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Applies all of the previously defined options to the specified router.
|
|
938
|
+
*
|
|
939
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
940
|
+
*/
|
|
941
|
+
router(router) {
|
|
942
|
+
return enhanceRouter(router, this["~orpc"]);
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Create a lazy router
|
|
946
|
+
* And applies all of the previously defined options to the specified router.
|
|
947
|
+
*
|
|
948
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
949
|
+
*/
|
|
950
|
+
lazy(loader) {
|
|
951
|
+
return enhanceRouter(lazy(loader), this["~orpc"]);
|
|
952
|
+
}
|
|
953
|
+
}({
|
|
954
|
+
config: {},
|
|
955
|
+
route: {},
|
|
956
|
+
meta: {},
|
|
957
|
+
errorMap: {},
|
|
958
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
|
959
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
|
960
|
+
middlewares: [],
|
|
961
|
+
dedupeLeadingMiddlewares: true
|
|
962
|
+
});
|
|
963
|
+
//#endregion
|
|
964
|
+
//#region ../api-contracts/dist/src-bLbxYIy4.mjs
|
|
33
965
|
var apps_default = {
|
|
34
|
-
find:
|
|
966
|
+
find: _orpc_contract.oc.route({
|
|
35
967
|
method: "GET",
|
|
36
968
|
path: "/apps/{id}",
|
|
37
969
|
tags: ["Apps"],
|
|
@@ -42,7 +974,7 @@ var apps_default = {
|
|
|
42
974
|
name: zod.default.string(),
|
|
43
975
|
createdAt: zod.default.coerce.date()
|
|
44
976
|
})),
|
|
45
|
-
list:
|
|
977
|
+
list: _orpc_contract.oc.route({
|
|
46
978
|
method: "GET",
|
|
47
979
|
path: "/apps",
|
|
48
980
|
tags: ["Apps"],
|
|
@@ -61,7 +993,7 @@ const ChatSchema = zod.default.object({
|
|
|
61
993
|
createdAt: zod.default.coerce.date()
|
|
62
994
|
});
|
|
63
995
|
var chats_default = {
|
|
64
|
-
create:
|
|
996
|
+
create: _orpc_contract.oc.route({
|
|
65
997
|
method: "POST",
|
|
66
998
|
path: "/chats",
|
|
67
999
|
tags: ["Chats"],
|
|
@@ -71,14 +1003,14 @@ var chats_default = {
|
|
|
71
1003
|
title: zod.default.string(),
|
|
72
1004
|
userId: zod.default.string().min(1)
|
|
73
1005
|
})).output(ChatSchema),
|
|
74
|
-
find:
|
|
1006
|
+
find: _orpc_contract.oc.route({
|
|
75
1007
|
method: "GET",
|
|
76
1008
|
path: "/chats/{id}",
|
|
77
1009
|
tags: ["Chats"],
|
|
78
1010
|
summary: "Get a chat",
|
|
79
1011
|
description: "Retrieve a chat by its ID"
|
|
80
1012
|
}).input(zod.default.object({ id: zod.default.string() })).output(ChatSchema),
|
|
81
|
-
list:
|
|
1013
|
+
list: _orpc_contract.oc.route({
|
|
82
1014
|
method: "GET",
|
|
83
1015
|
path: "/chats",
|
|
84
1016
|
tags: ["Chats"],
|
|
@@ -94,6 +1026,49 @@ var chats_default = {
|
|
|
94
1026
|
hasMore: zod.default.boolean()
|
|
95
1027
|
}))
|
|
96
1028
|
};
|
|
1029
|
+
const MessageSchema = zod.default.object({
|
|
1030
|
+
id: zod.default.string(),
|
|
1031
|
+
role: zod.default.enum(["user", "assistant"]),
|
|
1032
|
+
content: zod.default.array(ContentBlockSchema),
|
|
1033
|
+
createdAt: zod.default.coerce.date(),
|
|
1034
|
+
error: zod.default.object({
|
|
1035
|
+
code: zod.default.string(),
|
|
1036
|
+
message: zod.default.string()
|
|
1037
|
+
}).nullable()
|
|
1038
|
+
});
|
|
1039
|
+
var messages_default = { create: _orpc_contract.oc.route({
|
|
1040
|
+
method: "POST",
|
|
1041
|
+
path: "/messages",
|
|
1042
|
+
tags: ["Messages"],
|
|
1043
|
+
summary: "Create a message",
|
|
1044
|
+
description: "Create a user message in a chat"
|
|
1045
|
+
}).input(zod.default.object({
|
|
1046
|
+
id: zod.default.string().optional(),
|
|
1047
|
+
chatId: zod.default.string(),
|
|
1048
|
+
content: ContentFieldSchema
|
|
1049
|
+
})).output(MessageSchema) };
|
|
1050
|
+
const toolSchema = zod.default.object({
|
|
1051
|
+
name: zod.default.string(),
|
|
1052
|
+
description: zod.default.string(),
|
|
1053
|
+
defaultLoadingText: zod.default.string().nullish(),
|
|
1054
|
+
defaultSuccessText: zod.default.string().nullish(),
|
|
1055
|
+
inputSchema: zod.default.any().optional()
|
|
1056
|
+
});
|
|
1057
|
+
var responses_default = { create: _orpc_contract.oc.route({
|
|
1058
|
+
method: "POST",
|
|
1059
|
+
path: "/responses",
|
|
1060
|
+
tags: ["Responses"],
|
|
1061
|
+
summary: "Create a response",
|
|
1062
|
+
description: "Send a user message to a chat and stream the assistant response. Returns a Server-Sent Events (SSE) stream of message events.",
|
|
1063
|
+
successDescription: "SSE stream of message events (message_start, content_block_delta, message_delta, message_stop, etc.)."
|
|
1064
|
+
}).input(zod.default.object({
|
|
1065
|
+
id: zod.default.string().optional().describe("Optional client-generated message ID."),
|
|
1066
|
+
chatId: zod.default.string().describe("The chat ID to send the message to."),
|
|
1067
|
+
content: ContentFieldSchema.describe("The message content (text or structured blocks)."),
|
|
1068
|
+
tools: zod.default.array(toolSchema).default([]).describe("Tools available to the assistant for this request."),
|
|
1069
|
+
tags: zod.default.array(zod.default.string()).optional().describe("Tags to attach to this response."),
|
|
1070
|
+
model: zod.default.string().optional().describe("Override the model for this request.")
|
|
1071
|
+
})).output((0, _orpc_contract.eventIterator)(MessageStreamEventSchema)) };
|
|
97
1072
|
/**
|
|
98
1073
|
* Header name constants for the public API
|
|
99
1074
|
*/
|
|
@@ -103,15 +1078,13 @@ const API_KEY_HEADER = "x-api-key";
|
|
|
103
1078
|
* API keys are prefixed with 'sk_' (secret key)
|
|
104
1079
|
*/
|
|
105
1080
|
const ApiKeyHeaderSchema = zod.z.string().min(1, "API key is required");
|
|
106
|
-
|
|
107
|
-
* Combined headers schema for all API requests
|
|
108
|
-
*/
|
|
109
|
-
const ApiHeadersSchema = zod.z.object({ [API_KEY_HEADER]: ApiKeyHeaderSchema });
|
|
1081
|
+
zod.z.object({ [API_KEY_HEADER]: ApiKeyHeaderSchema });
|
|
110
1082
|
const contract = {
|
|
111
1083
|
apps: apps_default,
|
|
112
|
-
chats: chats_default
|
|
1084
|
+
chats: chats_default,
|
|
1085
|
+
messages: messages_default,
|
|
1086
|
+
responses: responses_default
|
|
113
1087
|
};
|
|
114
|
-
|
|
115
1088
|
//#endregion
|
|
116
1089
|
//#region src/index.ts
|
|
117
1090
|
const DEFAULT_BASE_URL = "https://api.plucky.ai";
|
|
@@ -140,7 +1113,7 @@ var Plucky = class {
|
|
|
140
1113
|
constructor(options) {
|
|
141
1114
|
const { apiKey, baseUrl = DEFAULT_BASE_URL, fetch: customFetch } = options;
|
|
142
1115
|
if (!apiKey) throw new Error("API key is required. Get one at https://app.plucky.ai");
|
|
143
|
-
this.client = (0,
|
|
1116
|
+
this.client = (0, _plucky_ai_api_contracts_client.createApiClient)({
|
|
144
1117
|
apiKey,
|
|
145
1118
|
baseUrl,
|
|
146
1119
|
fetch: customFetch
|
|
@@ -155,17 +1128,16 @@ var Plucky = class {
|
|
|
155
1128
|
return this.client;
|
|
156
1129
|
}
|
|
157
1130
|
};
|
|
158
|
-
var src_default = Plucky;
|
|
159
|
-
|
|
160
1131
|
//#endregion
|
|
161
1132
|
exports.API_KEY_HEADER = API_KEY_HEADER;
|
|
162
1133
|
exports.Plucky = Plucky;
|
|
1134
|
+
exports.default = Plucky;
|
|
163
1135
|
exports.contract = contract;
|
|
164
|
-
Object.defineProperty(exports,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
1136
|
+
Object.defineProperty(exports, "createApiClient", {
|
|
1137
|
+
enumerable: true,
|
|
1138
|
+
get: function() {
|
|
1139
|
+
return _plucky_ai_api_contracts_client.createApiClient;
|
|
1140
|
+
}
|
|
169
1141
|
});
|
|
170
|
-
|
|
1142
|
+
|
|
171
1143
|
//# sourceMappingURL=index.cjs.map
|