@granular-software/sdk 0.4.81 → 0.4.82
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/agent-evals.d.mts +2 -1
- package/dist/agent-evals.d.ts +2 -1
- package/dist/agent-evals.js +1343 -442
- package/dist/agent-evals.js.map +1 -1
- package/dist/agent-evals.mjs +1343 -442
- package/dist/agent-evals.mjs.map +1 -1
- package/dist/cli/index.js +1377 -1021
- package/dist/{client-CQU7xBRK.d.ts → client-BY66n-mS.d.ts} +14 -0
- package/dist/{client--FEdH24t.d.mts → client-BhjU5ZfT.d.mts} +14 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +778 -585
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +778 -585
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import * as Automerge from '@automerge/automerge';
|
|
2
2
|
|
|
3
|
+
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
13
|
var __esm = (fn, res) => function __init() {
|
|
6
14
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
15
|
};
|
|
@@ -9,6 +17,306 @@ var __export = (target, all) => {
|
|
|
9
17
|
for (var name in all)
|
|
10
18
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
19
|
};
|
|
20
|
+
var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
|
|
21
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
22
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
23
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
24
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
25
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
26
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
29
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
30
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
31
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
32
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
33
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
34
|
+
return __privateGet(this, extra);
|
|
35
|
+
}, set [name](x) {
|
|
36
|
+
return __privateSet(this, extra, x);
|
|
37
|
+
} }, name));
|
|
38
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
39
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
40
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
41
|
+
if (k) {
|
|
42
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
43
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
44
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
45
|
+
}
|
|
46
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
47
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
48
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
49
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
50
|
+
}
|
|
51
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
52
|
+
};
|
|
53
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
54
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
55
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
56
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
57
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
58
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
59
|
+
|
|
60
|
+
// ../fractory/dist/annotations.js
|
|
61
|
+
function publish(event, adapter) {
|
|
62
|
+
try {
|
|
63
|
+
adapter?.emit(event);
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
for (const listener of listeners) {
|
|
67
|
+
try {
|
|
68
|
+
listener(event);
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function identity(value) {
|
|
74
|
+
if (!value.trim())
|
|
75
|
+
throw new Error("Fractal identity must not be empty");
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
function Block(id3, options = {}) {
|
|
79
|
+
const definition = typeof id3 === "string" ? { ...options, id: identity(id3) } : { ...id3, id: identity(id3.id) };
|
|
80
|
+
return (target, _context) => {
|
|
81
|
+
blocks.set(target, definition);
|
|
82
|
+
return target;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function makeInterface(owner, name, options) {
|
|
86
|
+
return Object.freeze({
|
|
87
|
+
[interfaceBrand]: true,
|
|
88
|
+
name,
|
|
89
|
+
options: Object.freeze({ ...options }),
|
|
90
|
+
get blockId() {
|
|
91
|
+
const definition = blocks.get(owner());
|
|
92
|
+
if (!definition)
|
|
93
|
+
throw new Error(`Interface ${name} needs an annotated block`);
|
|
94
|
+
return definition.id;
|
|
95
|
+
},
|
|
96
|
+
get id() {
|
|
97
|
+
return options.id || `${this.blockId}::${name}`;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function Interface(options = {}, details = {}) {
|
|
102
|
+
if (typeof options === "string") {
|
|
103
|
+
const id3 = identity(options), name = id3.split("/").slice(-1)[0];
|
|
104
|
+
if (details.parent)
|
|
105
|
+
return makeInterface(details.parent, name, { ...details, id: id3 });
|
|
106
|
+
return Object.freeze({
|
|
107
|
+
[interfaceBrand]: true,
|
|
108
|
+
id: id3,
|
|
109
|
+
name,
|
|
110
|
+
blockId: id3.includes("/") ? id3.slice(0, id3.lastIndexOf("/")) : "factory",
|
|
111
|
+
options: Object.freeze({ ...details, id: id3 })
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if ("parent" in options)
|
|
115
|
+
return makeInterface(options.parent, identity(options.id).split("/").slice(-1)[0], options);
|
|
116
|
+
return interfaceDecorator(options);
|
|
117
|
+
}
|
|
118
|
+
function interfaceDecorator(options) {
|
|
119
|
+
function decorate(target, context) {
|
|
120
|
+
if (typeof context === "object") {
|
|
121
|
+
if (!context.static || context.private)
|
|
122
|
+
throw new Error("@Interface requires a public static field");
|
|
123
|
+
context.addInitializer(function() {
|
|
124
|
+
const owner = this;
|
|
125
|
+
if (!owner[context.name]?.[interfaceBrand])
|
|
126
|
+
Object.defineProperty(owner, context.name, {
|
|
127
|
+
value: makeInterface(() => owner, String(context.name), options),
|
|
128
|
+
writable: false,
|
|
129
|
+
configurable: true
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
return function() {
|
|
133
|
+
return makeInterface(() => this, String(context.name), options);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const value = makeInterface(() => target, String(context), options);
|
|
137
|
+
Object.defineProperty(target, context, {
|
|
138
|
+
value,
|
|
139
|
+
writable: false,
|
|
140
|
+
configurable: true
|
|
141
|
+
});
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
return decorate;
|
|
145
|
+
}
|
|
146
|
+
function validate(parser, value) {
|
|
147
|
+
const result = parser?.parse(value);
|
|
148
|
+
if (result && typeof result.then === "function") {
|
|
149
|
+
void Promise.resolve(result).catch(() => {
|
|
150
|
+
});
|
|
151
|
+
throw new Error("Fractal runtime validators must be synchronous");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function wrap(fn, name, reference, process2, options = {}) {
|
|
155
|
+
const previous = wrappers.get(fn);
|
|
156
|
+
if (previous) {
|
|
157
|
+
fn = previous.original;
|
|
158
|
+
reference ||= previous.reference;
|
|
159
|
+
process2 ||= previous.process;
|
|
160
|
+
options = { ...previous.options, ...options };
|
|
161
|
+
}
|
|
162
|
+
const wrapped = function(...args) {
|
|
163
|
+
const api = reference?.();
|
|
164
|
+
if (reference && (!api || api[interfaceBrand] !== true))
|
|
165
|
+
throw new Error("@Method requires an initialized typed interface reference");
|
|
166
|
+
const adapter = host;
|
|
167
|
+
if (!listeners.size && !options.contract && !api?.options.auth)
|
|
168
|
+
return fn.apply(this, args);
|
|
169
|
+
const id3 = crypto.randomUUID();
|
|
170
|
+
const frame = {
|
|
171
|
+
targetId: process2?.id || `${api.id}#${options.name || name || fn.name || "call"}`,
|
|
172
|
+
traceId: id3,
|
|
173
|
+
runId: id3
|
|
174
|
+
};
|
|
175
|
+
let codeRevision;
|
|
176
|
+
try {
|
|
177
|
+
codeRevision = adapter?.codeRevision?.();
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
const started = performance.now();
|
|
181
|
+
let terminal = false;
|
|
182
|
+
const base = {
|
|
183
|
+
targetId: frame.targetId,
|
|
184
|
+
...{},
|
|
185
|
+
id: id3,
|
|
186
|
+
traceId: frame.traceId,
|
|
187
|
+
...codeRevision ? { codeRevision } : {},
|
|
188
|
+
runId: frame.runId,
|
|
189
|
+
...{},
|
|
190
|
+
...{},
|
|
191
|
+
blockId: process2?.id || api.blockId,
|
|
192
|
+
...api ? { interfaceId: api.id } : {},
|
|
193
|
+
method: options.name || name || fn.name || "call"
|
|
194
|
+
};
|
|
195
|
+
const emit = (status, failure) => {
|
|
196
|
+
if (status !== "started") {
|
|
197
|
+
if (terminal)
|
|
198
|
+
return;
|
|
199
|
+
terminal = true;
|
|
200
|
+
frame.finished = true;
|
|
201
|
+
}
|
|
202
|
+
publish({
|
|
203
|
+
...base,
|
|
204
|
+
timestamp: Date.now(),
|
|
205
|
+
status,
|
|
206
|
+
...status !== "started" ? { durationMs: performance.now() - started } : {},
|
|
207
|
+
...failure ? { failure } : {}
|
|
208
|
+
}, adapter);
|
|
209
|
+
};
|
|
210
|
+
const execute = () => {
|
|
211
|
+
emit("started");
|
|
212
|
+
let phase = "auth";
|
|
213
|
+
const failed = (error) => {
|
|
214
|
+
emit("failed", phase);
|
|
215
|
+
throw error;
|
|
216
|
+
};
|
|
217
|
+
const invoke = () => {
|
|
218
|
+
phase = "input";
|
|
219
|
+
validate(options.contract?.args, args);
|
|
220
|
+
phase = "execution";
|
|
221
|
+
const value = fn.apply(this, args);
|
|
222
|
+
const complete = (result) => {
|
|
223
|
+
phase = "output";
|
|
224
|
+
validate(options.contract?.result, result);
|
|
225
|
+
emit("completed");
|
|
226
|
+
return result;
|
|
227
|
+
};
|
|
228
|
+
if (value && typeof value.then === "function") {
|
|
229
|
+
if (options.contract?.result)
|
|
230
|
+
return Promise.resolve(value).then(complete).catch(failed);
|
|
231
|
+
void Promise.resolve(value).then(() => emit("completed"), () => emit("failed", "execution"));
|
|
232
|
+
return value;
|
|
233
|
+
}
|
|
234
|
+
return complete(value);
|
|
235
|
+
};
|
|
236
|
+
try {
|
|
237
|
+
const authorized = api?.options.auth?.({
|
|
238
|
+
receiver: this,
|
|
239
|
+
args,
|
|
240
|
+
context: adapter?.context?.()
|
|
241
|
+
});
|
|
242
|
+
if (authorized && typeof authorized === "object" && typeof authorized.then === "function") {
|
|
243
|
+
if (fn.constructor.name !== "AsyncFunction") {
|
|
244
|
+
void authorized.catch(() => {
|
|
245
|
+
});
|
|
246
|
+
throw new Error("Async auth requires an async method");
|
|
247
|
+
}
|
|
248
|
+
return authorized.then((allowed) => {
|
|
249
|
+
if (allowed === false)
|
|
250
|
+
throw new FactoryViolation("auth", false);
|
|
251
|
+
return invoke();
|
|
252
|
+
}).catch(failed);
|
|
253
|
+
}
|
|
254
|
+
if (authorized === false)
|
|
255
|
+
throw new FactoryViolation("auth", false);
|
|
256
|
+
return invoke();
|
|
257
|
+
} catch (error) {
|
|
258
|
+
return failed(error);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const run = () => execute();
|
|
262
|
+
try {
|
|
263
|
+
return run();
|
|
264
|
+
} catch (error) {
|
|
265
|
+
if (fn.constructor.name === "AsyncFunction")
|
|
266
|
+
return Promise.reject(error);
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
Object.defineProperty(wrapped, "name", {
|
|
271
|
+
value: options.name || name || fn.name,
|
|
272
|
+
configurable: true
|
|
273
|
+
});
|
|
274
|
+
Object.defineProperty(wrapped, "length", {
|
|
275
|
+
value: fn.length,
|
|
276
|
+
configurable: true
|
|
277
|
+
});
|
|
278
|
+
if (process2)
|
|
279
|
+
blocks.set(wrapped, process2);
|
|
280
|
+
wrappers.set(wrapped, { original: fn, reference, process: process2, options });
|
|
281
|
+
return wrapped;
|
|
282
|
+
}
|
|
283
|
+
function callableDecorator(reference, process2, options = {}) {
|
|
284
|
+
function decorate(target, context, descriptor) {
|
|
285
|
+
if (descriptor) {
|
|
286
|
+
descriptor.value = wrap(descriptor.value, String(context), reference, process2, options);
|
|
287
|
+
return descriptor;
|
|
288
|
+
}
|
|
289
|
+
const fn = target;
|
|
290
|
+
return wrap(fn, typeof context === "object" ? String(context.name) : fn.name, reference, process2, options);
|
|
291
|
+
}
|
|
292
|
+
return decorate;
|
|
293
|
+
}
|
|
294
|
+
function Method(reference, options = {}) {
|
|
295
|
+
return callableDecorator(reference, void 0, options);
|
|
296
|
+
}
|
|
297
|
+
function Process(id3, options = {}) {
|
|
298
|
+
const definition = typeof id3 === "string" ? { ...options, id: identity(id3) } : { ...id3, id: identity(id3.id) };
|
|
299
|
+
return callableDecorator(void 0, definition);
|
|
300
|
+
}
|
|
301
|
+
var interfaceBrand, blocks, wrappers, listeners, host, FactoryViolation;
|
|
302
|
+
var init_annotations = __esm({
|
|
303
|
+
"../fractory/dist/annotations.js"() {
|
|
304
|
+
interfaceBrand = Symbol("fractal.interface");
|
|
305
|
+
blocks = /* @__PURE__ */ new WeakMap();
|
|
306
|
+
wrappers = /* @__PURE__ */ new WeakMap();
|
|
307
|
+
listeners = /* @__PURE__ */ new Set();
|
|
308
|
+
FactoryViolation = class extends Error {
|
|
309
|
+
phase;
|
|
310
|
+
cause;
|
|
311
|
+
constructor(phase, cause) {
|
|
312
|
+
super(`Fractal ${phase} requirement failed`);
|
|
313
|
+
this.phase = phase;
|
|
314
|
+
this.cause = cause;
|
|
315
|
+
this.name = "FactoryViolation";
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
});
|
|
12
320
|
|
|
13
321
|
// ../policy-engine/src/index.ts
|
|
14
322
|
var src_exports = {};
|
|
@@ -698,138 +1006,6 @@ function normalizeSourceProfiles(sources) {
|
|
|
698
1006
|
);
|
|
699
1007
|
return [...getBuiltinPermissionProfiles(), ...nonBuiltin];
|
|
700
1008
|
}
|
|
701
|
-
async function compilePolicyBundle(input) {
|
|
702
|
-
const errors = [];
|
|
703
|
-
const warnings = [];
|
|
704
|
-
const effects = [...input.effects].sort(
|
|
705
|
-
(left, right) => left.effectKey.localeCompare(right.effectKey)
|
|
706
|
-
);
|
|
707
|
-
const profiles = flattenProfiles(
|
|
708
|
-
normalizeSourceProfiles(input.profileSources),
|
|
709
|
-
errors
|
|
710
|
-
);
|
|
711
|
-
const manifestRules = {};
|
|
712
|
-
for (const effect of effects) {
|
|
713
|
-
try {
|
|
714
|
-
const rules = manifestPolicyRulesForEffect(effect, input.manifestId);
|
|
715
|
-
if (rules.length > 0) manifestRules[effect.effectKey] = rules;
|
|
716
|
-
} catch (error) {
|
|
717
|
-
errors.push(String(error instanceof Error ? error.message : error));
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
const compiledProfiles = {};
|
|
721
|
-
for (const profile of profiles) {
|
|
722
|
-
try {
|
|
723
|
-
const defaultActionPolicy = profile.defaults?.actionPolicy;
|
|
724
|
-
if (defaultActionPolicy !== void 0 && !normalizeDecision(defaultActionPolicy)) {
|
|
725
|
-
throw new Error(
|
|
726
|
-
`Permission profile "${profile.name}" has invalid defaults.actionPolicy`
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
const compiled = compileProfile({
|
|
730
|
-
profile,
|
|
731
|
-
effects,
|
|
732
|
-
manifestRules,
|
|
733
|
-
warnings
|
|
734
|
-
});
|
|
735
|
-
compiled.digest = await digestJson({
|
|
736
|
-
profile: compiled.flattened,
|
|
737
|
-
actionRules: compiled.actionRules,
|
|
738
|
-
defaultActionPolicy: compiled.defaultActionPolicy
|
|
739
|
-
});
|
|
740
|
-
compiledProfiles[profile.name] = compiled;
|
|
741
|
-
} catch (error) {
|
|
742
|
-
errors.push(String(error instanceof Error ? error.message : error));
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
const permissionProfilesDigest = await digestJson(
|
|
746
|
-
Object.values(compiledProfiles).map((profile) => ({
|
|
747
|
-
name: profile.name,
|
|
748
|
-
digest: profile.digest,
|
|
749
|
-
source: profile.source
|
|
750
|
-
}))
|
|
751
|
-
);
|
|
752
|
-
const bundleWithoutDigest = {
|
|
753
|
-
schemaVersion: 1,
|
|
754
|
-
buildId: input.buildId,
|
|
755
|
-
sandboxId: input.sandboxId,
|
|
756
|
-
manifestDigest: input.manifestDigest,
|
|
757
|
-
permissionProfilesDigest,
|
|
758
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
759
|
-
effects: effects.map((effect) => ({
|
|
760
|
-
effectKey: effect.effectKey,
|
|
761
|
-
name: effect.name,
|
|
762
|
-
attachedClass: normalizeAttachedClass(effect.attachedClass),
|
|
763
|
-
isStatic: effect.isStatic === true
|
|
764
|
-
})),
|
|
765
|
-
manifestRules,
|
|
766
|
-
profiles: compiledProfiles
|
|
767
|
-
};
|
|
768
|
-
const bundleDigest = await digestJson(bundleWithoutDigest);
|
|
769
|
-
return {
|
|
770
|
-
bundle: { ...bundleWithoutDigest, bundleDigest },
|
|
771
|
-
errors,
|
|
772
|
-
warnings
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
function evaluateCompiledPolicyBundle(input) {
|
|
776
|
-
const profile = input.bundle.profiles[input.profileName];
|
|
777
|
-
if (!profile) {
|
|
778
|
-
return {
|
|
779
|
-
outcome: "deny",
|
|
780
|
-
matches: [
|
|
781
|
-
{
|
|
782
|
-
id: "missing-profile",
|
|
783
|
-
outcome: "deny",
|
|
784
|
-
origin: {
|
|
785
|
-
kind: "permissionProfile",
|
|
786
|
-
profileName: input.profileName,
|
|
787
|
-
source: "permissionProfile"
|
|
788
|
-
},
|
|
789
|
-
reason: `Permission profile "${input.profileName}" does not exist in this version`,
|
|
790
|
-
summary: `Permission profile "${input.profileName}" does not exist in this version`
|
|
791
|
-
}
|
|
792
|
-
]
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
if (!profile.actionVisibility.includes(input.effectKey)) {
|
|
796
|
-
return {
|
|
797
|
-
outcome: "deny",
|
|
798
|
-
matches: [
|
|
799
|
-
{
|
|
800
|
-
id: "action-not-visible",
|
|
801
|
-
outcome: "deny",
|
|
802
|
-
origin: {
|
|
803
|
-
kind: "permissionProfile",
|
|
804
|
-
profileName: input.profileName,
|
|
805
|
-
source: profile.source
|
|
806
|
-
},
|
|
807
|
-
reason: `Action ${input.effectKey} is not visible for ${input.profileName}`,
|
|
808
|
-
summary: `Action ${input.effectKey} is not visible for ${input.profileName}`
|
|
809
|
-
}
|
|
810
|
-
]
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
const decision = evaluatePolicies({
|
|
814
|
-
manifestRules: input.bundle.manifestRules[input.effectKey] || [],
|
|
815
|
-
profileRules: profile.actionRules[input.effectKey] || [],
|
|
816
|
-
defaultActionPolicy: profile.defaultActionPolicy,
|
|
817
|
-
context: input.context
|
|
818
|
-
});
|
|
819
|
-
return {
|
|
820
|
-
outcome: decision.outcome,
|
|
821
|
-
matches: decision.matches.map(
|
|
822
|
-
(match) => match.id === `profile-default-${decision.outcome}` ? {
|
|
823
|
-
...match,
|
|
824
|
-
origin: {
|
|
825
|
-
kind: "permissionProfile",
|
|
826
|
-
profileName: profile.name,
|
|
827
|
-
source: profile.source
|
|
828
|
-
}
|
|
829
|
-
} : match
|
|
830
|
-
)
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
1009
|
function extractManifestEffects(manifest) {
|
|
834
1010
|
const effects = [];
|
|
835
1011
|
for (const volume of manifest.volumes || []) {
|
|
@@ -853,11 +1029,156 @@ function extractManifestEffects(manifest) {
|
|
|
853
1029
|
function listVisibleActionsForProfile(bundle, profileName) {
|
|
854
1030
|
return [...bundle.profiles[profileName]?.actionVisibility || []];
|
|
855
1031
|
}
|
|
856
|
-
var DECISIONS, BUILTIN_PROFILE_NAMES;
|
|
1032
|
+
var DECISIONS, BUILTIN_PROFILE_NAMES, compilePolicyBundle, evaluateCompiledPolicyBundle;
|
|
857
1033
|
var init_src = __esm({
|
|
858
1034
|
"../policy-engine/src/index.ts"() {
|
|
1035
|
+
init_annotations();
|
|
859
1036
|
DECISIONS = /* @__PURE__ */ new Set(["allow", "confirm", "deny"]);
|
|
860
1037
|
BUILTIN_PROFILE_NAMES = ["allow-all", "confirm-all", "deny-all"];
|
|
1038
|
+
compilePolicyBundle = Process({
|
|
1039
|
+
description: "Compile product permission rules into a bundle that runtime checks can evaluate.",
|
|
1040
|
+
id: "granular-product/compilation/metamodels-policy-compilation/compile",
|
|
1041
|
+
label: "Compile policy bundle",
|
|
1042
|
+
benchmarks: ["./compile.bench.ts"],
|
|
1043
|
+
tests: ["./index.test.ts"]
|
|
1044
|
+
})(async function compilePolicyBundle2(input) {
|
|
1045
|
+
const errors = [];
|
|
1046
|
+
const warnings = [];
|
|
1047
|
+
const effects = [...input.effects].sort(
|
|
1048
|
+
(left, right) => left.effectKey.localeCompare(right.effectKey)
|
|
1049
|
+
);
|
|
1050
|
+
const profiles = flattenProfiles(
|
|
1051
|
+
normalizeSourceProfiles(input.profileSources),
|
|
1052
|
+
errors
|
|
1053
|
+
);
|
|
1054
|
+
const manifestRules = {};
|
|
1055
|
+
for (const effect of effects) {
|
|
1056
|
+
try {
|
|
1057
|
+
const rules = manifestPolicyRulesForEffect(effect, input.manifestId);
|
|
1058
|
+
if (rules.length > 0) manifestRules[effect.effectKey] = rules;
|
|
1059
|
+
} catch (error) {
|
|
1060
|
+
errors.push(String(error instanceof Error ? error.message : error));
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
const compiledProfiles = {};
|
|
1064
|
+
for (const profile of profiles) {
|
|
1065
|
+
try {
|
|
1066
|
+
const defaultActionPolicy = profile.defaults?.actionPolicy;
|
|
1067
|
+
if (defaultActionPolicy !== void 0 && !normalizeDecision(defaultActionPolicy)) {
|
|
1068
|
+
throw new Error(
|
|
1069
|
+
`Permission profile "${profile.name}" has invalid defaults.actionPolicy`
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
const compiled = compileProfile({
|
|
1073
|
+
profile,
|
|
1074
|
+
effects,
|
|
1075
|
+
manifestRules,
|
|
1076
|
+
warnings
|
|
1077
|
+
});
|
|
1078
|
+
compiled.digest = await digestJson({
|
|
1079
|
+
profile: compiled.flattened,
|
|
1080
|
+
actionRules: compiled.actionRules,
|
|
1081
|
+
defaultActionPolicy: compiled.defaultActionPolicy
|
|
1082
|
+
});
|
|
1083
|
+
compiledProfiles[profile.name] = compiled;
|
|
1084
|
+
} catch (error) {
|
|
1085
|
+
errors.push(String(error instanceof Error ? error.message : error));
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
const permissionProfilesDigest = await digestJson(
|
|
1089
|
+
Object.values(compiledProfiles).map((profile) => ({
|
|
1090
|
+
name: profile.name,
|
|
1091
|
+
digest: profile.digest,
|
|
1092
|
+
source: profile.source
|
|
1093
|
+
}))
|
|
1094
|
+
);
|
|
1095
|
+
const bundleWithoutDigest = {
|
|
1096
|
+
schemaVersion: 1,
|
|
1097
|
+
buildId: input.buildId,
|
|
1098
|
+
sandboxId: input.sandboxId,
|
|
1099
|
+
manifestDigest: input.manifestDigest,
|
|
1100
|
+
permissionProfilesDigest,
|
|
1101
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1102
|
+
effects: effects.map((effect) => ({
|
|
1103
|
+
effectKey: effect.effectKey,
|
|
1104
|
+
name: effect.name,
|
|
1105
|
+
attachedClass: normalizeAttachedClass(effect.attachedClass),
|
|
1106
|
+
isStatic: effect.isStatic === true
|
|
1107
|
+
})),
|
|
1108
|
+
manifestRules,
|
|
1109
|
+
profiles: compiledProfiles
|
|
1110
|
+
};
|
|
1111
|
+
const bundleDigest = await digestJson(bundleWithoutDigest);
|
|
1112
|
+
return {
|
|
1113
|
+
bundle: { ...bundleWithoutDigest, bundleDigest },
|
|
1114
|
+
errors,
|
|
1115
|
+
warnings
|
|
1116
|
+
};
|
|
1117
|
+
});
|
|
1118
|
+
evaluateCompiledPolicyBundle = Process({
|
|
1119
|
+
description: "Evaluate compiled permission rules for an action and its current context.",
|
|
1120
|
+
id: "granular-product/effects/authorization-contracts/compiled-evaluation",
|
|
1121
|
+
label: "Evaluate compiled policies",
|
|
1122
|
+
benchmarks: ["./evaluation.bench.ts"],
|
|
1123
|
+
tests: ["./index.test.ts"]
|
|
1124
|
+
})(function evaluateCompiledPolicyBundle2(input) {
|
|
1125
|
+
const profile = input.bundle.profiles[input.profileName];
|
|
1126
|
+
if (!profile) {
|
|
1127
|
+
return {
|
|
1128
|
+
outcome: "deny",
|
|
1129
|
+
matches: [
|
|
1130
|
+
{
|
|
1131
|
+
id: "missing-profile",
|
|
1132
|
+
outcome: "deny",
|
|
1133
|
+
origin: {
|
|
1134
|
+
kind: "permissionProfile",
|
|
1135
|
+
profileName: input.profileName,
|
|
1136
|
+
source: "permissionProfile"
|
|
1137
|
+
},
|
|
1138
|
+
reason: `Permission profile "${input.profileName}" does not exist in this version`,
|
|
1139
|
+
summary: `Permission profile "${input.profileName}" does not exist in this version`
|
|
1140
|
+
}
|
|
1141
|
+
]
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
if (!profile.actionVisibility.includes(input.effectKey)) {
|
|
1145
|
+
return {
|
|
1146
|
+
outcome: "deny",
|
|
1147
|
+
matches: [
|
|
1148
|
+
{
|
|
1149
|
+
id: "action-not-visible",
|
|
1150
|
+
outcome: "deny",
|
|
1151
|
+
origin: {
|
|
1152
|
+
kind: "permissionProfile",
|
|
1153
|
+
profileName: input.profileName,
|
|
1154
|
+
source: profile.source
|
|
1155
|
+
},
|
|
1156
|
+
reason: `Action ${input.effectKey} is not visible for ${input.profileName}`,
|
|
1157
|
+
summary: `Action ${input.effectKey} is not visible for ${input.profileName}`
|
|
1158
|
+
}
|
|
1159
|
+
]
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
const decision = evaluatePolicies({
|
|
1163
|
+
manifestRules: input.bundle.manifestRules[input.effectKey] || [],
|
|
1164
|
+
profileRules: profile.actionRules[input.effectKey] || [],
|
|
1165
|
+
defaultActionPolicy: profile.defaultActionPolicy,
|
|
1166
|
+
context: input.context
|
|
1167
|
+
});
|
|
1168
|
+
return {
|
|
1169
|
+
outcome: decision.outcome,
|
|
1170
|
+
matches: decision.matches.map(
|
|
1171
|
+
(match) => match.id === `profile-default-${decision.outcome}` ? {
|
|
1172
|
+
...match,
|
|
1173
|
+
origin: {
|
|
1174
|
+
kind: "permissionProfile",
|
|
1175
|
+
profileName: profile.name,
|
|
1176
|
+
source: profile.source
|
|
1177
|
+
}
|
|
1178
|
+
} : match
|
|
1179
|
+
)
|
|
1180
|
+
};
|
|
1181
|
+
});
|
|
861
1182
|
}
|
|
862
1183
|
});
|
|
863
1184
|
|
|
@@ -9140,7 +9461,7 @@ function requireTransientFeedbackItem(value) {
|
|
|
9140
9461
|
}
|
|
9141
9462
|
return item;
|
|
9142
9463
|
}
|
|
9143
|
-
function createFeedPublisher(
|
|
9464
|
+
function createFeedPublisher(publish2) {
|
|
9144
9465
|
const makeHandle = (initial) => {
|
|
9145
9466
|
let current = initial;
|
|
9146
9467
|
let mutationQueue = Promise.resolve();
|
|
@@ -9166,7 +9487,7 @@ function createFeedPublisher(publish) {
|
|
|
9166
9487
|
const reservedOperationId = options.operationId || operationId("feed_transient_update");
|
|
9167
9488
|
const reservedOptions = { ...options };
|
|
9168
9489
|
return enqueueMutation(async () => {
|
|
9169
|
-
const response = await
|
|
9490
|
+
const response = await publish2("feed.transient.update", {
|
|
9170
9491
|
transientId: current.id,
|
|
9171
9492
|
expectedRevision: current.revision,
|
|
9172
9493
|
text: text6,
|
|
@@ -9181,7 +9502,7 @@ function createFeedPublisher(publish) {
|
|
|
9181
9502
|
const reservedOperationId = options.operationId || operationId("feed_transient_settle");
|
|
9182
9503
|
const reservedOptions = { ...options };
|
|
9183
9504
|
return enqueueMutation(async () => {
|
|
9184
|
-
const response = await
|
|
9505
|
+
const response = await publish2("feed.transient.settle", {
|
|
9185
9506
|
transientId: current.id,
|
|
9186
9507
|
expectedRevision: current.revision,
|
|
9187
9508
|
...text6 === void 0 ? {} : { text: text6 },
|
|
@@ -9204,7 +9525,7 @@ function createFeedPublisher(publish) {
|
|
|
9204
9525
|
return {
|
|
9205
9526
|
async feedback(text6, options = {}) {
|
|
9206
9527
|
return requireFeedbackItem(
|
|
9207
|
-
await
|
|
9528
|
+
await publish2("feed.feedback", {
|
|
9208
9529
|
text: text6,
|
|
9209
9530
|
...options,
|
|
9210
9531
|
operationId: options.operationId || operationId("feed_feedback")
|
|
@@ -9213,7 +9534,7 @@ function createFeedPublisher(publish) {
|
|
|
9213
9534
|
},
|
|
9214
9535
|
async transientFeedback(text6, options = {}) {
|
|
9215
9536
|
const item = requireTransientFeedbackItem(
|
|
9216
|
-
await
|
|
9537
|
+
await publish2("feed.transient.create", {
|
|
9217
9538
|
text: text6,
|
|
9218
9539
|
...options,
|
|
9219
9540
|
operationId: options.operationId || operationId("feed_transient_create")
|
|
@@ -12548,11 +12869,11 @@ var Session = class {
|
|
|
12548
12869
|
}
|
|
12549
12870
|
this.eventListeners.get("effects:changed").push(handler);
|
|
12550
12871
|
return () => {
|
|
12551
|
-
const
|
|
12552
|
-
if (
|
|
12872
|
+
const listeners2 = this.eventListeners.get("effects:changed");
|
|
12873
|
+
if (listeners2) {
|
|
12553
12874
|
this.eventListeners.set(
|
|
12554
12875
|
"effects:changed",
|
|
12555
|
-
|
|
12876
|
+
listeners2.filter((h) => h !== handler)
|
|
12556
12877
|
);
|
|
12557
12878
|
}
|
|
12558
12879
|
};
|
|
@@ -12567,11 +12888,11 @@ var Session = class {
|
|
|
12567
12888
|
}
|
|
12568
12889
|
this.eventListeners.get("tools:changed").push(handler);
|
|
12569
12890
|
return () => {
|
|
12570
|
-
const
|
|
12571
|
-
if (
|
|
12891
|
+
const listeners2 = this.eventListeners.get("tools:changed");
|
|
12892
|
+
if (listeners2) {
|
|
12572
12893
|
this.eventListeners.set(
|
|
12573
12894
|
"tools:changed",
|
|
12574
|
-
|
|
12895
|
+
listeners2.filter((h) => h !== handler)
|
|
12575
12896
|
);
|
|
12576
12897
|
}
|
|
12577
12898
|
};
|
|
@@ -14995,6 +15316,7 @@ var WSClient = class {
|
|
|
14995
15316
|
};
|
|
14996
15317
|
|
|
14997
15318
|
// src/client.ts
|
|
15319
|
+
init_annotations();
|
|
14998
15320
|
var DEFAULT_CONVERSATION_SESSION_LIST_LIMIT = 100;
|
|
14999
15321
|
var MAX_CONVERSATION_SESSION_LIST_LIMIT = 500;
|
|
15000
15322
|
function requireUserEnvironmentSequence(value, field) {
|
|
@@ -15136,7 +15458,11 @@ function isUnsupportedEffectCatalogMutation(error) {
|
|
|
15136
15458
|
const message = error instanceof Error ? error.message : String(error);
|
|
15137
15459
|
return message.includes("Unknown RPC method: effects.resetCatalog") || message.includes("Unknown RPC method: effects.addCatalog") || message.includes("Method not found: effects.resetCatalog") || message.includes("Method not found: effects.addCatalog");
|
|
15138
15460
|
}
|
|
15139
|
-
|
|
15461
|
+
var planRecordObjectsChunks = Process({
|
|
15462
|
+
id: "granular-product/authoring/importers-record-apis/record-objects/plan",
|
|
15463
|
+
label: "Plan record chunks",
|
|
15464
|
+
parent: () => Environment.prototype.recordObjects
|
|
15465
|
+
})(function planRecordObjectsChunks2(records, batchSize) {
|
|
15140
15466
|
const total = records.length;
|
|
15141
15467
|
const size = Math.max(1, Math.min(batchSize, total));
|
|
15142
15468
|
const chunkCount = Math.ceil(total / size);
|
|
@@ -15146,7 +15472,7 @@ function planRecordObjectsChunks(records, batchSize) {
|
|
|
15146
15472
|
plans.push({ chunkIndex, chunkCount, offset, slice });
|
|
15147
15473
|
}
|
|
15148
15474
|
return plans;
|
|
15149
|
-
}
|
|
15475
|
+
});
|
|
15150
15476
|
function preserveRecordObjectRealId(record4) {
|
|
15151
15477
|
const realId = record4.id.trim();
|
|
15152
15478
|
if (!realId) {
|
|
@@ -15371,15 +15697,54 @@ function isGraphQLMutationDocument(query) {
|
|
|
15371
15697
|
}
|
|
15372
15698
|
return false;
|
|
15373
15699
|
}
|
|
15374
|
-
var
|
|
15375
|
-
|
|
15376
|
-
|
|
15377
|
-
|
|
15378
|
-
|
|
15379
|
-
|
|
15380
|
-
|
|
15381
|
-
|
|
15700
|
+
var _cancelRecordImport_dec, _getRecordImport_dec, _listRecordImports_dec, _enqueueRecordImport_dec, _executeRecordObjectsChunk_dec, _recordObjects_dec, _recordObject_dec, _listRelated_dec, _detach_dec, _attach_dec, _getRelationships_dec, _defineRelationship_dec, _searchRecords_dec, _graphql_dec, _closeSession_dec, _connectSession_dec, _createSession_dec, _getUserEnvironmentState_dec, _listSessions_dec, _recordState_dec, _records_dec, _imports_dec, _relationships_dec, _sessions_dec, _stateChanges_dec, _queries_dec, _Environment_decorators, _init;
|
|
15701
|
+
_Environment_decorators = [Block({
|
|
15702
|
+
description: "Expose records, imports, queries, relationships and sessions for one product environment.",
|
|
15703
|
+
id: "granular-product/authoring/importers-record-apis",
|
|
15704
|
+
label: "Environment client",
|
|
15705
|
+
exposedBy: [() => Granular],
|
|
15706
|
+
tests: [
|
|
15707
|
+
"./record-objects.cancellation.test.ts",
|
|
15708
|
+
"./environment.feed.test.ts"
|
|
15709
|
+
],
|
|
15710
|
+
parent: () => Granular
|
|
15711
|
+
})], _queries_dec = [Interface({
|
|
15712
|
+
label: "Queries & search",
|
|
15713
|
+
description: "Query the environment\u2019s graph or search its records."
|
|
15714
|
+
})], _stateChanges_dec = [Interface({
|
|
15715
|
+
label: "User state",
|
|
15716
|
+
description: "Record changes to user state and read the environment\u2019s current state."
|
|
15717
|
+
})], _sessions_dec = [Interface({
|
|
15718
|
+
label: "Sessions",
|
|
15719
|
+
description: "Create, connect, list and close conversations in this environment."
|
|
15720
|
+
})], _relationships_dec = [Interface({
|
|
15721
|
+
label: "Relationships",
|
|
15722
|
+
description: "Define, read, attach and detach relationships between records."
|
|
15723
|
+
})], _imports_dec = [Interface({
|
|
15724
|
+
id: "granular-product/ingestion/importer-lifecycle",
|
|
15725
|
+
label: "Background imports",
|
|
15726
|
+
description: "Submit a background record import and inspect or cancel its progress."
|
|
15727
|
+
})], _records_dec = [Interface({
|
|
15728
|
+
label: "Records",
|
|
15729
|
+
description: "Write customer records into the environment, including bounded batch requests."
|
|
15730
|
+
})], _recordState_dec = [Method(() => _Environment.stateChanges)], _listSessions_dec = [Method(() => _Environment.sessions, { description: "List conversations using the supplied environment, product and user filters." })], _getUserEnvironmentState_dec = [Method(() => _Environment.stateChanges, { description: "Read the user's environment projection and selected session scope." })], _createSession_dec = [Method(() => _Environment.sessions, { description: "Activate the requested environment and create a scoped conversation connection." })], _connectSession_dec = [Method(() => _Environment.sessions, { description: "Mint scoped connection credentials and open the existing conversation." })], _closeSession_dec = [Method(() => _Environment.sessions, { description: "Close an active conversation connection or request closure through the session API." })], _graphql_dec = [Method(() => _Environment.queries)], _searchRecords_dec = [Method(() => _Environment.queries, { description: "Search records through the current environment connection." })], _defineRelationship_dec = [Method(() => _Environment.relationships)], _getRelationships_dec = [Method(() => _Environment.relationships)], _attach_dec = [Method(() => _Environment.relationships)], _detach_dec = [Method(() => _Environment.relationships)], _listRelated_dec = [Method(() => _Environment.relationships)], _recordObject_dec = [Method(() => _Environment.records)], _recordObjects_dec = [Process({
|
|
15731
|
+
id: "granular-product/authoring/importers-record-apis/record-objects",
|
|
15732
|
+
label: "Write record batches"
|
|
15733
|
+
}), Method(() => _Environment.records)], _executeRecordObjectsChunk_dec = [Process({
|
|
15734
|
+
id: "granular-product/authoring/importers-record-apis/record-objects/write-chunk",
|
|
15735
|
+
label: "Write chunk with retry",
|
|
15736
|
+
parent: () => _Environment.prototype.recordObjects
|
|
15737
|
+
})], _enqueueRecordImport_dec = [Method(() => _Environment.imports)], _listRecordImports_dec = [Method(() => _Environment.imports)], _getRecordImport_dec = [Method(() => _Environment.imports)], _cancelRecordImport_dec = [Method(() => _Environment.imports)];
|
|
15738
|
+
var _Environment = class _Environment {
|
|
15382
15739
|
constructor(granular, envData, apiKey, apiEndpoint, tokenProvider, beforeMutationSend, graphqlIdempotencyKey) {
|
|
15740
|
+
__runInitializers(_init, 5, this);
|
|
15741
|
+
__publicField(this, "granular");
|
|
15742
|
+
__publicField(this, "envData");
|
|
15743
|
+
__publicField(this, "_apiKey");
|
|
15744
|
+
__publicField(this, "_apiEndpoint");
|
|
15745
|
+
__publicField(this, "_tokenProvider");
|
|
15746
|
+
__publicField(this, "_beforeMutationSend");
|
|
15747
|
+
__publicField(this, "_graphqlIdempotencyKey");
|
|
15383
15748
|
this.granular = granular;
|
|
15384
15749
|
this.envData = envData;
|
|
15385
15750
|
this._apiKey = apiKey;
|
|
@@ -15629,10 +15994,6 @@ var Environment = class _Environment {
|
|
|
15629
15994
|
}
|
|
15630
15995
|
);
|
|
15631
15996
|
}
|
|
15632
|
-
/**
|
|
15633
|
-
* Mirror product-owned workflow state into Granular without making Granular
|
|
15634
|
-
* own the customer application's state machine.
|
|
15635
|
-
*/
|
|
15636
15997
|
async recordState(input) {
|
|
15637
15998
|
const { machine, state, ...target } = input;
|
|
15638
15999
|
if (!machine.trim()) {
|
|
@@ -15904,30 +16265,6 @@ var Environment = class _Environment {
|
|
|
15904
16265
|
const prefix = `${className}_`;
|
|
15905
16266
|
return graphPath.startsWith(prefix) ? graphPath.substring(prefix.length) : graphPath;
|
|
15906
16267
|
}
|
|
15907
|
-
/**
|
|
15908
|
-
* Execute a GraphQL query against the environment's graph.
|
|
15909
|
-
*
|
|
15910
|
-
* The query uses the Granular graph query language (based on Cypher/GraphQL).
|
|
15911
|
-
* Authentication is handled automatically using the SDK's API key.
|
|
15912
|
-
*
|
|
15913
|
-
* @param query - The GraphQL query string
|
|
15914
|
-
* @param variables - Optional variables for the query
|
|
15915
|
-
* @returns The query result data
|
|
15916
|
-
*
|
|
15917
|
-
* @example
|
|
15918
|
-
* ```typescript
|
|
15919
|
-
* // Read the workspace
|
|
15920
|
-
* const result = await env.graphql(
|
|
15921
|
-
* `query { model(path: "workspace") { path label submodels { path label } } }`
|
|
15922
|
-
* );
|
|
15923
|
-
* console.log(result.data);
|
|
15924
|
-
*
|
|
15925
|
-
* // Create a model
|
|
15926
|
-
* const created = await env.graphql(
|
|
15927
|
-
* `mutation { at(path: "workspace") { create_submodel(subpath: "my_node", label: "My Node", prototype: "Model") { model { path label } } } }`
|
|
15928
|
-
* );
|
|
15929
|
-
* ```
|
|
15930
|
-
*/
|
|
15931
16268
|
async graphql(query, variables, options) {
|
|
15932
16269
|
const authToken = await this.resolveAuthToken();
|
|
15933
16270
|
if (this._beforeMutationSend && isGraphQLMutationDocument(query)) {
|
|
@@ -16020,27 +16357,6 @@ var Environment = class _Environment {
|
|
|
16020
16357
|
rank: rankRecordSearchResult(result, normalizedQuery, index)
|
|
16021
16358
|
})).sort((left, right) => left.rank - right.rank).map((item) => item.result).slice(0, limit);
|
|
16022
16359
|
}
|
|
16023
|
-
// ==================== RELATIONSHIP METHODS ====================
|
|
16024
|
-
/**
|
|
16025
|
-
* Define a relationship between two model types.
|
|
16026
|
-
*
|
|
16027
|
-
* Creates both submodels (if they don't exist) and links them with
|
|
16028
|
-
* a RelationshipDef node that encodes cardinality.
|
|
16029
|
-
*
|
|
16030
|
-
* @example
|
|
16031
|
-
* ```typescript
|
|
16032
|
-
* // Author has many Books, Book has one Author
|
|
16033
|
-
* const rel = await env.defineRelationship({
|
|
16034
|
-
* model: 'author',
|
|
16035
|
-
* localSubmodel: 'books',
|
|
16036
|
-
* localIsMany: true,
|
|
16037
|
-
* foreignModel: 'book',
|
|
16038
|
-
* foreignSubmodel: 'author',
|
|
16039
|
-
* foreignIsMany: false,
|
|
16040
|
-
* });
|
|
16041
|
-
* console.log(rel.relationship_kind); // "one_to_many"
|
|
16042
|
-
* ```
|
|
16043
|
-
*/
|
|
16044
16360
|
async defineRelationship(options) {
|
|
16045
16361
|
const result = await this.graphql(
|
|
16046
16362
|
`mutation DefineRelationship(
|
|
@@ -16086,20 +16402,6 @@ var Environment = class _Environment {
|
|
|
16086
16402
|
}
|
|
16087
16403
|
return result.data.at.define_relationship;
|
|
16088
16404
|
}
|
|
16089
|
-
/**
|
|
16090
|
-
* Get all relationships for a model type.
|
|
16091
|
-
*
|
|
16092
|
-
* @param modelPath - The model type path (e.g., "author")
|
|
16093
|
-
* @returns Array of relationships from this model's perspective
|
|
16094
|
-
*
|
|
16095
|
-
* @example
|
|
16096
|
-
* ```typescript
|
|
16097
|
-
* const rels = await env.getRelationships('author');
|
|
16098
|
-
* for (const rel of rels) {
|
|
16099
|
-
* console.log(`${rel.local_submodel.path} -> ${rel.foreign_model.path} (${rel.relationship_kind})`);
|
|
16100
|
-
* }
|
|
16101
|
-
* ```
|
|
16102
|
-
*/
|
|
16103
16405
|
async getRelationships(modelPath) {
|
|
16104
16406
|
const result = await this.graphql(
|
|
16105
16407
|
`query GetRelationships($path: String) {
|
|
@@ -16124,27 +16426,6 @@ var Environment = class _Environment {
|
|
|
16124
16426
|
}
|
|
16125
16427
|
return result.data?.model?.relationships || [];
|
|
16126
16428
|
}
|
|
16127
|
-
/**
|
|
16128
|
-
* Attach a target model to a relationship submodel.
|
|
16129
|
-
*
|
|
16130
|
-
* Handles cardinality automatically:
|
|
16131
|
-
* - "One" side: sets/replaces the reference
|
|
16132
|
-
* - "Many" side: adds the target to the collection
|
|
16133
|
-
*
|
|
16134
|
-
* If the target model doesn't exist, it's created as an instance of the foreign type.
|
|
16135
|
-
* Bidirectional sync is automatic.
|
|
16136
|
-
*
|
|
16137
|
-
* @param modelPath - The model instance path (e.g., "tolkien")
|
|
16138
|
-
* @param submodelPath - The relationship submodel (e.g., "books")
|
|
16139
|
-
* @param targetPath - The target model to attach (e.g., "lord_of_the_rings")
|
|
16140
|
-
*
|
|
16141
|
-
* @example
|
|
16142
|
-
* ```typescript
|
|
16143
|
-
* // Attach a book to an author (many side)
|
|
16144
|
-
* await env.attach('tolkien', 'books', 'lord_of_the_rings');
|
|
16145
|
-
* // This also automatically sets lord_of_the_rings:author -> tolkien
|
|
16146
|
-
* ```
|
|
16147
|
-
*/
|
|
16148
16429
|
async attach(modelPath, submodelPath, targetPath) {
|
|
16149
16430
|
const result = await this.graphql(
|
|
16150
16431
|
`mutation Attach($target: String!) {
|
|
@@ -16164,24 +16445,6 @@ var Environment = class _Environment {
|
|
|
16164
16445
|
);
|
|
16165
16446
|
}
|
|
16166
16447
|
}
|
|
16167
|
-
/**
|
|
16168
|
-
* Detach a target model from a relationship submodel.
|
|
16169
|
-
*
|
|
16170
|
-
* Handles bidirectional cleanup automatically.
|
|
16171
|
-
*
|
|
16172
|
-
* @param modelPath - The model instance path
|
|
16173
|
-
* @param submodelPath - The relationship submodel
|
|
16174
|
-
* @param targetPath - The target to detach (optional for "one" side; omit on "many" side to detach all)
|
|
16175
|
-
*
|
|
16176
|
-
* @example
|
|
16177
|
-
* ```typescript
|
|
16178
|
-
* // Detach a specific book
|
|
16179
|
-
* await env.detach('tolkien', 'books', 'lord_of_the_rings');
|
|
16180
|
-
*
|
|
16181
|
-
* // Detach all books
|
|
16182
|
-
* await env.detach('tolkien', 'books');
|
|
16183
|
-
* ```
|
|
16184
|
-
*/
|
|
16185
16448
|
async detach(modelPath, submodelPath, targetPath) {
|
|
16186
16449
|
const targetArg = targetPath ? `target: "${targetPath}"` : "";
|
|
16187
16450
|
const result = await this.graphql(
|
|
@@ -16201,19 +16464,6 @@ var Environment = class _Environment {
|
|
|
16201
16464
|
);
|
|
16202
16465
|
}
|
|
16203
16466
|
}
|
|
16204
|
-
/**
|
|
16205
|
-
* List all related models through a relationship submodel.
|
|
16206
|
-
*
|
|
16207
|
-
* @param modelPath - The model instance path
|
|
16208
|
-
* @param submodelPath - The relationship submodel
|
|
16209
|
-
* @returns Array of related model references
|
|
16210
|
-
*
|
|
16211
|
-
* @example
|
|
16212
|
-
* ```typescript
|
|
16213
|
-
* const books = await env.listRelated('tolkien', 'books');
|
|
16214
|
-
* console.log(books); // [{ path: "lord_of_the_rings", label: "Lord of the Rings" }, ...]
|
|
16215
|
-
* ```
|
|
16216
|
-
*/
|
|
16217
16467
|
async listRelated(modelPath, submodelPath) {
|
|
16218
16468
|
const result = await this.graphql(
|
|
16219
16469
|
`mutation ListRelated {
|
|
@@ -16635,38 +16885,6 @@ var Environment = class _Environment {
|
|
|
16635
16885
|
}
|
|
16636
16886
|
}
|
|
16637
16887
|
}
|
|
16638
|
-
// ==================== RECORD OBJECT ====================
|
|
16639
|
-
/**
|
|
16640
|
-
* Create or update an instance of a class in the graph.
|
|
16641
|
-
*
|
|
16642
|
-
* Uses `instantiate` under the hood, which has find-or-create semantics:
|
|
16643
|
-
* if an instance with the given `id` already exists for the class it is
|
|
16644
|
-
* returned; otherwise a new instance is created. Fields are then set
|
|
16645
|
-
* (overwriting previous values) and relationships are attached.
|
|
16646
|
-
*
|
|
16647
|
-
* The graph path is derived as `{className}_{id}` to ensure uniqueness
|
|
16648
|
-
* across classes (two objects of different classes may share the same
|
|
16649
|
-
* real-world ID). Relationship targets are also resolved automatically
|
|
16650
|
-
* using the foreign class from the relationship definition.
|
|
16651
|
-
*
|
|
16652
|
-
* @param options - The object specification
|
|
16653
|
-
* @returns The graph path, real-world ID, and creation status
|
|
16654
|
-
*
|
|
16655
|
-
* @example
|
|
16656
|
-
* ```typescript
|
|
16657
|
-
* // Create an author with fields
|
|
16658
|
-
* const result = await env.recordObject({
|
|
16659
|
-
* className: 'author',
|
|
16660
|
-
* id: 'tolkien',
|
|
16661
|
-
* label: 'J.R.R. Tolkien',
|
|
16662
|
-
* fields: { name: 'J.R.R. Tolkien', birth_year: 1892 },
|
|
16663
|
-
* relationships: { books: ['lotr', 'silmarillion'] },
|
|
16664
|
-
* });
|
|
16665
|
-
* // result.path → 'author_tolkien' (internal graph path)
|
|
16666
|
-
* // result.id → 'tolkien' (real-world ID)
|
|
16667
|
-
* // result.created → true
|
|
16668
|
-
* ```
|
|
16669
|
-
*/
|
|
16670
16888
|
async recordObject(options) {
|
|
16671
16889
|
const results = await this.recordObjects([options]);
|
|
16672
16890
|
const result = results[0];
|
|
@@ -16675,24 +16893,6 @@ var Environment = class _Environment {
|
|
|
16675
16893
|
}
|
|
16676
16894
|
return result;
|
|
16677
16895
|
}
|
|
16678
|
-
/**
|
|
16679
|
-
* Batch version of `recordObject()`.
|
|
16680
|
-
*
|
|
16681
|
-
* Sends rows through the control-plane **`/records/batch`** endpoint in **chunks** (default
|
|
16682
|
-
* **100** records per HTTP request) so individual requests stay bounded and gateway timeouts are
|
|
16683
|
-
* unlikely. Each chunk is retried on transient network / worker errors.
|
|
16684
|
-
*
|
|
16685
|
-
* Use the optional second argument to:
|
|
16686
|
-
* - **`batchSize`** — rows per POST (smaller = more progress events; larger = fewer round trips).
|
|
16687
|
-
* - **`concurrency`** — run up to N chunk POSTs in parallel (capped at 16) when you want lower wall time.
|
|
16688
|
-
* - **`onChunkComplete`** — hook for UIs after each chunk succeeds (row order in the returned array
|
|
16689
|
-
* always matches `records`; chunk **completion** order may differ when `concurrency > 1`).
|
|
16690
|
-
*
|
|
16691
|
-
* For **asynchronous** ingestion with worker-side batching and aggregate counters (`queued`,
|
|
16692
|
-
* `completed`, …), use **`enqueueRecordImport`** and poll **`getRecordImport`** /
|
|
16693
|
-
* **`getRecordImportSummary`** — best for very large fire-and-forget loads when immediate
|
|
16694
|
-
* synchronous commit of every row is not required.
|
|
16695
|
-
*/
|
|
16696
16896
|
async recordObjects(records, options) {
|
|
16697
16897
|
options?.signal?.throwIfAborted();
|
|
16698
16898
|
if (!Array.isArray(records) || records.length === 0) {
|
|
@@ -16777,15 +16977,6 @@ var Environment = class _Environment {
|
|
|
16777
16977
|
}
|
|
16778
16978
|
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
16779
16979
|
}
|
|
16780
|
-
/**
|
|
16781
|
-
* Queue a background record import for this environment (async worker pipeline).
|
|
16782
|
-
*
|
|
16783
|
-
* **vs `recordObjects`:** this path accepts the full payload in one request, returns an
|
|
16784
|
-
* **`importId`**, and processes rows in the background — use **`getRecordImport`** /
|
|
16785
|
-
* **`getRecordImportSummary`** for progress. Choose it for large bulk loads where you do not
|
|
16786
|
-
* need every row committed before the HTTP call returns. Use **`recordObjects`** when you need
|
|
16787
|
-
* synchronous upserts and fine-grained chunk progress via **`onChunkComplete`**.
|
|
16788
|
-
*/
|
|
16789
16980
|
async enqueueRecordImport(records, options = {}) {
|
|
16790
16981
|
const recordsToImport = records.map(preserveRecordObjectRealId);
|
|
16791
16982
|
return this.controlPlaneRequest(
|
|
@@ -16802,9 +16993,6 @@ var Environment = class _Environment {
|
|
|
16802
16993
|
}
|
|
16803
16994
|
);
|
|
16804
16995
|
}
|
|
16805
|
-
/**
|
|
16806
|
-
* List queued or completed record imports for this environment.
|
|
16807
|
-
*/
|
|
16808
16996
|
async listRecordImports(status) {
|
|
16809
16997
|
const suffix = status ? `?status=${encodeURIComponent(status)}` : "";
|
|
16810
16998
|
const response = await this.controlPlaneRequest(
|
|
@@ -16827,9 +17015,6 @@ var Environment = class _Environment {
|
|
|
16827
17015
|
const summary = await this.getRecordImportSummary();
|
|
16828
17016
|
return summary.awaitingRecords;
|
|
16829
17017
|
}
|
|
16830
|
-
/**
|
|
16831
|
-
* Fetch a single record import by id.
|
|
16832
|
-
*/
|
|
16833
17018
|
async getRecordImport(importId) {
|
|
16834
17019
|
return this.controlPlaneRequest(
|
|
16835
17020
|
`/control/record-imports/${importId}`
|
|
@@ -16844,9 +17029,6 @@ var Environment = class _Environment {
|
|
|
16844
17029
|
const response = await this.controlPlaneRequest(`/control/record-imports/${importId}/items${suffix}`);
|
|
16845
17030
|
return Array.isArray(response.items) ? response.items : [];
|
|
16846
17031
|
}
|
|
16847
|
-
/**
|
|
16848
|
-
* Cancel a queued/background record import.
|
|
16849
|
-
*/
|
|
16850
17032
|
async cancelRecordImport(importId) {
|
|
16851
17033
|
return this.controlPlaneRequest(
|
|
16852
17034
|
`/control/record-imports/${importId}/cancel`,
|
|
@@ -16856,17 +17038,75 @@ var Environment = class _Environment {
|
|
|
16856
17038
|
);
|
|
16857
17039
|
}
|
|
16858
17040
|
};
|
|
16859
|
-
|
|
16860
|
-
|
|
16861
|
-
|
|
16862
|
-
|
|
16863
|
-
|
|
16864
|
-
|
|
16865
|
-
|
|
16866
|
-
|
|
16867
|
-
|
|
17041
|
+
_init = __decoratorStart(null);
|
|
17042
|
+
__decorateElement(_init, 1, "recordState", _recordState_dec, _Environment);
|
|
17043
|
+
__decorateElement(_init, 1, "listSessions", _listSessions_dec, _Environment);
|
|
17044
|
+
__decorateElement(_init, 1, "getUserEnvironmentState", _getUserEnvironmentState_dec, _Environment);
|
|
17045
|
+
__decorateElement(_init, 1, "createSession", _createSession_dec, _Environment);
|
|
17046
|
+
__decorateElement(_init, 1, "connectSession", _connectSession_dec, _Environment);
|
|
17047
|
+
__decorateElement(_init, 1, "closeSession", _closeSession_dec, _Environment);
|
|
17048
|
+
__decorateElement(_init, 1, "graphql", _graphql_dec, _Environment);
|
|
17049
|
+
__decorateElement(_init, 1, "searchRecords", _searchRecords_dec, _Environment);
|
|
17050
|
+
__decorateElement(_init, 1, "defineRelationship", _defineRelationship_dec, _Environment);
|
|
17051
|
+
__decorateElement(_init, 1, "getRelationships", _getRelationships_dec, _Environment);
|
|
17052
|
+
__decorateElement(_init, 1, "attach", _attach_dec, _Environment);
|
|
17053
|
+
__decorateElement(_init, 1, "detach", _detach_dec, _Environment);
|
|
17054
|
+
__decorateElement(_init, 1, "listRelated", _listRelated_dec, _Environment);
|
|
17055
|
+
__decorateElement(_init, 1, "recordObject", _recordObject_dec, _Environment);
|
|
17056
|
+
__decorateElement(_init, 1, "recordObjects", _recordObjects_dec, _Environment);
|
|
17057
|
+
__decorateElement(_init, 1, "executeRecordObjectsChunk", _executeRecordObjectsChunk_dec, _Environment);
|
|
17058
|
+
__decorateElement(_init, 1, "enqueueRecordImport", _enqueueRecordImport_dec, _Environment);
|
|
17059
|
+
__decorateElement(_init, 1, "listRecordImports", _listRecordImports_dec, _Environment);
|
|
17060
|
+
__decorateElement(_init, 1, "getRecordImport", _getRecordImport_dec, _Environment);
|
|
17061
|
+
__decorateElement(_init, 1, "cancelRecordImport", _cancelRecordImport_dec, _Environment);
|
|
17062
|
+
__decorateElement(_init, 13, "queries", _queries_dec, _Environment);
|
|
17063
|
+
__decorateElement(_init, 13, "stateChanges", _stateChanges_dec, _Environment);
|
|
17064
|
+
__decorateElement(_init, 13, "sessions", _sessions_dec, _Environment);
|
|
17065
|
+
__decorateElement(_init, 13, "relationships", _relationships_dec, _Environment);
|
|
17066
|
+
__decorateElement(_init, 13, "imports", _imports_dec, _Environment);
|
|
17067
|
+
__decorateElement(_init, 13, "records", _records_dec, _Environment);
|
|
17068
|
+
_Environment = __decorateElement(_init, 0, "Environment", _Environment_decorators, _Environment);
|
|
17069
|
+
__publicField(_Environment, "queries", __runInitializers(_init, 8, _Environment)), __runInitializers(_init, 11, _Environment);
|
|
17070
|
+
__publicField(_Environment, "stateChanges", __runInitializers(_init, 12, _Environment)), __runInitializers(_init, 15, _Environment);
|
|
17071
|
+
__publicField(_Environment, "sessions", __runInitializers(_init, 16, _Environment)), __runInitializers(_init, 19, _Environment);
|
|
17072
|
+
__publicField(_Environment, "relationships", __runInitializers(_init, 20, _Environment)), __runInitializers(_init, 23, _Environment);
|
|
17073
|
+
__publicField(_Environment, "imports", __runInitializers(_init, 24, _Environment)), __runInitializers(_init, 27, _Environment);
|
|
17074
|
+
__publicField(_Environment, "records", __runInitializers(_init, 28, _Environment)), __runInitializers(_init, 31, _Environment);
|
|
17075
|
+
__runInitializers(_init, 1, _Environment);
|
|
17076
|
+
var Environment = _Environment;
|
|
17077
|
+
var _checkReadiness_dec, _close_dec, _disconnect_dec, _recordObjects_dec2, _mentionRecord_dec, _publishAssistantReply_dec, _getDocument_dec, _getHeap_dec, _conversation_dec, _records_dec2, _lifecycle_dec, _a, _EnvironmentSession_decorators, _init2;
|
|
17078
|
+
_EnvironmentSession_decorators = [Block({
|
|
17079
|
+
description: "Expose conversation messages, selected data and lifecycle operations for one environment session.",
|
|
17080
|
+
id: "granular-product/authoring/importers-record-apis/session-client",
|
|
17081
|
+
label: "Session client",
|
|
17082
|
+
exposedBy: [() => Environment, () => Granular],
|
|
17083
|
+
tests: [
|
|
17084
|
+
"./environment.feed.test.ts",
|
|
17085
|
+
"./environment.assistant-reply.test.ts"
|
|
17086
|
+
],
|
|
17087
|
+
parent: () => Environment
|
|
17088
|
+
})];
|
|
17089
|
+
var _EnvironmentSession = class _EnvironmentSession extends (_a = Session, _lifecycle_dec = [Interface({
|
|
17090
|
+
label: "Connection lifecycle",
|
|
17091
|
+
description: "Check session readiness and close or disconnect the session client."
|
|
17092
|
+
})], _records_dec2 = [Interface({
|
|
17093
|
+
label: "Session records",
|
|
17094
|
+
description: "Write records or mention an existing record in the current conversation."
|
|
17095
|
+
})], _conversation_dec = [Interface({
|
|
17096
|
+
label: "Conversation data",
|
|
17097
|
+
description: "Read the conversation document and selected data, and publish assistant replies."
|
|
17098
|
+
})], _getHeap_dec = [Method(() => _EnvironmentSession.conversation)], _getDocument_dec = [Method(() => _EnvironmentSession.conversation)], _publishAssistantReply_dec = [Method(() => _EnvironmentSession.conversation)], _mentionRecord_dec = [Method(() => _EnvironmentSession.records, { description: "Add an existing record to the conversation's selected working context." })], _recordObjects_dec2 = [Method(() => _EnvironmentSession.records, { description: "Write a batch of records through the current environment's record-ingestion API." })], _disconnect_dec = [Method(() => _EnvironmentSession.lifecycle)], _close_dec = [Method(() => _EnvironmentSession.lifecycle)], _checkReadiness_dec = [Method(() => _EnvironmentSession.lifecycle)], _a) {
|
|
16868
17099
|
constructor(client, environment, clientId, options = {}) {
|
|
16869
17100
|
super(client, clientId, { initialQuota: options.initialQuota });
|
|
17101
|
+
__runInitializers(_init2, 5, this);
|
|
17102
|
+
__publicField(this, "environment");
|
|
17103
|
+
__publicField(this, "sessionDataRoutePrefix");
|
|
17104
|
+
__publicField(this, "sessionDataHeaders");
|
|
17105
|
+
__publicField(this, "beforeMutationSend");
|
|
17106
|
+
__publicField(this, "heartbeatTimer", null);
|
|
17107
|
+
__publicField(this, "heartbeatProbeInFlight", false);
|
|
17108
|
+
/** The last known graph container status, updated by checkReadiness(). */
|
|
17109
|
+
__publicField(this, "graphContainerStatus", null);
|
|
16870
17110
|
this.environment = environment;
|
|
16871
17111
|
this.sessionDataRoutePrefix = options.sessionDataRoutePrefix || "/orchestrator/ws/sessions";
|
|
16872
17112
|
this.sessionDataHeaders = options.sessionDataHeaders || {};
|
|
@@ -16964,9 +17204,6 @@ var EnvironmentSession = class extends Session {
|
|
|
16964
17204
|
get feedback() {
|
|
16965
17205
|
return this.environment.feedback;
|
|
16966
17206
|
}
|
|
16967
|
-
/**
|
|
16968
|
-
* Return a plain JS copy of the synced session heap.
|
|
16969
|
-
*/
|
|
16970
17207
|
getHeap() {
|
|
16971
17208
|
const doc = this.document;
|
|
16972
17209
|
return normalizeHeapSnapshot(doc?.heap);
|
|
@@ -17041,22 +17278,9 @@ var EnvironmentSession = class extends Session {
|
|
|
17041
17278
|
});
|
|
17042
17279
|
return response.json();
|
|
17043
17280
|
}
|
|
17044
|
-
/**
|
|
17045
|
-
* Fetch the live session document from the runtime DO.
|
|
17046
|
-
*
|
|
17047
|
-
* For presentation history use `feed.list()` or `transcript.list()`.
|
|
17048
|
-
* Timeline and job collections are diagnostic/execution data only.
|
|
17049
|
-
*/
|
|
17050
17281
|
async getDocument() {
|
|
17051
17282
|
return this.sessionDataRequest("/document");
|
|
17052
17283
|
}
|
|
17053
|
-
/**
|
|
17054
|
-
* Publish one terminal assistant reply from a trusted server integration.
|
|
17055
|
-
*
|
|
17056
|
-
* This uses the API-key-authenticated HTTP session boundary. Delegated
|
|
17057
|
-
* browser sessions cannot use it and never receive assistant feed-authoring
|
|
17058
|
-
* capability through their WebSocket.
|
|
17059
|
-
*/
|
|
17060
17284
|
async publishAssistantReply(input) {
|
|
17061
17285
|
if (this.sessionDataRoutePrefix === "/sdk/browser-sessions") {
|
|
17062
17286
|
throw new Error(
|
|
@@ -17438,13 +17662,6 @@ var EnvironmentSession = class extends Session {
|
|
|
17438
17662
|
async listFeedback() {
|
|
17439
17663
|
return this.environment.listFeedback();
|
|
17440
17664
|
}
|
|
17441
|
-
/**
|
|
17442
|
-
* Close the session and disconnect from the sandbox.
|
|
17443
|
-
*
|
|
17444
|
-
* Sends `client.goodbye` over WebSocket first, then issues an HTTP fallback
|
|
17445
|
-
* to the runtime goodbye endpoint if no definitive WS-side runtime notify
|
|
17446
|
-
* acknowledgement was observed.
|
|
17447
|
-
*/
|
|
17448
17665
|
async disconnect() {
|
|
17449
17666
|
this.stopHeartbeat();
|
|
17450
17667
|
this.disposeSessionFeed();
|
|
@@ -17488,15 +17705,9 @@ var EnvironmentSession = class extends Session {
|
|
|
17488
17705
|
this.stopHeartbeat();
|
|
17489
17706
|
this.client.disconnect({ reason: "Transport detach" });
|
|
17490
17707
|
}
|
|
17491
|
-
/**
|
|
17492
|
-
* Backwards-compatible alias for `disconnect()`.
|
|
17493
|
-
*/
|
|
17494
17708
|
async close() {
|
|
17495
17709
|
await this.disconnect();
|
|
17496
17710
|
}
|
|
17497
|
-
/**
|
|
17498
|
-
* Check if the graph container is ready and warm.
|
|
17499
|
-
*/
|
|
17500
17711
|
async checkReadiness() {
|
|
17501
17712
|
const result = await this.client.call("client.heartbeat", {});
|
|
17502
17713
|
const containerStatus = result?.graphContainerStatus ?? {
|
|
@@ -17508,6 +17719,24 @@ var EnvironmentSession = class extends Session {
|
|
|
17508
17719
|
return containerStatus;
|
|
17509
17720
|
}
|
|
17510
17721
|
};
|
|
17722
|
+
_init2 = __decoratorStart(_a);
|
|
17723
|
+
__decorateElement(_init2, 1, "getHeap", _getHeap_dec, _EnvironmentSession);
|
|
17724
|
+
__decorateElement(_init2, 1, "getDocument", _getDocument_dec, _EnvironmentSession);
|
|
17725
|
+
__decorateElement(_init2, 1, "publishAssistantReply", _publishAssistantReply_dec, _EnvironmentSession);
|
|
17726
|
+
__decorateElement(_init2, 1, "mentionRecord", _mentionRecord_dec, _EnvironmentSession);
|
|
17727
|
+
__decorateElement(_init2, 1, "recordObjects", _recordObjects_dec2, _EnvironmentSession);
|
|
17728
|
+
__decorateElement(_init2, 1, "disconnect", _disconnect_dec, _EnvironmentSession);
|
|
17729
|
+
__decorateElement(_init2, 1, "close", _close_dec, _EnvironmentSession);
|
|
17730
|
+
__decorateElement(_init2, 1, "checkReadiness", _checkReadiness_dec, _EnvironmentSession);
|
|
17731
|
+
__decorateElement(_init2, 13, "lifecycle", _lifecycle_dec, _EnvironmentSession);
|
|
17732
|
+
__decorateElement(_init2, 13, "records", _records_dec2, _EnvironmentSession);
|
|
17733
|
+
__decorateElement(_init2, 13, "conversation", _conversation_dec, _EnvironmentSession);
|
|
17734
|
+
_EnvironmentSession = __decorateElement(_init2, 0, "EnvironmentSession", _EnvironmentSession_decorators, _EnvironmentSession);
|
|
17735
|
+
__publicField(_EnvironmentSession, "lifecycle", __runInitializers(_init2, 8, _EnvironmentSession)), __runInitializers(_init2, 11, _EnvironmentSession);
|
|
17736
|
+
__publicField(_EnvironmentSession, "records", __runInitializers(_init2, 12, _EnvironmentSession)), __runInitializers(_init2, 15, _EnvironmentSession);
|
|
17737
|
+
__publicField(_EnvironmentSession, "conversation", __runInitializers(_init2, 16, _EnvironmentSession)), __runInitializers(_init2, 19, _EnvironmentSession);
|
|
17738
|
+
__runInitializers(_init2, 1, _EnvironmentSession);
|
|
17739
|
+
var EnvironmentSession = _EnvironmentSession;
|
|
17511
17740
|
var OntologyHandle = class {
|
|
17512
17741
|
granular;
|
|
17513
17742
|
ontologyNameOrId;
|
|
@@ -17559,40 +17788,62 @@ var OntologyHandle = class {
|
|
|
17559
17788
|
};
|
|
17560
17789
|
}
|
|
17561
17790
|
};
|
|
17562
|
-
var
|
|
17563
|
-
|
|
17564
|
-
|
|
17565
|
-
|
|
17566
|
-
|
|
17567
|
-
|
|
17568
|
-
|
|
17569
|
-
|
|
17570
|
-
|
|
17571
|
-
|
|
17572
|
-
|
|
17573
|
-
|
|
17574
|
-
|
|
17575
|
-
|
|
17576
|
-
|
|
17577
|
-
|
|
17578
|
-
|
|
17579
|
-
|
|
17580
|
-
|
|
17581
|
-
|
|
17582
|
-
|
|
17583
|
-
|
|
17584
|
-
sandboxEffectHostPromises = /* @__PURE__ */ new Map();
|
|
17585
|
-
effectHostGenerations = /* @__PURE__ */ new Map();
|
|
17586
|
-
effectHostRecovery = /* @__PURE__ */ new Map();
|
|
17587
|
-
/** Ontology-bound environment importer hooks keyed by the caller's ontology identifier. */
|
|
17588
|
-
ontologyImporters = /* @__PURE__ */ new Map();
|
|
17589
|
-
/** Resolved importer hooks keyed by sandboxId for fast lookups during openEnvironment(). */
|
|
17590
|
-
sandboxImporters = /* @__PURE__ */ new Map();
|
|
17791
|
+
var _request_dec, _disconnectEffects_dec, _unregisterEffect_dec, _registerEffects_dec, _registerEffect_dec, _reopenSession_dec, _closeSession_dec2, _connectSession_dec2, _createSession_dec2, _listSessions_dec2, _connect_dec, _adoptEnvironmentForUser_dec, _getEnvironmentForUser_dec, _getActiveEnvironmentForUser_dec, _openEnvironment_dec, _environmentAccess_dec, _sessions_dec2, _effectHosts_dec, _transport_dec, _Granular_decorators, _init3;
|
|
17792
|
+
_Granular_decorators = [Block({
|
|
17793
|
+
description: "Authenticate an application and provide access to its environments, sessions and registered action handlers.",
|
|
17794
|
+
id: "granular-product/authoring/sdk-ontology-facade",
|
|
17795
|
+
label: "Granular client",
|
|
17796
|
+
tests: ["./environment.opening.test.ts"],
|
|
17797
|
+
docs: "../README.md"
|
|
17798
|
+
})], _transport_dec = [Interface({
|
|
17799
|
+
label: "HTTP requests",
|
|
17800
|
+
description: "Send authenticated SDK requests to the configured Granular API."
|
|
17801
|
+
})], _effectHosts_dec = [Interface({
|
|
17802
|
+
id: "granular-product/authoring/live-effect-hosts",
|
|
17803
|
+
label: "Application action handlers",
|
|
17804
|
+
description: "Register application functions that Granular may invoke as actions, and disconnect handlers when they are no longer available."
|
|
17805
|
+
})], _sessions_dec2 = [Interface({
|
|
17806
|
+
label: "Sessions",
|
|
17807
|
+
description: "Create, list, connect and close product sessions through the SDK."
|
|
17808
|
+
})], _environmentAccess_dec = [Interface({
|
|
17809
|
+
label: "Environment access",
|
|
17810
|
+
description: "Resolve a user\u2019s assigned environment or open a connection to it."
|
|
17811
|
+
})], _openEnvironment_dec = [Method(() => _Granular.environmentAccess)], _getActiveEnvironmentForUser_dec = [Method(() => _Granular.environmentAccess)], _getEnvironmentForUser_dec = [Method(() => _Granular.environmentAccess)], _adoptEnvironmentForUser_dec = [Method(() => _Granular.environmentAccess)], _connect_dec = [Method(() => _Granular.environmentAccess)], _listSessions_dec2 = [Method(() => _Granular.sessions)], _createSession_dec2 = [Method(() => _Granular.sessions, { benchmarks: ["./session-ready.bench.ts"] })], _connectSession_dec2 = [Method(() => _Granular.sessions)], _closeSession_dec2 = [Method(() => _Granular.sessions)], _reopenSession_dec = [Method(() => _Granular.sessions)], _registerEffect_dec = [Method(() => _Granular.effectHosts)], _registerEffects_dec = [Method(() => _Granular.effectHosts)], _unregisterEffect_dec = [Method(() => _Granular.effectHosts)], _disconnectEffects_dec = [Method(() => _Granular.effectHosts)], _request_dec = [Method(() => _Granular.transport)];
|
|
17812
|
+
var _Granular = class _Granular {
|
|
17591
17813
|
/**
|
|
17592
17814
|
* Create a new Granular client
|
|
17593
17815
|
* @param options - Client configuration
|
|
17594
17816
|
*/
|
|
17595
17817
|
constructor(options) {
|
|
17818
|
+
__runInitializers(_init3, 5, this);
|
|
17819
|
+
/** Tenant events feed, authenticated with this client's credentials. */
|
|
17820
|
+
__publicField(this, "eventsFeed", new EventsFeed(
|
|
17821
|
+
(path, options) => this.request(path, options)
|
|
17822
|
+
));
|
|
17823
|
+
__publicField(this, "apiKey");
|
|
17824
|
+
__publicField(this, "apiUrl");
|
|
17825
|
+
__publicField(this, "httpUrl");
|
|
17826
|
+
__publicField(this, "tokenProvider");
|
|
17827
|
+
__publicField(this, "WebSocketCtor");
|
|
17828
|
+
__publicField(this, "onUnexpectedClose");
|
|
17829
|
+
__publicField(this, "onReconnectError");
|
|
17830
|
+
__publicField(this, "effectHostUrl");
|
|
17831
|
+
__publicField(this, "graphqlIdempotencyKey");
|
|
17832
|
+
__publicField(this, "debugHttp", process.env.GRANULAR_DEBUG_HTTP === "1");
|
|
17833
|
+
/** Sandbox-level effect registry: sandboxId → (effectKey@selector → ToolWithHandler) */
|
|
17834
|
+
__publicField(this, "sandboxEffects", /* @__PURE__ */ new Map());
|
|
17835
|
+
/** Live sandbox-scoped effect hosts keyed by sandboxId */
|
|
17836
|
+
__publicField(this, "sandboxEffectHosts", /* @__PURE__ */ new Map());
|
|
17837
|
+
__publicField(this, "developmentProviders", /* @__PURE__ */ new Map());
|
|
17838
|
+
__publicField(this, "usersProviders", /* @__PURE__ */ new Map());
|
|
17839
|
+
/** In-flight host connection promises to avoid duplicate concurrent connects */
|
|
17840
|
+
__publicField(this, "sandboxEffectHostPromises", /* @__PURE__ */ new Map());
|
|
17841
|
+
__publicField(this, "effectHostGenerations", /* @__PURE__ */ new Map());
|
|
17842
|
+
__publicField(this, "effectHostRecovery", /* @__PURE__ */ new Map());
|
|
17843
|
+
/** Ontology-bound environment importer hooks keyed by the caller's ontology identifier. */
|
|
17844
|
+
__publicField(this, "ontologyImporters", /* @__PURE__ */ new Map());
|
|
17845
|
+
/** Resolved importer hooks keyed by sandboxId for fast lookups during openEnvironment(). */
|
|
17846
|
+
__publicField(this, "sandboxImporters", /* @__PURE__ */ new Map());
|
|
17596
17847
|
const auth = options.token ?? options.apiKey;
|
|
17597
17848
|
if (!auth) {
|
|
17598
17849
|
throw new Error(
|
|
@@ -17640,8 +17891,8 @@ var Granular = class _Granular {
|
|
|
17640
17891
|
sandboxId
|
|
17641
17892
|
);
|
|
17642
17893
|
if (!importer) throw new Error("No environment importer registered.");
|
|
17643
|
-
const
|
|
17644
|
-
await
|
|
17894
|
+
const host2 = await this.ensureSandboxEffectHost(sandboxId);
|
|
17895
|
+
await host2.wsClient.call("environment.importer.register", {});
|
|
17645
17896
|
}
|
|
17646
17897
|
clearEnvironmentImporter(ontologyNameOrId) {
|
|
17647
17898
|
this.ontologyImporters.delete(ontologyNameOrId);
|
|
@@ -17743,29 +17994,6 @@ var Granular = class _Granular {
|
|
|
17743
17994
|
"openEnvironment() requires either userId, granularId, or a user object returned by recordUser()."
|
|
17744
17995
|
);
|
|
17745
17996
|
}
|
|
17746
|
-
/**
|
|
17747
|
-
* Open or resolve an ontology environment for one user without opening a session.
|
|
17748
|
-
*
|
|
17749
|
-
* @example
|
|
17750
|
-
* ```typescript
|
|
17751
|
-
* const environment = await granular.openEnvironment({
|
|
17752
|
-
* ontology: 'my-ontology',
|
|
17753
|
-
* tag: 'dev',
|
|
17754
|
-
* userId: 'user_123',
|
|
17755
|
-
* permissions: ['agent'],
|
|
17756
|
-
* });
|
|
17757
|
-
*
|
|
17758
|
-
* await environment.data.record({
|
|
17759
|
-
* className: 'customer',
|
|
17760
|
-
* id: 'acme',
|
|
17761
|
-
* fields: { name: 'Acme' },
|
|
17762
|
-
* });
|
|
17763
|
-
*
|
|
17764
|
-
* const session = await environment.sessions.create();
|
|
17765
|
-
* const job = await session.submitJob(`return "hello";`);
|
|
17766
|
-
* console.log(await job.result);
|
|
17767
|
-
* ```
|
|
17768
|
-
*/
|
|
17769
17997
|
async openEnvironment(options) {
|
|
17770
17998
|
const resolved = await this.resolveOpenEnvironmentData(
|
|
17771
17999
|
options,
|
|
@@ -17775,11 +18003,6 @@ var Granular = class _Granular {
|
|
|
17775
18003
|
await this.maybeRunEnvironmentImporter(resolved, environment);
|
|
17776
18004
|
return environment;
|
|
17777
18005
|
}
|
|
17778
|
-
/**
|
|
17779
|
-
* Read the active environment selected by Granular for an already-recorded
|
|
17780
|
-
* external user. This is intentionally read-only: browser/login code must
|
|
17781
|
-
* not create subjects or environments as a side effect.
|
|
17782
|
-
*/
|
|
17783
18006
|
async getActiveEnvironmentForUser(options) {
|
|
17784
18007
|
const sandboxId = options.sandboxId.trim();
|
|
17785
18008
|
const tagName = options.tag.trim();
|
|
@@ -17825,13 +18048,6 @@ var Granular = class _Granular {
|
|
|
17825
18048
|
throw error;
|
|
17826
18049
|
}
|
|
17827
18050
|
}
|
|
17828
|
-
/**
|
|
17829
|
-
* Resolve one exact environment only when Granular confirms that it belongs
|
|
17830
|
-
* to the given external user in the requested sandbox (and, optionally,
|
|
17831
|
-
* tag). This is deliberately read-only: callers use it to keep an already
|
|
17832
|
-
* opened delegated workspace stable while a newer active environment is
|
|
17833
|
-
* being prepared in the background.
|
|
17834
|
-
*/
|
|
17835
18051
|
async getEnvironmentForUser(options) {
|
|
17836
18052
|
const sandboxId = options.sandboxId.trim();
|
|
17837
18053
|
const userId = options.userId.trim();
|
|
@@ -17874,11 +18090,6 @@ var Granular = class _Granular {
|
|
|
17874
18090
|
}
|
|
17875
18091
|
return this.bindEnvironmentHandle(environment);
|
|
17876
18092
|
}
|
|
17877
|
-
/**
|
|
17878
|
-
* Register one reviewed, pre-existing environment as the active workspace
|
|
17879
|
-
* for an external user. This is for a controlled migration only: it does
|
|
17880
|
-
* not create an environment and it does not run an importer.
|
|
17881
|
-
*/
|
|
17882
18093
|
async adoptEnvironmentForUser(options) {
|
|
17883
18094
|
const sandboxId = options.sandboxId.trim();
|
|
17884
18095
|
const tagName = options.tag.trim();
|
|
@@ -17925,11 +18136,6 @@ var Granular = class _Granular {
|
|
|
17925
18136
|
normalizeEnvironmentData(payload.environment)
|
|
17926
18137
|
);
|
|
17927
18138
|
}
|
|
17928
|
-
/**
|
|
17929
|
-
* Deprecated compatibility alias for `openEnvironment()`.
|
|
17930
|
-
*
|
|
17931
|
-
* `connect()` no longer opens a runtime session automatically.
|
|
17932
|
-
*/
|
|
17933
18139
|
async connect(options) {
|
|
17934
18140
|
return this.openEnvironment({
|
|
17935
18141
|
...options,
|
|
@@ -18233,9 +18439,6 @@ var Granular = class _Granular {
|
|
|
18233
18439
|
setupOperationKey: resetKey
|
|
18234
18440
|
};
|
|
18235
18441
|
}
|
|
18236
|
-
/**
|
|
18237
|
-
* List indexed sessions using ownership filters and bounded pagination.
|
|
18238
|
-
*/
|
|
18239
18442
|
async listSessions(options) {
|
|
18240
18443
|
const items = [];
|
|
18241
18444
|
let cursor = options.cursor?.trim() || void 0;
|
|
@@ -18432,10 +18635,6 @@ var Granular = class _Granular {
|
|
|
18432
18635
|
}
|
|
18433
18636
|
return (/* @__PURE__ */ new Date(0)).toISOString();
|
|
18434
18637
|
}
|
|
18435
|
-
/**
|
|
18436
|
-
* Create a new session (conversation) for an existing environment and connect to it.
|
|
18437
|
-
* The runtime graph is shared across all sessions for the same environment.
|
|
18438
|
-
*/
|
|
18439
18638
|
async createSession(options) {
|
|
18440
18639
|
const clientId = options.clientId || `client_${Date.now()}`;
|
|
18441
18640
|
const sessionScope = options.sessionScope?.trim() || void 0;
|
|
@@ -18456,9 +18655,6 @@ var Granular = class _Granular {
|
|
|
18456
18655
|
});
|
|
18457
18656
|
return this.bindWebSocketEnvironmentSession(environment, clientId, session);
|
|
18458
18657
|
}
|
|
18459
|
-
/**
|
|
18460
|
-
* Connect to an existing open session (same conversation thread) using a freshly minted WebSocket token.
|
|
18461
|
-
*/
|
|
18462
18658
|
async connectSession(options) {
|
|
18463
18659
|
const clientId = options.clientId || `client_${Date.now()}`;
|
|
18464
18660
|
const minted = await this.request(`/ws/sessions/${encodeURIComponent(options.sessionId)}/token`, {
|
|
@@ -18485,7 +18681,6 @@ var Granular = class _Granular {
|
|
|
18485
18681
|
metadata: options?.metadata
|
|
18486
18682
|
});
|
|
18487
18683
|
}
|
|
18488
|
-
/** End a session through the runtime, or disconnect its connected handle. */
|
|
18489
18684
|
async closeSession(sessionId, environment) {
|
|
18490
18685
|
if (environment && environment.sessionId === sessionId) {
|
|
18491
18686
|
await environment.disconnect();
|
|
@@ -18496,9 +18691,6 @@ var Granular = class _Granular {
|
|
|
18496
18691
|
{ method: "POST" }
|
|
18497
18692
|
);
|
|
18498
18693
|
}
|
|
18499
|
-
/**
|
|
18500
|
-
* Re-open a closed session in the index and connect to its existing runtime document.
|
|
18501
|
-
*/
|
|
18502
18694
|
async reopenSession(sessionId, options) {
|
|
18503
18695
|
await this.request(`/control/sessions/${encodeURIComponent(sessionId)}`, {
|
|
18504
18696
|
method: "PATCH",
|
|
@@ -18739,25 +18931,25 @@ var Granular = class _Granular {
|
|
|
18739
18931
|
}
|
|
18740
18932
|
return serialized2;
|
|
18741
18933
|
}
|
|
18742
|
-
async publishSandboxEffectCatalog(
|
|
18934
|
+
async publishSandboxEffectCatalog(host2) {
|
|
18743
18935
|
const effects = Array.from(
|
|
18744
|
-
this.getSandboxEffectMap(
|
|
18936
|
+
this.getSandboxEffectMap(host2.sandboxId).values()
|
|
18745
18937
|
).map((effect) => this.serializeEffect(effect));
|
|
18746
18938
|
let acceptedCount = 0;
|
|
18747
18939
|
const rejected = [];
|
|
18748
18940
|
try {
|
|
18749
18941
|
await withTimeout(
|
|
18750
|
-
|
|
18942
|
+
host2.wsClient.call("effects.resetCatalog", {}),
|
|
18751
18943
|
EFFECT_CATALOG_SYNC_TIMEOUT_MS,
|
|
18752
|
-
`effects.resetCatalog for sandbox ${
|
|
18944
|
+
`effects.resetCatalog for sandbox ${host2.sandboxId}`
|
|
18753
18945
|
);
|
|
18754
18946
|
for (const batch of chunkItems(effects, EFFECT_CATALOG_SYNC_BATCH_SIZE)) {
|
|
18755
18947
|
const result = await withTimeout(
|
|
18756
|
-
|
|
18948
|
+
host2.wsClient.call("effects.addCatalog", {
|
|
18757
18949
|
effects: batch
|
|
18758
18950
|
}),
|
|
18759
18951
|
EFFECT_CATALOG_SYNC_TIMEOUT_MS,
|
|
18760
|
-
`effects.addCatalog for sandbox ${
|
|
18952
|
+
`effects.addCatalog for sandbox ${host2.sandboxId}`
|
|
18761
18953
|
);
|
|
18762
18954
|
acceptedCount += typeof result?.acceptedCount === "number" ? result.acceptedCount : 0;
|
|
18763
18955
|
if (Array.isArray(result?.rejected)) {
|
|
@@ -18769,11 +18961,11 @@ var Granular = class _Granular {
|
|
|
18769
18961
|
throw error;
|
|
18770
18962
|
}
|
|
18771
18963
|
const result = await withTimeout(
|
|
18772
|
-
|
|
18964
|
+
host2.wsClient.call("effects.publishCatalog", {
|
|
18773
18965
|
effects
|
|
18774
18966
|
}),
|
|
18775
18967
|
EFFECT_CATALOG_SYNC_TIMEOUT_MS,
|
|
18776
|
-
`effects.publishCatalog for sandbox ${
|
|
18968
|
+
`effects.publishCatalog for sandbox ${host2.sandboxId}`
|
|
18777
18969
|
);
|
|
18778
18970
|
acceptedCount = typeof result?.acceptedCount === "number" ? result.acceptedCount : 0;
|
|
18779
18971
|
if (Array.isArray(result?.rejected)) {
|
|
@@ -18785,12 +18977,12 @@ var Granular = class _Granular {
|
|
|
18785
18977
|
(entry) => `${entry.name || "unknown"}: ${entry.reason || "rejected"}`
|
|
18786
18978
|
).join("; ");
|
|
18787
18979
|
throw new Error(
|
|
18788
|
-
`Failed to publish live effects for sandbox ${
|
|
18980
|
+
`Failed to publish live effects for sandbox ${host2.sandboxId}: ${detail}`
|
|
18789
18981
|
);
|
|
18790
18982
|
}
|
|
18791
18983
|
if (rejected.length > 0) {
|
|
18792
18984
|
console.warn(
|
|
18793
|
-
`[Granular] Some live effects were rejected for sandbox ${
|
|
18985
|
+
`[Granular] Some live effects were rejected for sandbox ${host2.sandboxId}:`,
|
|
18794
18986
|
rejected
|
|
18795
18987
|
);
|
|
18796
18988
|
}
|
|
@@ -18799,8 +18991,8 @@ var Granular = class _Granular {
|
|
|
18799
18991
|
let lastError;
|
|
18800
18992
|
for (let attempt = 1; attempt <= EFFECT_CATALOG_SYNC_RETRY_COUNT; attempt += 1) {
|
|
18801
18993
|
try {
|
|
18802
|
-
const
|
|
18803
|
-
await this.publishSandboxEffectCatalog(
|
|
18994
|
+
const host2 = await this.ensureSandboxEffectHost(sandboxId);
|
|
18995
|
+
await this.publishSandboxEffectCatalog(host2);
|
|
18804
18996
|
return;
|
|
18805
18997
|
} catch (error) {
|
|
18806
18998
|
lastError = error;
|
|
@@ -18817,11 +19009,11 @@ var Granular = class _Granular {
|
|
|
18817
19009
|
}
|
|
18818
19010
|
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
18819
19011
|
}
|
|
18820
|
-
recoverEffectHost(
|
|
18821
|
-
const sandboxId =
|
|
18822
|
-
if (
|
|
19012
|
+
recoverEffectHost(host2, error) {
|
|
19013
|
+
const sandboxId = host2.sandboxId;
|
|
19014
|
+
if (host2.recovering || this.sandboxEffectHosts.get(sandboxId) !== host2)
|
|
18823
19015
|
return;
|
|
18824
|
-
|
|
19016
|
+
host2.recovering = true;
|
|
18825
19017
|
this.disconnectSandboxEffectHost(sandboxId);
|
|
18826
19018
|
const state = {
|
|
18827
19019
|
attempt: 0,
|
|
@@ -18844,7 +19036,7 @@ var Granular = class _Granular {
|
|
|
18844
19036
|
);
|
|
18845
19037
|
try {
|
|
18846
19038
|
this.onReconnectError?.({
|
|
18847
|
-
sessionId: `effect-host:${
|
|
19039
|
+
sessionId: `effect-host:${host2.effectClientId}`,
|
|
18848
19040
|
error: reconnectError instanceof Error ? reconnectError.message : String(reconnectError),
|
|
18849
19041
|
timestamp: Date.now(),
|
|
18850
19042
|
terminal: !retryable
|
|
@@ -18897,13 +19089,13 @@ var Granular = class _Granular {
|
|
|
18897
19089
|
)
|
|
18898
19090
|
};
|
|
18899
19091
|
}
|
|
18900
|
-
async recoverSourceCommits(
|
|
19092
|
+
async recoverSourceCommits(host2) {
|
|
18901
19093
|
const stores = new Set(
|
|
18902
|
-
Array.from(this.getSandboxEffectMap(
|
|
19094
|
+
Array.from(this.getSandboxEffectMap(host2.sandboxId).values()).map((effect) => effect.commit?.storage).filter(Boolean)
|
|
18903
19095
|
);
|
|
18904
19096
|
for (const store of stores) {
|
|
18905
19097
|
try {
|
|
18906
|
-
await store.recover(this.effectCommitTransport(),
|
|
19098
|
+
await store.recover(this.effectCommitTransport(), host2.sandboxId);
|
|
18907
19099
|
} catch (error) {
|
|
18908
19100
|
console.warn(
|
|
18909
19101
|
"[Granular] Source commit delivery remains pending:",
|
|
@@ -18912,43 +19104,43 @@ var Granular = class _Granular {
|
|
|
18912
19104
|
}
|
|
18913
19105
|
}
|
|
18914
19106
|
}
|
|
18915
|
-
startEffectHostHeartbeat(
|
|
18916
|
-
if (
|
|
18917
|
-
clearInterval(
|
|
19107
|
+
startEffectHostHeartbeat(host2) {
|
|
19108
|
+
if (host2.heartbeatTimer) {
|
|
19109
|
+
clearInterval(host2.heartbeatTimer);
|
|
18918
19110
|
}
|
|
18919
|
-
|
|
19111
|
+
host2.heartbeatInFlight = false;
|
|
18920
19112
|
const sendHeartbeat = (failureLabel, recoverOnFailure) => {
|
|
18921
|
-
if (
|
|
19113
|
+
if (host2.heartbeatInFlight || host2.recovering) {
|
|
18922
19114
|
return;
|
|
18923
19115
|
}
|
|
18924
|
-
|
|
18925
|
-
|
|
18926
|
-
console.warn(`${failureLabel} ${
|
|
19116
|
+
host2.heartbeatInFlight = true;
|
|
19117
|
+
host2.wsClient.call("client.heartbeat", {}).then(() => this.recoverSourceCommits(host2)).catch((error) => {
|
|
19118
|
+
console.warn(`${failureLabel} ${host2.sandboxId}:`, error);
|
|
18927
19119
|
if (recoverOnFailure) {
|
|
18928
|
-
this.recoverEffectHost(
|
|
19120
|
+
this.recoverEffectHost(host2, error);
|
|
18929
19121
|
}
|
|
18930
19122
|
}).finally(() => {
|
|
18931
|
-
|
|
19123
|
+
host2.heartbeatInFlight = false;
|
|
18932
19124
|
});
|
|
18933
19125
|
};
|
|
18934
19126
|
sendHeartbeat(
|
|
18935
19127
|
"[Granular] Initial effect host heartbeat failed for sandbox",
|
|
18936
19128
|
false
|
|
18937
19129
|
);
|
|
18938
|
-
|
|
19130
|
+
host2.heartbeatTimer = setInterval(() => {
|
|
18939
19131
|
sendHeartbeat(
|
|
18940
19132
|
"[Granular] Effect host heartbeat failed for sandbox",
|
|
18941
19133
|
true
|
|
18942
19134
|
);
|
|
18943
19135
|
}, 1e4);
|
|
18944
19136
|
}
|
|
18945
|
-
stopEffectHostHeartbeat(
|
|
18946
|
-
if (!
|
|
19137
|
+
stopEffectHostHeartbeat(host2) {
|
|
19138
|
+
if (!host2?.heartbeatTimer) {
|
|
18947
19139
|
return;
|
|
18948
19140
|
}
|
|
18949
|
-
clearInterval(
|
|
18950
|
-
|
|
18951
|
-
|
|
19141
|
+
clearInterval(host2.heartbeatTimer);
|
|
19142
|
+
host2.heartbeatTimer = null;
|
|
19143
|
+
host2.heartbeatInFlight = false;
|
|
18952
19144
|
}
|
|
18953
19145
|
async registerUsers(ontologyNameOrId, handler, options) {
|
|
18954
19146
|
const provider = new UsersProvider(handler, options);
|
|
@@ -18956,8 +19148,8 @@ var Granular = class _Granular {
|
|
|
18956
19148
|
const previous = this.usersProviders.get(sandboxId);
|
|
18957
19149
|
this.usersProviders.set(sandboxId, provider);
|
|
18958
19150
|
try {
|
|
18959
|
-
const
|
|
18960
|
-
if (provider.registration?.providerId !==
|
|
19151
|
+
const host2 = await this.ensureSandboxEffectHost(sandboxId);
|
|
19152
|
+
if (provider.registration?.providerId !== host2.effectClientId) await this.registerUsersOnHost(host2, provider);
|
|
18961
19153
|
if (!provider.registration) throw new Error("User directory registration is no longer live.");
|
|
18962
19154
|
return provider.registration;
|
|
18963
19155
|
} catch (error) {
|
|
@@ -18968,10 +19160,10 @@ var Granular = class _Granular {
|
|
|
18968
19160
|
throw error;
|
|
18969
19161
|
}
|
|
18970
19162
|
}
|
|
18971
|
-
async registerUsersOnHost(
|
|
18972
|
-
const registration = await
|
|
18973
|
-
if (this.usersProviders.get(
|
|
18974
|
-
provider.bind(registration,
|
|
19163
|
+
async registerUsersOnHost(host2, provider) {
|
|
19164
|
+
const registration = await host2.wsClient.call("users.register", {});
|
|
19165
|
+
if (this.usersProviders.get(host2.sandboxId) !== provider) throw new Error("User directory registration was replaced.");
|
|
19166
|
+
provider.bind(registration, host2.sandboxId, host2.effectClientId);
|
|
18975
19167
|
}
|
|
18976
19168
|
/** Publish only public setup metadata; product session authority stays in resolveLaunch. */
|
|
18977
19169
|
async registerCustomerSkill(ontologyNameOrId, options) {
|
|
@@ -19023,10 +19215,10 @@ var Granular = class _Granular {
|
|
|
19023
19215
|
const previous = this.developmentProviders.get(sandboxId);
|
|
19024
19216
|
this.developmentProviders.set(sandboxId, provider);
|
|
19025
19217
|
try {
|
|
19026
|
-
const
|
|
19218
|
+
const host2 = await this.ensureSandboxEffectHost(sandboxId);
|
|
19027
19219
|
if (this.developmentProviders.get(sandboxId) !== provider) throw new Error("Development registration was replaced.");
|
|
19028
|
-
if (provider.registration?.providerId !==
|
|
19029
|
-
await this.registerDevelopmentOnHost(
|
|
19220
|
+
if (provider.registration?.providerId !== host2.effectClientId) {
|
|
19221
|
+
await this.registerDevelopmentOnHost(host2, provider);
|
|
19030
19222
|
}
|
|
19031
19223
|
if (!provider.registration) throw new Error("Development provider registration is no longer live.");
|
|
19032
19224
|
return provider.registration;
|
|
@@ -19038,38 +19230,38 @@ var Granular = class _Granular {
|
|
|
19038
19230
|
throw error;
|
|
19039
19231
|
}
|
|
19040
19232
|
}
|
|
19041
|
-
async registerDevelopmentOnHost(
|
|
19042
|
-
const registration = await
|
|
19233
|
+
async registerDevelopmentOnHost(host2, provider) {
|
|
19234
|
+
const registration = await host2.wsClient.call(
|
|
19043
19235
|
"onboarding.register",
|
|
19044
19236
|
provider.registrationParams()
|
|
19045
19237
|
);
|
|
19046
|
-
if (this.developmentProviders.get(
|
|
19238
|
+
if (this.developmentProviders.get(host2.sandboxId) !== provider)
|
|
19047
19239
|
throw new Error("Development registration was replaced.");
|
|
19048
|
-
provider.bind(registration,
|
|
19240
|
+
provider.bind(registration, host2.sandboxId, host2.effectClientId);
|
|
19049
19241
|
}
|
|
19050
|
-
async synchronizeEffectHost(
|
|
19051
|
-
if (
|
|
19052
|
-
return
|
|
19242
|
+
async synchronizeEffectHost(host2) {
|
|
19243
|
+
if (host2.syncPromise) {
|
|
19244
|
+
return host2.syncPromise;
|
|
19053
19245
|
}
|
|
19054
|
-
|
|
19055
|
-
await
|
|
19056
|
-
clientId:
|
|
19246
|
+
host2.syncPromise = (async () => {
|
|
19247
|
+
await host2.wsClient.call("client.hello", {
|
|
19248
|
+
clientId: host2.clientId,
|
|
19057
19249
|
protocolVersion: "2.0"
|
|
19058
19250
|
});
|
|
19059
|
-
await this.publishSandboxEffectCatalog(
|
|
19060
|
-
if (this.resolveEnvironmentImporter(
|
|
19061
|
-
await
|
|
19062
|
-
const users2 = this.usersProviders.get(
|
|
19063
|
-
if (users2) await this.registerUsersOnHost(
|
|
19064
|
-
const development = this.developmentProviders.get(
|
|
19065
|
-
if (development) await this.registerDevelopmentOnHost(
|
|
19066
|
-
this.startEffectHostHeartbeat(
|
|
19251
|
+
await this.publishSandboxEffectCatalog(host2);
|
|
19252
|
+
if (this.resolveEnvironmentImporter(host2.sandboxId, host2.sandboxId))
|
|
19253
|
+
await host2.wsClient.call("environment.importer.register", {});
|
|
19254
|
+
const users2 = this.usersProviders.get(host2.sandboxId);
|
|
19255
|
+
if (users2) await this.registerUsersOnHost(host2, users2);
|
|
19256
|
+
const development = this.developmentProviders.get(host2.sandboxId);
|
|
19257
|
+
if (development) await this.registerDevelopmentOnHost(host2, development);
|
|
19258
|
+
this.startEffectHostHeartbeat(host2);
|
|
19067
19259
|
})();
|
|
19068
19260
|
try {
|
|
19069
|
-
await
|
|
19261
|
+
await host2.syncPromise;
|
|
19070
19262
|
} finally {
|
|
19071
|
-
if (
|
|
19072
|
-
|
|
19263
|
+
if (host2.syncPromise) {
|
|
19264
|
+
host2.syncPromise = null;
|
|
19073
19265
|
}
|
|
19074
19266
|
}
|
|
19075
19267
|
}
|
|
@@ -19099,7 +19291,7 @@ var Granular = class _Granular {
|
|
|
19099
19291
|
onUnexpectedClose: this.onUnexpectedClose,
|
|
19100
19292
|
onReconnectError: this.onReconnectError
|
|
19101
19293
|
});
|
|
19102
|
-
const
|
|
19294
|
+
const host2 = {
|
|
19103
19295
|
generation: generation2,
|
|
19104
19296
|
sandboxId,
|
|
19105
19297
|
effectClientId,
|
|
@@ -19186,20 +19378,20 @@ var Granular = class _Granular {
|
|
|
19186
19378
|
};
|
|
19187
19379
|
});
|
|
19188
19380
|
wsClient.on("open", () => {
|
|
19189
|
-
void this.synchronizeEffectHost(
|
|
19381
|
+
void this.synchronizeEffectHost(host2).catch((error) => {
|
|
19190
19382
|
console.error(
|
|
19191
19383
|
`[Granular] Failed to re-sync effect host for sandbox ${sandboxId}:`,
|
|
19192
19384
|
error
|
|
19193
19385
|
);
|
|
19194
|
-
this.recoverEffectHost(
|
|
19386
|
+
this.recoverEffectHost(host2, error);
|
|
19195
19387
|
});
|
|
19196
19388
|
});
|
|
19197
19389
|
wsClient.on("disconnect", () => {
|
|
19198
|
-
this.stopEffectHostHeartbeat(
|
|
19390
|
+
this.stopEffectHostHeartbeat(host2);
|
|
19199
19391
|
const users2 = this.usersProviders.get(sandboxId);
|
|
19200
|
-
if (users2?.registration?.providerId ===
|
|
19392
|
+
if (users2?.registration?.providerId === host2.effectClientId) users2.unbind();
|
|
19201
19393
|
const provider = this.developmentProviders.get(sandboxId);
|
|
19202
|
-
if (provider?.registration?.providerId ===
|
|
19394
|
+
if (provider?.registration?.providerId === host2.effectClientId) provider.unbind();
|
|
19203
19395
|
});
|
|
19204
19396
|
try {
|
|
19205
19397
|
await withTimeout(
|
|
@@ -19207,13 +19399,13 @@ var Granular = class _Granular {
|
|
|
19207
19399
|
EFFECT_HOST_CONNECT_TIMEOUT_MS,
|
|
19208
19400
|
`effect host WebSocket connect for sandbox ${sandboxId}`
|
|
19209
19401
|
);
|
|
19210
|
-
await this.synchronizeEffectHost(
|
|
19402
|
+
await this.synchronizeEffectHost(host2);
|
|
19211
19403
|
if ((this.effectHostGenerations.get(sandboxId) || 0) !== generation2)
|
|
19212
19404
|
throw new Error("Effect host connection was canceled");
|
|
19213
|
-
this.sandboxEffectHosts.set(sandboxId,
|
|
19214
|
-
return
|
|
19405
|
+
this.sandboxEffectHosts.set(sandboxId, host2);
|
|
19406
|
+
return host2;
|
|
19215
19407
|
} catch (error) {
|
|
19216
|
-
this.stopEffectHostHeartbeat(
|
|
19408
|
+
this.stopEffectHostHeartbeat(host2);
|
|
19217
19409
|
wsClient.disconnect({ reason: "Effect host initialization failed" });
|
|
19218
19410
|
throw error;
|
|
19219
19411
|
}
|
|
@@ -19237,20 +19429,14 @@ var Granular = class _Granular {
|
|
|
19237
19429
|
const recovering = this.effectHostRecovery.get(sandboxId);
|
|
19238
19430
|
if (recovering?.timer) clearTimeout(recovering.timer);
|
|
19239
19431
|
this.effectHostRecovery.delete(sandboxId);
|
|
19240
|
-
const
|
|
19241
|
-
if (!
|
|
19432
|
+
const host2 = this.sandboxEffectHosts.get(sandboxId);
|
|
19433
|
+
if (!host2) {
|
|
19242
19434
|
return;
|
|
19243
19435
|
}
|
|
19244
19436
|
this.sandboxEffectHosts.delete(sandboxId);
|
|
19245
|
-
this.stopEffectHostHeartbeat(
|
|
19246
|
-
|
|
19437
|
+
this.stopEffectHostHeartbeat(host2);
|
|
19438
|
+
host2.wsClient.disconnect();
|
|
19247
19439
|
}
|
|
19248
|
-
/**
|
|
19249
|
-
* Register an effect (tool) for a specific sandbox.
|
|
19250
|
-
*
|
|
19251
|
-
* @param sandboxNameOrId - The name or ID of the sandbox
|
|
19252
|
-
* @param effect - The tool definition and handler
|
|
19253
|
-
*/
|
|
19254
19440
|
async registerEffect(sandboxNameOrId, effect) {
|
|
19255
19441
|
const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
|
|
19256
19442
|
const sandboxId = sandbox.sandboxId;
|
|
@@ -19260,11 +19446,6 @@ var Granular = class _Granular {
|
|
|
19260
19446
|
);
|
|
19261
19447
|
await this.syncSandboxEffectCatalog(sandboxId);
|
|
19262
19448
|
}
|
|
19263
|
-
/**
|
|
19264
|
-
* Register multiple effects (tools) for a specific sandbox.
|
|
19265
|
-
*
|
|
19266
|
-
* batch version of `registerEffect`.
|
|
19267
|
-
*/
|
|
19268
19449
|
async registerEffects(sandboxNameOrId, effects) {
|
|
19269
19450
|
const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
|
|
19270
19451
|
const sandboxId = sandbox.sandboxId;
|
|
@@ -19274,12 +19455,6 @@ var Granular = class _Granular {
|
|
|
19274
19455
|
}
|
|
19275
19456
|
await this.syncSandboxEffectCatalog(sandboxId);
|
|
19276
19457
|
}
|
|
19277
|
-
/**
|
|
19278
|
-
* Unregister an effect from a sandbox.
|
|
19279
|
-
*
|
|
19280
|
-
* Removes it from the local sandbox registry and updates the
|
|
19281
|
-
* sandbox-scoped live catalog.
|
|
19282
|
-
*/
|
|
19283
19458
|
async unregisterEffect(sandboxNameOrId, name) {
|
|
19284
19459
|
const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
|
|
19285
19460
|
const sandboxId = sandbox.sandboxId;
|
|
@@ -19302,12 +19477,6 @@ var Granular = class _Granular {
|
|
|
19302
19477
|
}
|
|
19303
19478
|
await this.syncSandboxEffectCatalog(sandboxId);
|
|
19304
19479
|
}
|
|
19305
|
-
/**
|
|
19306
|
-
* Disconnect one sandbox-scoped effect host, or all of them when no sandbox is provided.
|
|
19307
|
-
*
|
|
19308
|
-
* This is primarily useful for long-lived helper processes such as generated
|
|
19309
|
-
* `granular-effects.ts` scripts that need to shut down cleanly on SIGINT/SIGTERM.
|
|
19310
|
-
*/
|
|
19311
19480
|
async disconnectEffects(sandboxNameOrId) {
|
|
19312
19481
|
if (sandboxNameOrId) {
|
|
19313
19482
|
const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
|
|
@@ -19732,9 +19901,6 @@ var Granular = class _Granular {
|
|
|
19732
19901
|
throw new Error(`Ontology not found: ${ontologyNameOrId}`);
|
|
19733
19902
|
return result.items[0].sandboxId;
|
|
19734
19903
|
}
|
|
19735
|
-
/**
|
|
19736
|
-
* Make an authenticated API request
|
|
19737
|
-
*/
|
|
19738
19904
|
async request(path, options = {}) {
|
|
19739
19905
|
const url = `${this.httpUrl}${path}`;
|
|
19740
19906
|
if (this.debugHttp) {
|
|
@@ -19784,6 +19950,33 @@ var Granular = class _Granular {
|
|
|
19784
19950
|
throw new Error(`Granular API Error: exhausted retries for ${url}`);
|
|
19785
19951
|
}
|
|
19786
19952
|
};
|
|
19953
|
+
_init3 = __decoratorStart(null);
|
|
19954
|
+
__decorateElement(_init3, 1, "openEnvironment", _openEnvironment_dec, _Granular);
|
|
19955
|
+
__decorateElement(_init3, 1, "getActiveEnvironmentForUser", _getActiveEnvironmentForUser_dec, _Granular);
|
|
19956
|
+
__decorateElement(_init3, 1, "getEnvironmentForUser", _getEnvironmentForUser_dec, _Granular);
|
|
19957
|
+
__decorateElement(_init3, 1, "adoptEnvironmentForUser", _adoptEnvironmentForUser_dec, _Granular);
|
|
19958
|
+
__decorateElement(_init3, 1, "connect", _connect_dec, _Granular);
|
|
19959
|
+
__decorateElement(_init3, 1, "listSessions", _listSessions_dec2, _Granular);
|
|
19960
|
+
__decorateElement(_init3, 1, "createSession", _createSession_dec2, _Granular);
|
|
19961
|
+
__decorateElement(_init3, 1, "connectSession", _connectSession_dec2, _Granular);
|
|
19962
|
+
__decorateElement(_init3, 1, "closeSession", _closeSession_dec2, _Granular);
|
|
19963
|
+
__decorateElement(_init3, 1, "reopenSession", _reopenSession_dec, _Granular);
|
|
19964
|
+
__decorateElement(_init3, 1, "registerEffect", _registerEffect_dec, _Granular);
|
|
19965
|
+
__decorateElement(_init3, 1, "registerEffects", _registerEffects_dec, _Granular);
|
|
19966
|
+
__decorateElement(_init3, 1, "unregisterEffect", _unregisterEffect_dec, _Granular);
|
|
19967
|
+
__decorateElement(_init3, 1, "disconnectEffects", _disconnectEffects_dec, _Granular);
|
|
19968
|
+
__decorateElement(_init3, 1, "request", _request_dec, _Granular);
|
|
19969
|
+
__decorateElement(_init3, 13, "transport", _transport_dec, _Granular);
|
|
19970
|
+
__decorateElement(_init3, 13, "effectHosts", _effectHosts_dec, _Granular);
|
|
19971
|
+
__decorateElement(_init3, 13, "sessions", _sessions_dec2, _Granular);
|
|
19972
|
+
__decorateElement(_init3, 13, "environmentAccess", _environmentAccess_dec, _Granular);
|
|
19973
|
+
_Granular = __decorateElement(_init3, 0, "Granular", _Granular_decorators, _Granular);
|
|
19974
|
+
__publicField(_Granular, "transport", __runInitializers(_init3, 8, _Granular)), __runInitializers(_init3, 11, _Granular);
|
|
19975
|
+
__publicField(_Granular, "effectHosts", __runInitializers(_init3, 12, _Granular)), __runInitializers(_init3, 15, _Granular);
|
|
19976
|
+
__publicField(_Granular, "sessions", __runInitializers(_init3, 16, _Granular)), __runInitializers(_init3, 19, _Granular);
|
|
19977
|
+
__publicField(_Granular, "environmentAccess", __runInitializers(_init3, 20, _Granular)), __runInitializers(_init3, 23, _Granular);
|
|
19978
|
+
__runInitializers(_init3, 1, _Granular);
|
|
19979
|
+
var Granular = _Granular;
|
|
19787
19980
|
|
|
19788
19981
|
// src/environment-setup.ts
|
|
19789
19982
|
var EnvironmentSetupTerminalError = class extends Error {
|
|
@@ -24536,7 +24729,7 @@ function createOnboardingIncrementalRunner(options) {
|
|
|
24536
24729
|
let again = false;
|
|
24537
24730
|
let generation2 = 0;
|
|
24538
24731
|
let unsubscribe;
|
|
24539
|
-
const
|
|
24732
|
+
const publish2 = (next) => {
|
|
24540
24733
|
status = next;
|
|
24541
24734
|
try {
|
|
24542
24735
|
options.onStatus?.(next);
|
|
@@ -24551,21 +24744,21 @@ function createOnboardingIncrementalRunner(options) {
|
|
|
24551
24744
|
try {
|
|
24552
24745
|
if (active) options.source.scheduleRetry(wake);
|
|
24553
24746
|
} catch {
|
|
24554
|
-
return
|
|
24747
|
+
return publish2({
|
|
24555
24748
|
status: "unknown",
|
|
24556
24749
|
message: "Product retry scheduler is unavailable."
|
|
24557
24750
|
});
|
|
24558
24751
|
}
|
|
24559
|
-
return
|
|
24752
|
+
return publish2(value);
|
|
24560
24753
|
};
|
|
24561
24754
|
const execute = async () => {
|
|
24562
24755
|
const started = generation2;
|
|
24563
24756
|
const interrupted = () => started !== generation2;
|
|
24564
|
-
const stopped = () =>
|
|
24757
|
+
const stopped = () => publish2({
|
|
24565
24758
|
status: "unknown",
|
|
24566
24759
|
message: "Change source is stopped; freshness is unknown."
|
|
24567
24760
|
});
|
|
24568
|
-
|
|
24761
|
+
publish2({ status: "checking" });
|
|
24569
24762
|
let cursor;
|
|
24570
24763
|
try {
|
|
24571
24764
|
cursor = await options.source.readCheckpoint();
|
|
@@ -24633,7 +24826,7 @@ function createOnboardingIncrementalRunner(options) {
|
|
|
24633
24826
|
eventId: item.change.eventId,
|
|
24634
24827
|
observationId: receipt.observationId
|
|
24635
24828
|
};
|
|
24636
|
-
return next.status === "failed" ?
|
|
24829
|
+
return next.status === "failed" ? publish2(next) : defer(next);
|
|
24637
24830
|
}
|
|
24638
24831
|
try {
|
|
24639
24832
|
if (!await options.source.advanceCheckpoint(cursor, item.cursor))
|
|
@@ -24656,13 +24849,13 @@ function createOnboardingIncrementalRunner(options) {
|
|
|
24656
24849
|
visited.add(cursor);
|
|
24657
24850
|
}
|
|
24658
24851
|
if (page.caughtUp)
|
|
24659
|
-
return
|
|
24852
|
+
return publish2({ status: "source_current", checkedAt: Date.now() });
|
|
24660
24853
|
if (!page.events.length)
|
|
24661
24854
|
return defer({
|
|
24662
24855
|
status: "unknown",
|
|
24663
24856
|
message: "Source has not established a current high-water mark."
|
|
24664
24857
|
});
|
|
24665
|
-
|
|
24858
|
+
publish2({ status: "catching_up" });
|
|
24666
24859
|
}
|
|
24667
24860
|
return defer({ status: "catching_up" });
|
|
24668
24861
|
};
|
|
@@ -24689,7 +24882,7 @@ function createOnboardingIncrementalRunner(options) {
|
|
|
24689
24882
|
try {
|
|
24690
24883
|
await options.retryObservation(status.observationId);
|
|
24691
24884
|
} catch {
|
|
24692
|
-
return
|
|
24885
|
+
return publish2({
|
|
24693
24886
|
status: "unknown",
|
|
24694
24887
|
message: "Projection retry could not be confirmed; retain the source checkpoint.",
|
|
24695
24888
|
observationId: status.observationId
|
|
@@ -24706,7 +24899,7 @@ function createOnboardingIncrementalRunner(options) {
|
|
|
24706
24899
|
} catch {
|
|
24707
24900
|
active = false;
|
|
24708
24901
|
unsubscribe = void 0;
|
|
24709
|
-
|
|
24902
|
+
publish2({ status: "unknown", message: "Change source subscription is unavailable; retry start." });
|
|
24710
24903
|
return;
|
|
24711
24904
|
}
|
|
24712
24905
|
wake();
|
|
@@ -24716,7 +24909,7 @@ function createOnboardingIncrementalRunner(options) {
|
|
|
24716
24909
|
generation2++;
|
|
24717
24910
|
unsubscribe?.();
|
|
24718
24911
|
unsubscribe = void 0;
|
|
24719
|
-
|
|
24912
|
+
publish2({
|
|
24720
24913
|
status: "unknown",
|
|
24721
24914
|
message: "Change source is stopped; freshness is unknown."
|
|
24722
24915
|
});
|
|
@@ -24810,7 +25003,7 @@ var SourceMutationRejected = class extends Error {
|
|
|
24810
25003
|
this.providerFailure = providerFailure;
|
|
24811
25004
|
}
|
|
24812
25005
|
};
|
|
24813
|
-
function
|
|
25006
|
+
function identity2(i) {
|
|
24814
25007
|
if (!i.context.sandboxId || !i.context.environmentId || !i.context.user?.subjectId || !i.operationId || !i.effectKey)
|
|
24815
25008
|
throw Error("Source commit storage requires trusted invocation scope");
|
|
24816
25009
|
return {
|
|
@@ -24859,7 +25052,7 @@ function sqliteCommitStorage(db) {
|
|
|
24859
25052
|
accepted INTEGER NOT NULL DEFAULT 0, attempts INTEGER NOT NULL DEFAULT 0, last_error TEXT,
|
|
24860
25053
|
PRIMARY KEY(scope,operation_id), UNIQUE(scope,invocation_id));`);
|
|
24861
25054
|
const prior = (i) => {
|
|
24862
|
-
const k =
|
|
25055
|
+
const k = identity2(i);
|
|
24863
25056
|
const row3 = db.query(
|
|
24864
25057
|
"SELECT * FROM granular_source_commits WHERE scope=? AND operation_id=?"
|
|
24865
25058
|
).get(k.scope, i.operationId);
|
|
@@ -24868,7 +25061,7 @@ function sqliteCommitStorage(db) {
|
|
|
24868
25061
|
return row3;
|
|
24869
25062
|
};
|
|
24870
25063
|
const save2 = (i, receipt, request) => {
|
|
24871
|
-
const k =
|
|
25064
|
+
const k = identity2(i);
|
|
24872
25065
|
db.query(
|
|
24873
25066
|
"INSERT INTO granular_source_commits(scope,operation_id,fingerprint,sandbox_id,invocation_id,receipt_json,commit_json) VALUES(?,?,?,?,?,?,?)"
|
|
24874
25067
|
).run(
|