@gizmo-ai/client 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,835 @@
1
+ // @bun
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true,
8
+ configurable: true,
9
+ set: (newValue) => all[name] = () => newValue
10
+ });
11
+ };
12
+
13
+ // src/errors.ts
14
+ class GizmoClientError extends Error {
15
+ status;
16
+ body;
17
+ constructor(status, message, body) {
18
+ super(message);
19
+ this.name = "GizmoClientError";
20
+ this.status = status;
21
+ this.body = body;
22
+ }
23
+ }
24
+
25
+ // ../../node_modules/.bun/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.mjs
26
+ var exports_core = {};
27
+ __export(exports_core, {
28
+ validator: () => validator,
29
+ validate: () => validate,
30
+ getValueByPointer: () => getValueByPointer,
31
+ deepClone: () => deepClone,
32
+ applyReducer: () => applyReducer,
33
+ applyPatch: () => applyPatch,
34
+ applyOperation: () => applyOperation,
35
+ _areEquals: () => _areEquals,
36
+ JsonPatchError: () => JsonPatchError
37
+ });
38
+
39
+ // ../../node_modules/.bun/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/helpers.mjs
40
+ /*!
41
+ * https://github.com/Starcounter-Jack/JSON-Patch
42
+ * (c) 2017-2022 Joachim Wester
43
+ * MIT licensed
44
+ */
45
+ var __extends = function() {
46
+ var extendStatics = function(d, b) {
47
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
48
+ d2.__proto__ = b2;
49
+ } || function(d2, b2) {
50
+ for (var p in b2)
51
+ if (b2.hasOwnProperty(p))
52
+ d2[p] = b2[p];
53
+ };
54
+ return extendStatics(d, b);
55
+ };
56
+ return function(d, b) {
57
+ extendStatics(d, b);
58
+ function __() {
59
+ this.constructor = d;
60
+ }
61
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __);
62
+ };
63
+ }();
64
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
65
+ function hasOwnProperty(obj, key) {
66
+ return _hasOwnProperty.call(obj, key);
67
+ }
68
+ function _objectKeys(obj) {
69
+ if (Array.isArray(obj)) {
70
+ var keys_1 = new Array(obj.length);
71
+ for (var k = 0;k < keys_1.length; k++) {
72
+ keys_1[k] = "" + k;
73
+ }
74
+ return keys_1;
75
+ }
76
+ if (Object.keys) {
77
+ return Object.keys(obj);
78
+ }
79
+ var keys = [];
80
+ for (var i in obj) {
81
+ if (hasOwnProperty(obj, i)) {
82
+ keys.push(i);
83
+ }
84
+ }
85
+ return keys;
86
+ }
87
+ function _deepClone(obj) {
88
+ switch (typeof obj) {
89
+ case "object":
90
+ return JSON.parse(JSON.stringify(obj));
91
+ case "undefined":
92
+ return null;
93
+ default:
94
+ return obj;
95
+ }
96
+ }
97
+ function isInteger(str) {
98
+ var i = 0;
99
+ var len = str.length;
100
+ var charCode;
101
+ while (i < len) {
102
+ charCode = str.charCodeAt(i);
103
+ if (charCode >= 48 && charCode <= 57) {
104
+ i++;
105
+ continue;
106
+ }
107
+ return false;
108
+ }
109
+ return true;
110
+ }
111
+ function escapePathComponent(path) {
112
+ if (path.indexOf("/") === -1 && path.indexOf("~") === -1)
113
+ return path;
114
+ return path.replace(/~/g, "~0").replace(/\//g, "~1");
115
+ }
116
+ function unescapePathComponent(path) {
117
+ return path.replace(/~1/g, "/").replace(/~0/g, "~");
118
+ }
119
+ function hasUndefined(obj) {
120
+ if (obj === undefined) {
121
+ return true;
122
+ }
123
+ if (obj) {
124
+ if (Array.isArray(obj)) {
125
+ for (var i_1 = 0, len = obj.length;i_1 < len; i_1++) {
126
+ if (hasUndefined(obj[i_1])) {
127
+ return true;
128
+ }
129
+ }
130
+ } else if (typeof obj === "object") {
131
+ var objKeys = _objectKeys(obj);
132
+ var objKeysLength = objKeys.length;
133
+ for (var i = 0;i < objKeysLength; i++) {
134
+ if (hasUndefined(obj[objKeys[i]])) {
135
+ return true;
136
+ }
137
+ }
138
+ }
139
+ }
140
+ return false;
141
+ }
142
+ function patchErrorMessageFormatter(message, args) {
143
+ var messageParts = [message];
144
+ for (var key in args) {
145
+ var value = typeof args[key] === "object" ? JSON.stringify(args[key], null, 2) : args[key];
146
+ if (typeof value !== "undefined") {
147
+ messageParts.push(key + ": " + value);
148
+ }
149
+ }
150
+ return messageParts.join(`
151
+ `);
152
+ }
153
+ var PatchError = function(_super) {
154
+ __extends(PatchError2, _super);
155
+ function PatchError2(message, name, index, operation, tree) {
156
+ var _newTarget = this.constructor;
157
+ var _this = _super.call(this, patchErrorMessageFormatter(message, { name, index, operation, tree })) || this;
158
+ _this.name = name;
159
+ _this.index = index;
160
+ _this.operation = operation;
161
+ _this.tree = tree;
162
+ Object.setPrototypeOf(_this, _newTarget.prototype);
163
+ _this.message = patchErrorMessageFormatter(message, { name, index, operation, tree });
164
+ return _this;
165
+ }
166
+ return PatchError2;
167
+ }(Error);
168
+
169
+ // ../../node_modules/.bun/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/core.mjs
170
+ var JsonPatchError = PatchError;
171
+ var deepClone = _deepClone;
172
+ var objOps = {
173
+ add: function(obj, key, document) {
174
+ obj[key] = this.value;
175
+ return { newDocument: document };
176
+ },
177
+ remove: function(obj, key, document) {
178
+ var removed = obj[key];
179
+ delete obj[key];
180
+ return { newDocument: document, removed };
181
+ },
182
+ replace: function(obj, key, document) {
183
+ var removed = obj[key];
184
+ obj[key] = this.value;
185
+ return { newDocument: document, removed };
186
+ },
187
+ move: function(obj, key, document) {
188
+ var removed = getValueByPointer(document, this.path);
189
+ if (removed) {
190
+ removed = _deepClone(removed);
191
+ }
192
+ var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
193
+ applyOperation(document, { op: "add", path: this.path, value: originalValue });
194
+ return { newDocument: document, removed };
195
+ },
196
+ copy: function(obj, key, document) {
197
+ var valueToCopy = getValueByPointer(document, this.from);
198
+ applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) });
199
+ return { newDocument: document };
200
+ },
201
+ test: function(obj, key, document) {
202
+ return { newDocument: document, test: _areEquals(obj[key], this.value) };
203
+ },
204
+ _get: function(obj, key, document) {
205
+ this.value = obj[key];
206
+ return { newDocument: document };
207
+ }
208
+ };
209
+ var arrOps = {
210
+ add: function(arr, i, document) {
211
+ if (isInteger(i)) {
212
+ arr.splice(i, 0, this.value);
213
+ } else {
214
+ arr[i] = this.value;
215
+ }
216
+ return { newDocument: document, index: i };
217
+ },
218
+ remove: function(arr, i, document) {
219
+ var removedList = arr.splice(i, 1);
220
+ return { newDocument: document, removed: removedList[0] };
221
+ },
222
+ replace: function(arr, i, document) {
223
+ var removed = arr[i];
224
+ arr[i] = this.value;
225
+ return { newDocument: document, removed };
226
+ },
227
+ move: objOps.move,
228
+ copy: objOps.copy,
229
+ test: objOps.test,
230
+ _get: objOps._get
231
+ };
232
+ function getValueByPointer(document, pointer) {
233
+ if (pointer == "") {
234
+ return document;
235
+ }
236
+ var getOriginalDestination = { op: "_get", path: pointer };
237
+ applyOperation(document, getOriginalDestination);
238
+ return getOriginalDestination.value;
239
+ }
240
+ function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
241
+ if (validateOperation === undefined) {
242
+ validateOperation = false;
243
+ }
244
+ if (mutateDocument === undefined) {
245
+ mutateDocument = true;
246
+ }
247
+ if (banPrototypeModifications === undefined) {
248
+ banPrototypeModifications = true;
249
+ }
250
+ if (index === undefined) {
251
+ index = 0;
252
+ }
253
+ if (validateOperation) {
254
+ if (typeof validateOperation == "function") {
255
+ validateOperation(operation, 0, document, operation.path);
256
+ } else {
257
+ validator(operation, 0);
258
+ }
259
+ }
260
+ if (operation.path === "") {
261
+ var returnValue = { newDocument: document };
262
+ if (operation.op === "add") {
263
+ returnValue.newDocument = operation.value;
264
+ return returnValue;
265
+ } else if (operation.op === "replace") {
266
+ returnValue.newDocument = operation.value;
267
+ returnValue.removed = document;
268
+ return returnValue;
269
+ } else if (operation.op === "move" || operation.op === "copy") {
270
+ returnValue.newDocument = getValueByPointer(document, operation.from);
271
+ if (operation.op === "move") {
272
+ returnValue.removed = document;
273
+ }
274
+ return returnValue;
275
+ } else if (operation.op === "test") {
276
+ returnValue.test = _areEquals(document, operation.value);
277
+ if (returnValue.test === false) {
278
+ throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
279
+ }
280
+ returnValue.newDocument = document;
281
+ return returnValue;
282
+ } else if (operation.op === "remove") {
283
+ returnValue.removed = document;
284
+ returnValue.newDocument = null;
285
+ return returnValue;
286
+ } else if (operation.op === "_get") {
287
+ operation.value = document;
288
+ return returnValue;
289
+ } else {
290
+ if (validateOperation) {
291
+ throw new JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", index, operation, document);
292
+ } else {
293
+ return returnValue;
294
+ }
295
+ }
296
+ } else {
297
+ if (!mutateDocument) {
298
+ document = _deepClone(document);
299
+ }
300
+ var path = operation.path || "";
301
+ var keys = path.split("/");
302
+ var obj = document;
303
+ var t = 1;
304
+ var len = keys.length;
305
+ var existingPathFragment = undefined;
306
+ var key = undefined;
307
+ var validateFunction = undefined;
308
+ if (typeof validateOperation == "function") {
309
+ validateFunction = validateOperation;
310
+ } else {
311
+ validateFunction = validator;
312
+ }
313
+ while (true) {
314
+ key = keys[t];
315
+ if (key && key.indexOf("~") != -1) {
316
+ key = unescapePathComponent(key);
317
+ }
318
+ if (banPrototypeModifications && (key == "__proto__" || key == "prototype" && t > 0 && keys[t - 1] == "constructor")) {
319
+ throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");
320
+ }
321
+ if (validateOperation) {
322
+ if (existingPathFragment === undefined) {
323
+ if (obj[key] === undefined) {
324
+ existingPathFragment = keys.slice(0, t).join("/");
325
+ } else if (t == len - 1) {
326
+ existingPathFragment = operation.path;
327
+ }
328
+ if (existingPathFragment !== undefined) {
329
+ validateFunction(operation, 0, document, existingPathFragment);
330
+ }
331
+ }
332
+ }
333
+ t++;
334
+ if (Array.isArray(obj)) {
335
+ if (key === "-") {
336
+ key = obj.length;
337
+ } else {
338
+ if (validateOperation && !isInteger(key)) {
339
+ throw new JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
340
+ } else if (isInteger(key)) {
341
+ key = ~~key;
342
+ }
343
+ }
344
+ if (t >= len) {
345
+ if (validateOperation && operation.op === "add" && key > obj.length) {
346
+ throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
347
+ }
348
+ var returnValue = arrOps[operation.op].call(operation, obj, key, document);
349
+ if (returnValue.test === false) {
350
+ throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
351
+ }
352
+ return returnValue;
353
+ }
354
+ } else {
355
+ if (t >= len) {
356
+ var returnValue = objOps[operation.op].call(operation, obj, key, document);
357
+ if (returnValue.test === false) {
358
+ throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
359
+ }
360
+ return returnValue;
361
+ }
362
+ }
363
+ obj = obj[key];
364
+ if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
365
+ throw new JsonPatchError("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", index, operation, document);
366
+ }
367
+ }
368
+ }
369
+ }
370
+ function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
371
+ if (mutateDocument === undefined) {
372
+ mutateDocument = true;
373
+ }
374
+ if (banPrototypeModifications === undefined) {
375
+ banPrototypeModifications = true;
376
+ }
377
+ if (validateOperation) {
378
+ if (!Array.isArray(patch)) {
379
+ throw new JsonPatchError("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
380
+ }
381
+ }
382
+ if (!mutateDocument) {
383
+ document = _deepClone(document);
384
+ }
385
+ var results = new Array(patch.length);
386
+ for (var i = 0, length_1 = patch.length;i < length_1; i++) {
387
+ results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
388
+ document = results[i].newDocument;
389
+ }
390
+ results.newDocument = document;
391
+ return results;
392
+ }
393
+ function applyReducer(document, operation, index) {
394
+ var operationResult = applyOperation(document, operation);
395
+ if (operationResult.test === false) {
396
+ throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
397
+ }
398
+ return operationResult.newDocument;
399
+ }
400
+ function validator(operation, index, document, existingPathFragment) {
401
+ if (typeof operation !== "object" || operation === null || Array.isArray(operation)) {
402
+ throw new JsonPatchError("Operation is not an object", "OPERATION_NOT_AN_OBJECT", index, operation, document);
403
+ } else if (!objOps[operation.op]) {
404
+ throw new JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", index, operation, document);
405
+ } else if (typeof operation.path !== "string") {
406
+ throw new JsonPatchError("Operation `path` property is not a string", "OPERATION_PATH_INVALID", index, operation, document);
407
+ } else if (operation.path.indexOf("/") !== 0 && operation.path.length > 0) {
408
+ throw new JsonPatchError('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", index, operation, document);
409
+ } else if ((operation.op === "move" || operation.op === "copy") && typeof operation.from !== "string") {
410
+ throw new JsonPatchError("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", index, operation, document);
411
+ } else if ((operation.op === "add" || operation.op === "replace" || operation.op === "test") && operation.value === undefined) {
412
+ throw new JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", index, operation, document);
413
+ } else if ((operation.op === "add" || operation.op === "replace" || operation.op === "test") && hasUndefined(operation.value)) {
414
+ throw new JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", index, operation, document);
415
+ } else if (document) {
416
+ if (operation.op == "add") {
417
+ var pathLen = operation.path.split("/").length;
418
+ var existingPathLen = existingPathFragment.split("/").length;
419
+ if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
420
+ throw new JsonPatchError("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", index, operation, document);
421
+ }
422
+ } else if (operation.op === "replace" || operation.op === "remove" || operation.op === "_get") {
423
+ if (operation.path !== existingPathFragment) {
424
+ throw new JsonPatchError("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", index, operation, document);
425
+ }
426
+ } else if (operation.op === "move" || operation.op === "copy") {
427
+ var existingValue = { op: "_get", path: operation.from, value: undefined };
428
+ var error = validate([existingValue], document);
429
+ if (error && error.name === "OPERATION_PATH_UNRESOLVABLE") {
430
+ throw new JsonPatchError("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", index, operation, document);
431
+ }
432
+ }
433
+ }
434
+ }
435
+ function validate(sequence, document, externalValidator) {
436
+ try {
437
+ if (!Array.isArray(sequence)) {
438
+ throw new JsonPatchError("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
439
+ }
440
+ if (document) {
441
+ applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
442
+ } else {
443
+ externalValidator = externalValidator || validator;
444
+ for (var i = 0;i < sequence.length; i++) {
445
+ externalValidator(sequence[i], i, document, undefined);
446
+ }
447
+ }
448
+ } catch (e) {
449
+ if (e instanceof JsonPatchError) {
450
+ return e;
451
+ } else {
452
+ throw e;
453
+ }
454
+ }
455
+ }
456
+ function _areEquals(a, b) {
457
+ if (a === b)
458
+ return true;
459
+ if (a && b && typeof a == "object" && typeof b == "object") {
460
+ var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
461
+ if (arrA && arrB) {
462
+ length = a.length;
463
+ if (length != b.length)
464
+ return false;
465
+ for (i = length;i-- !== 0; )
466
+ if (!_areEquals(a[i], b[i]))
467
+ return false;
468
+ return true;
469
+ }
470
+ if (arrA != arrB)
471
+ return false;
472
+ var keys = Object.keys(a);
473
+ length = keys.length;
474
+ if (length !== Object.keys(b).length)
475
+ return false;
476
+ for (i = length;i-- !== 0; )
477
+ if (!b.hasOwnProperty(keys[i]))
478
+ return false;
479
+ for (i = length;i-- !== 0; ) {
480
+ key = keys[i];
481
+ if (!_areEquals(a[key], b[key]))
482
+ return false;
483
+ }
484
+ return true;
485
+ }
486
+ return a !== a && b !== b;
487
+ }
488
+ // ../../node_modules/.bun/fast-json-patch@3.1.1/node_modules/fast-json-patch/module/duplex.mjs
489
+ var exports_duplex = {};
490
+ __export(exports_duplex, {
491
+ unobserve: () => unobserve,
492
+ observe: () => observe,
493
+ generate: () => generate,
494
+ compare: () => compare
495
+ });
496
+ /*!
497
+ * https://github.com/Starcounter-Jack/JSON-Patch
498
+ * (c) 2017-2021 Joachim Wester
499
+ * MIT license
500
+ */
501
+ var beforeDict = new WeakMap;
502
+ var Mirror = function() {
503
+ function Mirror2(obj) {
504
+ this.observers = new Map;
505
+ this.obj = obj;
506
+ }
507
+ return Mirror2;
508
+ }();
509
+ var ObserverInfo = function() {
510
+ function ObserverInfo2(callback, observer) {
511
+ this.callback = callback;
512
+ this.observer = observer;
513
+ }
514
+ return ObserverInfo2;
515
+ }();
516
+ function getMirror(obj) {
517
+ return beforeDict.get(obj);
518
+ }
519
+ function getObserverFromMirror(mirror, callback) {
520
+ return mirror.observers.get(callback);
521
+ }
522
+ function removeObserverFromMirror(mirror, observer) {
523
+ mirror.observers.delete(observer.callback);
524
+ }
525
+ function unobserve(root, observer) {
526
+ observer.unobserve();
527
+ }
528
+ function observe(obj, callback) {
529
+ var patches = [];
530
+ var observer;
531
+ var mirror = getMirror(obj);
532
+ if (!mirror) {
533
+ mirror = new Mirror(obj);
534
+ beforeDict.set(obj, mirror);
535
+ } else {
536
+ var observerInfo = getObserverFromMirror(mirror, callback);
537
+ observer = observerInfo && observerInfo.observer;
538
+ }
539
+ if (observer) {
540
+ return observer;
541
+ }
542
+ observer = {};
543
+ mirror.value = _deepClone(obj);
544
+ if (callback) {
545
+ observer.callback = callback;
546
+ observer.next = null;
547
+ var dirtyCheck = function() {
548
+ generate(observer);
549
+ };
550
+ var fastCheck = function() {
551
+ clearTimeout(observer.next);
552
+ observer.next = setTimeout(dirtyCheck);
553
+ };
554
+ if (typeof window !== "undefined") {
555
+ window.addEventListener("mouseup", fastCheck);
556
+ window.addEventListener("keyup", fastCheck);
557
+ window.addEventListener("mousedown", fastCheck);
558
+ window.addEventListener("keydown", fastCheck);
559
+ window.addEventListener("change", fastCheck);
560
+ }
561
+ }
562
+ observer.patches = patches;
563
+ observer.object = obj;
564
+ observer.unobserve = function() {
565
+ generate(observer);
566
+ clearTimeout(observer.next);
567
+ removeObserverFromMirror(mirror, observer);
568
+ if (typeof window !== "undefined") {
569
+ window.removeEventListener("mouseup", fastCheck);
570
+ window.removeEventListener("keyup", fastCheck);
571
+ window.removeEventListener("mousedown", fastCheck);
572
+ window.removeEventListener("keydown", fastCheck);
573
+ window.removeEventListener("change", fastCheck);
574
+ }
575
+ };
576
+ mirror.observers.set(callback, new ObserverInfo(callback, observer));
577
+ return observer;
578
+ }
579
+ function generate(observer, invertible) {
580
+ if (invertible === undefined) {
581
+ invertible = false;
582
+ }
583
+ var mirror = beforeDict.get(observer.object);
584
+ _generate(mirror.value, observer.object, observer.patches, "", invertible);
585
+ if (observer.patches.length) {
586
+ applyPatch(mirror.value, observer.patches);
587
+ }
588
+ var temp = observer.patches;
589
+ if (temp.length > 0) {
590
+ observer.patches = [];
591
+ if (observer.callback) {
592
+ observer.callback(temp);
593
+ }
594
+ }
595
+ return temp;
596
+ }
597
+ function _generate(mirror, obj, patches, path, invertible) {
598
+ if (obj === mirror) {
599
+ return;
600
+ }
601
+ if (typeof obj.toJSON === "function") {
602
+ obj = obj.toJSON();
603
+ }
604
+ var newKeys = _objectKeys(obj);
605
+ var oldKeys = _objectKeys(mirror);
606
+ var changed = false;
607
+ var deleted = false;
608
+ for (var t = oldKeys.length - 1;t >= 0; t--) {
609
+ var key = oldKeys[t];
610
+ var oldVal = mirror[key];
611
+ if (hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
612
+ var newVal = obj[key];
613
+ if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
614
+ _generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key), invertible);
615
+ } else {
616
+ if (oldVal !== newVal) {
617
+ changed = true;
618
+ if (invertible) {
619
+ patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
620
+ }
621
+ patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: _deepClone(newVal) });
622
+ }
623
+ }
624
+ } else if (Array.isArray(mirror) === Array.isArray(obj)) {
625
+ if (invertible) {
626
+ patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
627
+ }
628
+ patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) });
629
+ deleted = true;
630
+ } else {
631
+ if (invertible) {
632
+ patches.push({ op: "test", path, value: mirror });
633
+ }
634
+ patches.push({ op: "replace", path, value: obj });
635
+ changed = true;
636
+ }
637
+ }
638
+ if (!deleted && newKeys.length == oldKeys.length) {
639
+ return;
640
+ }
641
+ for (var t = 0;t < newKeys.length; t++) {
642
+ var key = newKeys[t];
643
+ if (!hasOwnProperty(mirror, key) && obj[key] !== undefined) {
644
+ patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: _deepClone(obj[key]) });
645
+ }
646
+ }
647
+ }
648
+ function compare(tree1, tree2, invertible) {
649
+ if (invertible === undefined) {
650
+ invertible = false;
651
+ }
652
+ var patches = [];
653
+ _generate(tree1, tree2, patches, "", invertible);
654
+ return patches;
655
+ }
656
+ // ../../node_modules/.bun/fast-json-patch@3.1.1/node_modules/fast-json-patch/index.mjs
657
+ var fast_json_patch_default = Object.assign({}, exports_core, exports_duplex, {
658
+ JsonPatchError: PatchError,
659
+ deepClone: _deepClone,
660
+ escapePathComponent,
661
+ unescapePathComponent
662
+ });
663
+
664
+ // src/subscribe.ts
665
+ function subscribe(baseUrl, callback, options) {
666
+ const endpoint = options?.endpoint ?? "/events";
667
+ const url = `${baseUrl}${endpoint}`;
668
+ const slices = {};
669
+ const es = new EventSource(url);
670
+ es.addEventListener("state.initial", (e) => {
671
+ const event = JSON.parse(e.data);
672
+ for (const key of Object.keys(slices))
673
+ delete slices[key];
674
+ Object.assign(slices, event.slices);
675
+ callback({ slices: { ...slices }, event });
676
+ });
677
+ es.addEventListener("state.update", (e) => {
678
+ const event = JSON.parse(e.data);
679
+ if (event.patches && event.patches.length > 0) {
680
+ const current = slices[event.slice] ?? {};
681
+ const cloned = structuredClone(current);
682
+ const result = applyPatch(cloned, event.patches);
683
+ slices[event.slice] = result.newDocument;
684
+ } else if ("value" in event) {
685
+ slices[event.slice] = event.value;
686
+ }
687
+ callback({ slices: { ...slices }, event });
688
+ });
689
+ es.addEventListener("execution.status", (e) => {
690
+ const event = JSON.parse(e.data);
691
+ callback({ slices: { ...slices }, event });
692
+ });
693
+ es.addEventListener("heartbeat", (e) => {
694
+ const event = JSON.parse(e.data);
695
+ callback({ slices: { ...slices }, event });
696
+ });
697
+ es.addEventListener("custom-event", (e) => {
698
+ const event = JSON.parse(e.data);
699
+ callback({ slices: { ...slices }, event });
700
+ });
701
+ return () => {
702
+ es.close();
703
+ };
704
+ }
705
+
706
+ // src/client.ts
707
+ function createClient(baseUrl, options) {
708
+ const _fetch = options?.fetch ?? globalThis.fetch;
709
+ const _headers = options?.headers ?? {};
710
+ const base = baseUrl.replace(/\/$/, "");
711
+ async function get(path) {
712
+ const res = await _fetch(`${base}${path}`, {
713
+ method: "GET",
714
+ headers: { ...headers(), Accept: "application/json" }
715
+ });
716
+ if (!res.ok) {
717
+ const body = await safeJson(res);
718
+ throw new GizmoClientError(res.status, errorMessage(res, body), body);
719
+ }
720
+ return res.json();
721
+ }
722
+ async function post(path, body) {
723
+ const res = await _fetch(`${base}${path}`, {
724
+ method: "POST",
725
+ headers: { ...headers(), "Content-Type": "application/json", Accept: "application/json" },
726
+ body: body !== undefined ? JSON.stringify(body) : undefined
727
+ });
728
+ if (!res.ok) {
729
+ const errBody = await safeJson(res);
730
+ throw new GizmoClientError(res.status, errorMessage(res, errBody), errBody);
731
+ }
732
+ return res.json();
733
+ }
734
+ function headers() {
735
+ return { ..._headers };
736
+ }
737
+ let manifestCache = null;
738
+ const runs = {
739
+ async list(params) {
740
+ const qs = buildQuery(params);
741
+ const res = await get(`/runs${qs}`);
742
+ return res.runs;
743
+ },
744
+ async get(executionId) {
745
+ return get(`/runs/${encodeURIComponent(executionId)}`);
746
+ },
747
+ async actions(executionId) {
748
+ const run = await runs.get(executionId);
749
+ return run.actions;
750
+ },
751
+ async cancel(executionId) {
752
+ return post(`/runs/${encodeURIComponent(executionId)}/cancel`);
753
+ },
754
+ async hydrate(executionId, opts) {
755
+ return post("/hydrate", { executionId, ...opts });
756
+ }
757
+ };
758
+ const approvals = {
759
+ async list() {
760
+ const res = await get("/approvals");
761
+ return res.approvals;
762
+ },
763
+ async history() {
764
+ const res = await get("/approvals/history");
765
+ return res.history;
766
+ },
767
+ async get(id) {
768
+ const res = await get(`/approvals/${encodeURIComponent(id)}`);
769
+ return res.approval;
770
+ },
771
+ async approve(id, reason) {
772
+ const res = await post(`/approvals/${encodeURIComponent(id)}`, { decision: "approve", reason });
773
+ return res.approval;
774
+ },
775
+ async reject(id, reason) {
776
+ const res = await post(`/approvals/${encodeURIComponent(id)}`, { decision: "reject", reason });
777
+ return res.approval;
778
+ }
779
+ };
780
+ return {
781
+ async discover() {
782
+ if (manifestCache)
783
+ return manifestCache;
784
+ manifestCache = await get("/.well-known/manifest.json");
785
+ return manifestCache;
786
+ },
787
+ async invoke(input) {
788
+ return post("/invoke", { input });
789
+ },
790
+ async abort() {
791
+ return post("/abort");
792
+ },
793
+ async state(slice) {
794
+ const path = slice ? `/state/${encodeURIComponent(slice)}` : "/state";
795
+ return get(path);
796
+ },
797
+ subscribe(callback, opts) {
798
+ return subscribe(base, callback, opts);
799
+ },
800
+ async health() {
801
+ return get("/health");
802
+ },
803
+ async dispatch(action) {
804
+ return post("/dispatch", action);
805
+ },
806
+ runs,
807
+ approvals
808
+ };
809
+ }
810
+ function buildQuery(params) {
811
+ if (!params)
812
+ return "";
813
+ const entries = Object.entries(params).filter(([, v]) => v !== undefined && v !== null);
814
+ if (entries.length === 0)
815
+ return "";
816
+ const qs = entries.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join("&");
817
+ return `?${qs}`;
818
+ }
819
+ async function safeJson(res) {
820
+ try {
821
+ return await res.json();
822
+ } catch {
823
+ return;
824
+ }
825
+ }
826
+ function errorMessage(res, body) {
827
+ if (body && typeof body === "object" && "error" in body) {
828
+ return String(body.error);
829
+ }
830
+ return `HTTP ${res.status}`;
831
+ }
832
+ export {
833
+ createClient,
834
+ GizmoClientError
835
+ };