@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/cli/index.js
CHANGED
|
@@ -52,6 +52,12 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
52
52
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
53
53
|
var __getProtoOf = Object.getPrototypeOf;
|
|
54
54
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
55
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
56
|
+
var __typeError = (msg) => {
|
|
57
|
+
throw TypeError(msg);
|
|
58
|
+
};
|
|
59
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
60
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
55
61
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
56
62
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
57
63
|
}) : x)(function(x) {
|
|
@@ -84,6 +90,306 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
84
90
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
85
91
|
mod
|
|
86
92
|
));
|
|
93
|
+
var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
|
|
94
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
95
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
96
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
97
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
98
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
99
|
+
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);
|
|
100
|
+
return value;
|
|
101
|
+
};
|
|
102
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
103
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
104
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
105
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
106
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
107
|
+
return __privateGet(this, extra);
|
|
108
|
+
}, set [name](x) {
|
|
109
|
+
return __privateSet(this, extra, x);
|
|
110
|
+
} }, name));
|
|
111
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
112
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
113
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
114
|
+
if (k) {
|
|
115
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
116
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
117
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
118
|
+
}
|
|
119
|
+
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;
|
|
120
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
121
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
122
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
123
|
+
}
|
|
124
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
125
|
+
};
|
|
126
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
127
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
128
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
129
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
130
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
131
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
132
|
+
|
|
133
|
+
// ../fractory/dist/annotations.js
|
|
134
|
+
function publish(event, adapter) {
|
|
135
|
+
try {
|
|
136
|
+
adapter?.emit(event);
|
|
137
|
+
} catch {
|
|
138
|
+
}
|
|
139
|
+
for (const listener of listeners) {
|
|
140
|
+
try {
|
|
141
|
+
listener(event);
|
|
142
|
+
} catch {
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function identity(value) {
|
|
147
|
+
if (!value.trim())
|
|
148
|
+
throw new Error("Fractal identity must not be empty");
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
function Block(id3, options = {}) {
|
|
152
|
+
const definition = typeof id3 === "string" ? { ...options, id: identity(id3) } : { ...id3, id: identity(id3.id) };
|
|
153
|
+
return (target, _context) => {
|
|
154
|
+
blocks.set(target, definition);
|
|
155
|
+
return target;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function makeInterface(owner, name, options) {
|
|
159
|
+
return Object.freeze({
|
|
160
|
+
[interfaceBrand]: true,
|
|
161
|
+
name,
|
|
162
|
+
options: Object.freeze({ ...options }),
|
|
163
|
+
get blockId() {
|
|
164
|
+
const definition = blocks.get(owner());
|
|
165
|
+
if (!definition)
|
|
166
|
+
throw new Error(`Interface ${name} needs an annotated block`);
|
|
167
|
+
return definition.id;
|
|
168
|
+
},
|
|
169
|
+
get id() {
|
|
170
|
+
return options.id || `${this.blockId}::${name}`;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function Interface(options = {}, details = {}) {
|
|
175
|
+
if (typeof options === "string") {
|
|
176
|
+
const id3 = identity(options), name = id3.split("/").slice(-1)[0];
|
|
177
|
+
if (details.parent)
|
|
178
|
+
return makeInterface(details.parent, name, { ...details, id: id3 });
|
|
179
|
+
return Object.freeze({
|
|
180
|
+
[interfaceBrand]: true,
|
|
181
|
+
id: id3,
|
|
182
|
+
name,
|
|
183
|
+
blockId: id3.includes("/") ? id3.slice(0, id3.lastIndexOf("/")) : "factory",
|
|
184
|
+
options: Object.freeze({ ...details, id: id3 })
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if ("parent" in options)
|
|
188
|
+
return makeInterface(options.parent, identity(options.id).split("/").slice(-1)[0], options);
|
|
189
|
+
return interfaceDecorator(options);
|
|
190
|
+
}
|
|
191
|
+
function interfaceDecorator(options) {
|
|
192
|
+
function decorate(target, context) {
|
|
193
|
+
if (typeof context === "object") {
|
|
194
|
+
if (!context.static || context.private)
|
|
195
|
+
throw new Error("@Interface requires a public static field");
|
|
196
|
+
context.addInitializer(function() {
|
|
197
|
+
const owner = this;
|
|
198
|
+
if (!owner[context.name]?.[interfaceBrand])
|
|
199
|
+
Object.defineProperty(owner, context.name, {
|
|
200
|
+
value: makeInterface(() => owner, String(context.name), options),
|
|
201
|
+
writable: false,
|
|
202
|
+
configurable: true
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
return function() {
|
|
206
|
+
return makeInterface(() => this, String(context.name), options);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const value = makeInterface(() => target, String(context), options);
|
|
210
|
+
Object.defineProperty(target, context, {
|
|
211
|
+
value,
|
|
212
|
+
writable: false,
|
|
213
|
+
configurable: true
|
|
214
|
+
});
|
|
215
|
+
return void 0;
|
|
216
|
+
}
|
|
217
|
+
return decorate;
|
|
218
|
+
}
|
|
219
|
+
function validate(parser, value) {
|
|
220
|
+
const result = parser?.parse(value);
|
|
221
|
+
if (result && typeof result.then === "function") {
|
|
222
|
+
void Promise.resolve(result).catch(() => {
|
|
223
|
+
});
|
|
224
|
+
throw new Error("Fractal runtime validators must be synchronous");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function wrap(fn, name, reference, process10, options = {}) {
|
|
228
|
+
const previous = wrappers.get(fn);
|
|
229
|
+
if (previous) {
|
|
230
|
+
fn = previous.original;
|
|
231
|
+
reference ||= previous.reference;
|
|
232
|
+
process10 ||= previous.process;
|
|
233
|
+
options = { ...previous.options, ...options };
|
|
234
|
+
}
|
|
235
|
+
const wrapped = function(...args) {
|
|
236
|
+
const api = reference?.();
|
|
237
|
+
if (reference && (!api || api[interfaceBrand] !== true))
|
|
238
|
+
throw new Error("@Method requires an initialized typed interface reference");
|
|
239
|
+
const adapter = host;
|
|
240
|
+
if (!listeners.size && !options.contract && !api?.options.auth)
|
|
241
|
+
return fn.apply(this, args);
|
|
242
|
+
const id3 = crypto.randomUUID();
|
|
243
|
+
const frame = {
|
|
244
|
+
targetId: process10?.id || `${api.id}#${options.name || name || fn.name || "call"}`,
|
|
245
|
+
traceId: id3,
|
|
246
|
+
runId: id3
|
|
247
|
+
};
|
|
248
|
+
let codeRevision;
|
|
249
|
+
try {
|
|
250
|
+
codeRevision = adapter?.codeRevision?.();
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
const started = performance.now();
|
|
254
|
+
let terminal2 = false;
|
|
255
|
+
const base = {
|
|
256
|
+
targetId: frame.targetId,
|
|
257
|
+
...{},
|
|
258
|
+
id: id3,
|
|
259
|
+
traceId: frame.traceId,
|
|
260
|
+
...codeRevision ? { codeRevision } : {},
|
|
261
|
+
runId: frame.runId,
|
|
262
|
+
...{},
|
|
263
|
+
...{},
|
|
264
|
+
blockId: process10?.id || api.blockId,
|
|
265
|
+
...api ? { interfaceId: api.id } : {},
|
|
266
|
+
method: options.name || name || fn.name || "call"
|
|
267
|
+
};
|
|
268
|
+
const emit2 = (status, failure) => {
|
|
269
|
+
if (status !== "started") {
|
|
270
|
+
if (terminal2)
|
|
271
|
+
return;
|
|
272
|
+
terminal2 = true;
|
|
273
|
+
frame.finished = true;
|
|
274
|
+
}
|
|
275
|
+
publish({
|
|
276
|
+
...base,
|
|
277
|
+
timestamp: Date.now(),
|
|
278
|
+
status,
|
|
279
|
+
...status !== "started" ? { durationMs: performance.now() - started } : {},
|
|
280
|
+
...failure ? { failure } : {}
|
|
281
|
+
}, adapter);
|
|
282
|
+
};
|
|
283
|
+
const execute = () => {
|
|
284
|
+
emit2("started");
|
|
285
|
+
let phase2 = "auth";
|
|
286
|
+
const failed = (error2) => {
|
|
287
|
+
emit2("failed", phase2);
|
|
288
|
+
throw error2;
|
|
289
|
+
};
|
|
290
|
+
const invoke = () => {
|
|
291
|
+
phase2 = "input";
|
|
292
|
+
validate(options.contract?.args, args);
|
|
293
|
+
phase2 = "execution";
|
|
294
|
+
const value = fn.apply(this, args);
|
|
295
|
+
const complete = (result) => {
|
|
296
|
+
phase2 = "output";
|
|
297
|
+
validate(options.contract?.result, result);
|
|
298
|
+
emit2("completed");
|
|
299
|
+
return result;
|
|
300
|
+
};
|
|
301
|
+
if (value && typeof value.then === "function") {
|
|
302
|
+
if (options.contract?.result)
|
|
303
|
+
return Promise.resolve(value).then(complete).catch(failed);
|
|
304
|
+
void Promise.resolve(value).then(() => emit2("completed"), () => emit2("failed", "execution"));
|
|
305
|
+
return value;
|
|
306
|
+
}
|
|
307
|
+
return complete(value);
|
|
308
|
+
};
|
|
309
|
+
try {
|
|
310
|
+
const authorized = api?.options.auth?.({
|
|
311
|
+
receiver: this,
|
|
312
|
+
args,
|
|
313
|
+
context: adapter?.context?.()
|
|
314
|
+
});
|
|
315
|
+
if (authorized && typeof authorized === "object" && typeof authorized.then === "function") {
|
|
316
|
+
if (fn.constructor.name !== "AsyncFunction") {
|
|
317
|
+
void authorized.catch(() => {
|
|
318
|
+
});
|
|
319
|
+
throw new Error("Async auth requires an async method");
|
|
320
|
+
}
|
|
321
|
+
return authorized.then((allowed) => {
|
|
322
|
+
if (allowed === false)
|
|
323
|
+
throw new FactoryViolation("auth", false);
|
|
324
|
+
return invoke();
|
|
325
|
+
}).catch(failed);
|
|
326
|
+
}
|
|
327
|
+
if (authorized === false)
|
|
328
|
+
throw new FactoryViolation("auth", false);
|
|
329
|
+
return invoke();
|
|
330
|
+
} catch (error2) {
|
|
331
|
+
return failed(error2);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const run = () => execute();
|
|
335
|
+
try {
|
|
336
|
+
return run();
|
|
337
|
+
} catch (error2) {
|
|
338
|
+
if (fn.constructor.name === "AsyncFunction")
|
|
339
|
+
return Promise.reject(error2);
|
|
340
|
+
throw error2;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
Object.defineProperty(wrapped, "name", {
|
|
344
|
+
value: options.name || name || fn.name,
|
|
345
|
+
configurable: true
|
|
346
|
+
});
|
|
347
|
+
Object.defineProperty(wrapped, "length", {
|
|
348
|
+
value: fn.length,
|
|
349
|
+
configurable: true
|
|
350
|
+
});
|
|
351
|
+
if (process10)
|
|
352
|
+
blocks.set(wrapped, process10);
|
|
353
|
+
wrappers.set(wrapped, { original: fn, reference, process: process10, options });
|
|
354
|
+
return wrapped;
|
|
355
|
+
}
|
|
356
|
+
function callableDecorator(reference, process10, options = {}) {
|
|
357
|
+
function decorate(target, context, descriptor) {
|
|
358
|
+
if (descriptor) {
|
|
359
|
+
descriptor.value = wrap(descriptor.value, String(context), reference, process10, options);
|
|
360
|
+
return descriptor;
|
|
361
|
+
}
|
|
362
|
+
const fn = target;
|
|
363
|
+
return wrap(fn, typeof context === "object" ? String(context.name) : fn.name, reference, process10, options);
|
|
364
|
+
}
|
|
365
|
+
return decorate;
|
|
366
|
+
}
|
|
367
|
+
function Method(reference, options = {}) {
|
|
368
|
+
return callableDecorator(reference, void 0, options);
|
|
369
|
+
}
|
|
370
|
+
function Process(id3, options = {}) {
|
|
371
|
+
const definition = typeof id3 === "string" ? { ...options, id: identity(id3) } : { ...id3, id: identity(id3.id) };
|
|
372
|
+
return callableDecorator(void 0, definition);
|
|
373
|
+
}
|
|
374
|
+
var interfaceBrand, blocks, wrappers, listeners, host, FactoryViolation;
|
|
375
|
+
var init_annotations = __esm({
|
|
376
|
+
"../fractory/dist/annotations.js"() {
|
|
377
|
+
interfaceBrand = Symbol("fractal.interface");
|
|
378
|
+
blocks = /* @__PURE__ */ new WeakMap();
|
|
379
|
+
wrappers = /* @__PURE__ */ new WeakMap();
|
|
380
|
+
listeners = /* @__PURE__ */ new Set();
|
|
381
|
+
FactoryViolation = class extends Error {
|
|
382
|
+
phase;
|
|
383
|
+
cause;
|
|
384
|
+
constructor(phase2, cause) {
|
|
385
|
+
super(`Fractal ${phase2} requirement failed`);
|
|
386
|
+
this.phase = phase2;
|
|
387
|
+
this.cause = cause;
|
|
388
|
+
this.name = "FactoryViolation";
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
});
|
|
87
393
|
|
|
88
394
|
// ../policy-engine/src/index.ts
|
|
89
395
|
var src_exports = {};
|
|
@@ -773,138 +1079,6 @@ function normalizeSourceProfiles(sources) {
|
|
|
773
1079
|
);
|
|
774
1080
|
return [...getBuiltinPermissionProfiles(), ...nonBuiltin];
|
|
775
1081
|
}
|
|
776
|
-
async function compilePolicyBundle(input) {
|
|
777
|
-
const errors = [];
|
|
778
|
-
const warnings = [];
|
|
779
|
-
const effects2 = [...input.effects].sort(
|
|
780
|
-
(left, right) => left.effectKey.localeCompare(right.effectKey)
|
|
781
|
-
);
|
|
782
|
-
const profiles = flattenProfiles(
|
|
783
|
-
normalizeSourceProfiles(input.profileSources),
|
|
784
|
-
errors
|
|
785
|
-
);
|
|
786
|
-
const manifestRules = {};
|
|
787
|
-
for (const effect of effects2) {
|
|
788
|
-
try {
|
|
789
|
-
const rules = manifestPolicyRulesForEffect(effect, input.manifestId);
|
|
790
|
-
if (rules.length > 0) manifestRules[effect.effectKey] = rules;
|
|
791
|
-
} catch (error2) {
|
|
792
|
-
errors.push(String(error2 instanceof Error ? error2.message : error2));
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
const compiledProfiles = {};
|
|
796
|
-
for (const profile of profiles) {
|
|
797
|
-
try {
|
|
798
|
-
const defaultActionPolicy = profile.defaults?.actionPolicy;
|
|
799
|
-
if (defaultActionPolicy !== void 0 && !normalizeDecision(defaultActionPolicy)) {
|
|
800
|
-
throw new Error(
|
|
801
|
-
`Permission profile "${profile.name}" has invalid defaults.actionPolicy`
|
|
802
|
-
);
|
|
803
|
-
}
|
|
804
|
-
const compiled = compileProfile({
|
|
805
|
-
profile,
|
|
806
|
-
effects: effects2,
|
|
807
|
-
manifestRules,
|
|
808
|
-
warnings
|
|
809
|
-
});
|
|
810
|
-
compiled.digest = await digestJson({
|
|
811
|
-
profile: compiled.flattened,
|
|
812
|
-
actionRules: compiled.actionRules,
|
|
813
|
-
defaultActionPolicy: compiled.defaultActionPolicy
|
|
814
|
-
});
|
|
815
|
-
compiledProfiles[profile.name] = compiled;
|
|
816
|
-
} catch (error2) {
|
|
817
|
-
errors.push(String(error2 instanceof Error ? error2.message : error2));
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
const permissionProfilesDigest = await digestJson(
|
|
821
|
-
Object.values(compiledProfiles).map((profile) => ({
|
|
822
|
-
name: profile.name,
|
|
823
|
-
digest: profile.digest,
|
|
824
|
-
source: profile.source
|
|
825
|
-
}))
|
|
826
|
-
);
|
|
827
|
-
const bundleWithoutDigest = {
|
|
828
|
-
schemaVersion: 1,
|
|
829
|
-
buildId: input.buildId,
|
|
830
|
-
sandboxId: input.sandboxId,
|
|
831
|
-
manifestDigest: input.manifestDigest,
|
|
832
|
-
permissionProfilesDigest,
|
|
833
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
834
|
-
effects: effects2.map((effect) => ({
|
|
835
|
-
effectKey: effect.effectKey,
|
|
836
|
-
name: effect.name,
|
|
837
|
-
attachedClass: normalizeAttachedClass(effect.attachedClass),
|
|
838
|
-
isStatic: effect.isStatic === true
|
|
839
|
-
})),
|
|
840
|
-
manifestRules,
|
|
841
|
-
profiles: compiledProfiles
|
|
842
|
-
};
|
|
843
|
-
const bundleDigest = await digestJson(bundleWithoutDigest);
|
|
844
|
-
return {
|
|
845
|
-
bundle: { ...bundleWithoutDigest, bundleDigest },
|
|
846
|
-
errors,
|
|
847
|
-
warnings
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
function evaluateCompiledPolicyBundle(input) {
|
|
851
|
-
const profile = input.bundle.profiles[input.profileName];
|
|
852
|
-
if (!profile) {
|
|
853
|
-
return {
|
|
854
|
-
outcome: "deny",
|
|
855
|
-
matches: [
|
|
856
|
-
{
|
|
857
|
-
id: "missing-profile",
|
|
858
|
-
outcome: "deny",
|
|
859
|
-
origin: {
|
|
860
|
-
kind: "permissionProfile",
|
|
861
|
-
profileName: input.profileName,
|
|
862
|
-
source: "permissionProfile"
|
|
863
|
-
},
|
|
864
|
-
reason: `Permission profile "${input.profileName}" does not exist in this version`,
|
|
865
|
-
summary: `Permission profile "${input.profileName}" does not exist in this version`
|
|
866
|
-
}
|
|
867
|
-
]
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
if (!profile.actionVisibility.includes(input.effectKey)) {
|
|
871
|
-
return {
|
|
872
|
-
outcome: "deny",
|
|
873
|
-
matches: [
|
|
874
|
-
{
|
|
875
|
-
id: "action-not-visible",
|
|
876
|
-
outcome: "deny",
|
|
877
|
-
origin: {
|
|
878
|
-
kind: "permissionProfile",
|
|
879
|
-
profileName: input.profileName,
|
|
880
|
-
source: profile.source
|
|
881
|
-
},
|
|
882
|
-
reason: `Action ${input.effectKey} is not visible for ${input.profileName}`,
|
|
883
|
-
summary: `Action ${input.effectKey} is not visible for ${input.profileName}`
|
|
884
|
-
}
|
|
885
|
-
]
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
const decision = evaluatePolicies({
|
|
889
|
-
manifestRules: input.bundle.manifestRules[input.effectKey] || [],
|
|
890
|
-
profileRules: profile.actionRules[input.effectKey] || [],
|
|
891
|
-
defaultActionPolicy: profile.defaultActionPolicy,
|
|
892
|
-
context: input.context
|
|
893
|
-
});
|
|
894
|
-
return {
|
|
895
|
-
outcome: decision.outcome,
|
|
896
|
-
matches: decision.matches.map(
|
|
897
|
-
(match) => match.id === `profile-default-${decision.outcome}` ? {
|
|
898
|
-
...match,
|
|
899
|
-
origin: {
|
|
900
|
-
kind: "permissionProfile",
|
|
901
|
-
profileName: profile.name,
|
|
902
|
-
source: profile.source
|
|
903
|
-
}
|
|
904
|
-
} : match
|
|
905
|
-
)
|
|
906
|
-
};
|
|
907
|
-
}
|
|
908
1082
|
function extractManifestEffects(manifest2) {
|
|
909
1083
|
const effects2 = [];
|
|
910
1084
|
for (const volume of manifest2.volumes || []) {
|
|
@@ -928,11 +1102,156 @@ function extractManifestEffects(manifest2) {
|
|
|
928
1102
|
function listVisibleActionsForProfile(bundle, profileName) {
|
|
929
1103
|
return [...bundle.profiles[profileName]?.actionVisibility || []];
|
|
930
1104
|
}
|
|
931
|
-
var DECISIONS, BUILTIN_PROFILE_NAMES;
|
|
1105
|
+
var DECISIONS, BUILTIN_PROFILE_NAMES, compilePolicyBundle, evaluateCompiledPolicyBundle;
|
|
932
1106
|
var init_src = __esm({
|
|
933
1107
|
"../policy-engine/src/index.ts"() {
|
|
1108
|
+
init_annotations();
|
|
934
1109
|
DECISIONS = /* @__PURE__ */ new Set(["allow", "confirm", "deny"]);
|
|
935
1110
|
BUILTIN_PROFILE_NAMES = ["allow-all", "confirm-all", "deny-all"];
|
|
1111
|
+
compilePolicyBundle = Process({
|
|
1112
|
+
description: "Compile product permission rules into a bundle that runtime checks can evaluate.",
|
|
1113
|
+
id: "granular-product/compilation/metamodels-policy-compilation/compile",
|
|
1114
|
+
label: "Compile policy bundle",
|
|
1115
|
+
benchmarks: ["./compile.bench.ts"],
|
|
1116
|
+
tests: ["./index.test.ts"]
|
|
1117
|
+
})(async function compilePolicyBundle2(input) {
|
|
1118
|
+
const errors = [];
|
|
1119
|
+
const warnings = [];
|
|
1120
|
+
const effects2 = [...input.effects].sort(
|
|
1121
|
+
(left, right) => left.effectKey.localeCompare(right.effectKey)
|
|
1122
|
+
);
|
|
1123
|
+
const profiles = flattenProfiles(
|
|
1124
|
+
normalizeSourceProfiles(input.profileSources),
|
|
1125
|
+
errors
|
|
1126
|
+
);
|
|
1127
|
+
const manifestRules = {};
|
|
1128
|
+
for (const effect of effects2) {
|
|
1129
|
+
try {
|
|
1130
|
+
const rules = manifestPolicyRulesForEffect(effect, input.manifestId);
|
|
1131
|
+
if (rules.length > 0) manifestRules[effect.effectKey] = rules;
|
|
1132
|
+
} catch (error2) {
|
|
1133
|
+
errors.push(String(error2 instanceof Error ? error2.message : error2));
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
const compiledProfiles = {};
|
|
1137
|
+
for (const profile of profiles) {
|
|
1138
|
+
try {
|
|
1139
|
+
const defaultActionPolicy = profile.defaults?.actionPolicy;
|
|
1140
|
+
if (defaultActionPolicy !== void 0 && !normalizeDecision(defaultActionPolicy)) {
|
|
1141
|
+
throw new Error(
|
|
1142
|
+
`Permission profile "${profile.name}" has invalid defaults.actionPolicy`
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
const compiled = compileProfile({
|
|
1146
|
+
profile,
|
|
1147
|
+
effects: effects2,
|
|
1148
|
+
manifestRules,
|
|
1149
|
+
warnings
|
|
1150
|
+
});
|
|
1151
|
+
compiled.digest = await digestJson({
|
|
1152
|
+
profile: compiled.flattened,
|
|
1153
|
+
actionRules: compiled.actionRules,
|
|
1154
|
+
defaultActionPolicy: compiled.defaultActionPolicy
|
|
1155
|
+
});
|
|
1156
|
+
compiledProfiles[profile.name] = compiled;
|
|
1157
|
+
} catch (error2) {
|
|
1158
|
+
errors.push(String(error2 instanceof Error ? error2.message : error2));
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
const permissionProfilesDigest = await digestJson(
|
|
1162
|
+
Object.values(compiledProfiles).map((profile) => ({
|
|
1163
|
+
name: profile.name,
|
|
1164
|
+
digest: profile.digest,
|
|
1165
|
+
source: profile.source
|
|
1166
|
+
}))
|
|
1167
|
+
);
|
|
1168
|
+
const bundleWithoutDigest = {
|
|
1169
|
+
schemaVersion: 1,
|
|
1170
|
+
buildId: input.buildId,
|
|
1171
|
+
sandboxId: input.sandboxId,
|
|
1172
|
+
manifestDigest: input.manifestDigest,
|
|
1173
|
+
permissionProfilesDigest,
|
|
1174
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1175
|
+
effects: effects2.map((effect) => ({
|
|
1176
|
+
effectKey: effect.effectKey,
|
|
1177
|
+
name: effect.name,
|
|
1178
|
+
attachedClass: normalizeAttachedClass(effect.attachedClass),
|
|
1179
|
+
isStatic: effect.isStatic === true
|
|
1180
|
+
})),
|
|
1181
|
+
manifestRules,
|
|
1182
|
+
profiles: compiledProfiles
|
|
1183
|
+
};
|
|
1184
|
+
const bundleDigest = await digestJson(bundleWithoutDigest);
|
|
1185
|
+
return {
|
|
1186
|
+
bundle: { ...bundleWithoutDigest, bundleDigest },
|
|
1187
|
+
errors,
|
|
1188
|
+
warnings
|
|
1189
|
+
};
|
|
1190
|
+
});
|
|
1191
|
+
evaluateCompiledPolicyBundle = Process({
|
|
1192
|
+
description: "Evaluate compiled permission rules for an action and its current context.",
|
|
1193
|
+
id: "granular-product/effects/authorization-contracts/compiled-evaluation",
|
|
1194
|
+
label: "Evaluate compiled policies",
|
|
1195
|
+
benchmarks: ["./evaluation.bench.ts"],
|
|
1196
|
+
tests: ["./index.test.ts"]
|
|
1197
|
+
})(function evaluateCompiledPolicyBundle2(input) {
|
|
1198
|
+
const profile = input.bundle.profiles[input.profileName];
|
|
1199
|
+
if (!profile) {
|
|
1200
|
+
return {
|
|
1201
|
+
outcome: "deny",
|
|
1202
|
+
matches: [
|
|
1203
|
+
{
|
|
1204
|
+
id: "missing-profile",
|
|
1205
|
+
outcome: "deny",
|
|
1206
|
+
origin: {
|
|
1207
|
+
kind: "permissionProfile",
|
|
1208
|
+
profileName: input.profileName,
|
|
1209
|
+
source: "permissionProfile"
|
|
1210
|
+
},
|
|
1211
|
+
reason: `Permission profile "${input.profileName}" does not exist in this version`,
|
|
1212
|
+
summary: `Permission profile "${input.profileName}" does not exist in this version`
|
|
1213
|
+
}
|
|
1214
|
+
]
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
if (!profile.actionVisibility.includes(input.effectKey)) {
|
|
1218
|
+
return {
|
|
1219
|
+
outcome: "deny",
|
|
1220
|
+
matches: [
|
|
1221
|
+
{
|
|
1222
|
+
id: "action-not-visible",
|
|
1223
|
+
outcome: "deny",
|
|
1224
|
+
origin: {
|
|
1225
|
+
kind: "permissionProfile",
|
|
1226
|
+
profileName: input.profileName,
|
|
1227
|
+
source: profile.source
|
|
1228
|
+
},
|
|
1229
|
+
reason: `Action ${input.effectKey} is not visible for ${input.profileName}`,
|
|
1230
|
+
summary: `Action ${input.effectKey} is not visible for ${input.profileName}`
|
|
1231
|
+
}
|
|
1232
|
+
]
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
const decision = evaluatePolicies({
|
|
1236
|
+
manifestRules: input.bundle.manifestRules[input.effectKey] || [],
|
|
1237
|
+
profileRules: profile.actionRules[input.effectKey] || [],
|
|
1238
|
+
defaultActionPolicy: profile.defaultActionPolicy,
|
|
1239
|
+
context: input.context
|
|
1240
|
+
});
|
|
1241
|
+
return {
|
|
1242
|
+
outcome: decision.outcome,
|
|
1243
|
+
matches: decision.matches.map(
|
|
1244
|
+
(match) => match.id === `profile-default-${decision.outcome}` ? {
|
|
1245
|
+
...match,
|
|
1246
|
+
origin: {
|
|
1247
|
+
kind: "permissionProfile",
|
|
1248
|
+
profileName: profile.name,
|
|
1249
|
+
source: profile.source
|
|
1250
|
+
}
|
|
1251
|
+
} : match
|
|
1252
|
+
)
|
|
1253
|
+
};
|
|
1254
|
+
});
|
|
936
1255
|
}
|
|
937
1256
|
});
|
|
938
1257
|
|
|
@@ -6785,7 +7104,7 @@ async function compileApprovedRolePolicies(blueprint2, roleIds, manifest2) {
|
|
|
6785
7104
|
var issues = (check, value, path10) => check(value) ? [] : check.issues?.(value, path10) || [path10];
|
|
6786
7105
|
var record2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6787
7106
|
var text3 = (value) => typeof value === "string";
|
|
6788
|
-
var
|
|
7107
|
+
var identity2 = (value) => typeof value === "string" && Boolean(value.trim());
|
|
6789
7108
|
var boolean = (value) => typeof value === "boolean";
|
|
6790
7109
|
var number = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
6791
7110
|
var integer = (value) => number(value) && Number.isSafeInteger(value);
|
|
@@ -6812,7 +7131,7 @@ var shape = (fields2) => Object.assign(
|
|
|
6812
7131
|
var fields = (names, check) => Object.fromEntries(names.map((name) => [name, check]));
|
|
6813
7132
|
var strings2 = list(text3);
|
|
6814
7133
|
var proposalBase = {
|
|
6815
|
-
id:
|
|
7134
|
+
id: identity2,
|
|
6816
7135
|
...fields(["description", "status"], optional(text3)),
|
|
6817
7136
|
evidence: optional(strings2)
|
|
6818
7137
|
};
|
|
@@ -6823,7 +7142,7 @@ var proposalChecks = {
|
|
|
6823
7142
|
label: optional(text3),
|
|
6824
7143
|
fields: list(
|
|
6825
7144
|
shape({
|
|
6826
|
-
id:
|
|
7145
|
+
id: identity2,
|
|
6827
7146
|
name: text3,
|
|
6828
7147
|
type: text3,
|
|
6829
7148
|
...fields(["description", "status"], optional(text3)),
|
|
@@ -6850,7 +7169,7 @@ var proposalChecks = {
|
|
|
6850
7169
|
),
|
|
6851
7170
|
transitions: list(
|
|
6852
7171
|
shape({
|
|
6853
|
-
id:
|
|
7172
|
+
id: identity2,
|
|
6854
7173
|
...fields(["name", "from", "to"], text3),
|
|
6855
7174
|
...fields(["label", "description"], optional(text3))
|
|
6856
7175
|
})
|
|
@@ -6858,8 +7177,8 @@ var proposalChecks = {
|
|
|
6858
7177
|
}),
|
|
6859
7178
|
action: shape({
|
|
6860
7179
|
...proposalBase,
|
|
6861
|
-
label: optional(
|
|
6862
|
-
summary: optional(
|
|
7180
|
+
label: optional(identity2),
|
|
7181
|
+
summary: optional(identity2),
|
|
6863
7182
|
constraints: optional(strings2),
|
|
6864
7183
|
key: text3,
|
|
6865
7184
|
className: optional(text3),
|
|
@@ -6913,7 +7232,7 @@ var OnboardingValidationError = class extends Error {
|
|
|
6913
7232
|
};
|
|
6914
7233
|
var realDevBinding = {
|
|
6915
7234
|
source: oneOf("real-dev"),
|
|
6916
|
-
...fields(["runId", "buildId", "environmentId", "subjectId"],
|
|
7235
|
+
...fields(["runId", "buildId", "environmentId", "subjectId"], identity2)
|
|
6917
7236
|
};
|
|
6918
7237
|
var realDevData = shape({
|
|
6919
7238
|
...realDevBinding,
|
|
@@ -6921,13 +7240,13 @@ var realDevData = shape({
|
|
|
6921
7240
|
environmentName: oneOf("dev"),
|
|
6922
7241
|
...fields(
|
|
6923
7242
|
["identityId", "permissionProfileId", "sessionId"],
|
|
6924
|
-
|
|
7243
|
+
identity2
|
|
6925
7244
|
),
|
|
6926
|
-
setupRunId: optional(
|
|
6927
|
-
importGeneration: optional(
|
|
6928
|
-
importIds: optional(list(
|
|
6929
|
-
importId: (value) => value === null ||
|
|
6930
|
-
collectionAssertionId: optional(
|
|
7245
|
+
setupRunId: optional(identity2),
|
|
7246
|
+
importGeneration: optional(identity2),
|
|
7247
|
+
importIds: optional(list(identity2)),
|
|
7248
|
+
importId: (value) => value === null || identity2(value),
|
|
7249
|
+
collectionAssertionId: optional(identity2),
|
|
6931
7250
|
totalRecords: integer,
|
|
6932
7251
|
importedRecords: integer
|
|
6933
7252
|
});
|
|
@@ -6938,8 +7257,8 @@ function validateOnboardingRealDevData(value) {
|
|
|
6938
7257
|
}
|
|
6939
7258
|
if (record2(value)) {
|
|
6940
7259
|
const hasSetup = value.setupRunId !== void 0 || value.importGeneration !== void 0 || value.importIds !== void 0;
|
|
6941
|
-
if (hasSetup && (!
|
|
6942
|
-
if (value.importId === null && (!hasSetup || !Array.isArray(value.importIds) || value.importIds.length !== 0 || value.totalRecords !== 0 || !
|
|
7260
|
+
if (hasSetup && (!identity2(value.setupRunId) || !identity2(value.importGeneration) || !Array.isArray(value.importIds) || value.importIds.length > 100 || value.importIds.some((id3) => !identity2(id3)) || new Set(value.importIds).size !== value.importIds.length || value.importId !== null && !value.importIds.includes(value.importId) || String(value.importGeneration).includes(":"))) invalidFields.push("seed.setupRunId/importGeneration/importIds");
|
|
7261
|
+
if (value.importId === null && (!hasSetup || !Array.isArray(value.importIds) || value.importIds.length !== 0 || value.totalRecords !== 0 || !identity2(value.collectionAssertionId))) invalidFields.push("seed.emptyCollection");
|
|
6943
7262
|
if (!hasSetup && value.importId === null) invalidFields.push("seed.importId");
|
|
6944
7263
|
}
|
|
6945
7264
|
return { valid: invalidFields.length === 0, invalidFields };
|
|
@@ -6949,7 +7268,7 @@ function validateOnboardingRealDevScenarios(value) {
|
|
|
6949
7268
|
...realDevBinding,
|
|
6950
7269
|
scenarios: list(
|
|
6951
7270
|
shape({
|
|
6952
|
-
...fields(["id", "title", "subjectId", "query"],
|
|
7271
|
+
...fields(["id", "title", "subjectId", "query"], identity2),
|
|
6953
7272
|
kind: oneOf(
|
|
6954
7273
|
"read",
|
|
6955
7274
|
"relationship",
|
|
@@ -6958,7 +7277,7 @@ function validateOnboardingRealDevScenarios(value) {
|
|
|
6958
7277
|
"permission",
|
|
6959
7278
|
"denial"
|
|
6960
7279
|
),
|
|
6961
|
-
expectedEvidence: list(
|
|
7280
|
+
expectedEvidence: list(identity2),
|
|
6962
7281
|
protected: optional(boolean)
|
|
6963
7282
|
})
|
|
6964
7283
|
)
|
|
@@ -9815,11 +10134,44 @@ var GranularApiError = class extends Error {
|
|
|
9815
10134
|
};
|
|
9816
10135
|
|
|
9817
10136
|
// src/cli/api-client.ts
|
|
10137
|
+
init_annotations();
|
|
10138
|
+
var versionAccess = Interface(
|
|
10139
|
+
"granular-product/configuration/versions-promotion-tags/cli",
|
|
10140
|
+
{
|
|
10141
|
+
label: "Version API client",
|
|
10142
|
+
tests: ["./api-client.test.ts"],
|
|
10143
|
+
description: "Read and manage product versions and tags through the CLI\u2019s Control Plane client."
|
|
10144
|
+
}
|
|
10145
|
+
);
|
|
10146
|
+
var definitionAccess = Interface(
|
|
10147
|
+
"granular-product/configuration/ontologies-manifests/cli",
|
|
10148
|
+
{
|
|
10149
|
+
label: "Definition API client",
|
|
10150
|
+
description: "Read product definitions and update stored manifests through the CLI\u2019s Control Plane client."
|
|
10151
|
+
}
|
|
10152
|
+
);
|
|
10153
|
+
var buildAccess = Interface(
|
|
10154
|
+
"granular-product/compilation/build-lifecycle-artifacts/cli",
|
|
10155
|
+
{
|
|
10156
|
+
label: "Build API client",
|
|
10157
|
+
description: "Start builds and read their status through the CLI\u2019s Control Plane client."
|
|
10158
|
+
}
|
|
10159
|
+
);
|
|
10160
|
+
var permissionAccess = Interface(
|
|
10161
|
+
"granular-product/effects/authorization-contracts/cli",
|
|
10162
|
+
{
|
|
10163
|
+
label: "Permission API client",
|
|
10164
|
+
description: "Read and update version permission profiles through the CLI\u2019s Control Plane client."
|
|
10165
|
+
}
|
|
10166
|
+
);
|
|
9818
10167
|
var DEFAULT_BUILD_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
10168
|
+
var _evaluateVersionPolicy_dec, _getVersionPermissionProfiles_dec, _getVersionPolicies_dec, _syncPermissionProfileSources_dec, _ensureDefaultProfile_dec, _createPermissionProfile_dec, _waitForVersionBuild_dec, _waitForBuild_dec, _getVersionDiff_dec, _getBuildDiff_dec, _promoteVersionToProd_dec, _promoteToProd_dec, _moveVersionTag_dec, _moveTag_dec, _listTags_dec, _createVersion_dec, _triggerBuild_dec, _getVersion_dec, _getBuild_dec, _listVersions_dec, _listBuilds_dec, _uploadManifest_dec, _getManifest_dec, _listManifests_dec, _findOrCreateSandbox_dec, _createSandbox_dec, _getSandbox_dec, _listSandboxes_dec, _init;
|
|
10169
|
+
_listSandboxes_dec = [Method(() => definitionAccess, { label: "List products", description: "List the products available to the authenticated developer." })], _getSandbox_dec = [Method(() => definitionAccess, { label: "Read product", description: "Read a product's configuration and identity." })], _createSandbox_dec = [Method(() => definitionAccess, { label: "Create product", description: "Create the product that will own definitions, builds and environments." })], _findOrCreateSandbox_dec = [Method(() => definitionAccess, { label: "Resolve product", description: "Find a product by name or create it when it does not exist." })], _listManifests_dec = [Method(() => definitionAccess, { label: "List definitions", description: "List a product's published definition revisions." })], _getManifest_dec = [Method(() => definitionAccess, { label: "Read definition", description: "Load a product definition revision and its metadata." })], _uploadManifest_dec = [Method(() => definitionAccess, { label: "Publish definition", description: "Publish a definition revision with its version label." })], _listBuilds_dec = [Method(() => buildAccess, { label: "List builds", description: "List the builds published for a product." })], _listVersions_dec = [Method(() => versionAccess, { label: "List versions", description: "List the product's version records." })], _getBuild_dec = [Method(() => buildAccess, { label: "Read build", description: "Read the current build status and metadata by its identifier." })], _getVersion_dec = [Method(() => versionAccess, { label: "Read version", description: "Read the build record backing a product version." })], _triggerBuild_dec = [Method(() => buildAccess, { label: "Start build", description: "Submit a product definition for compilation and return the build record." })], _createVersion_dec = [Method(() => versionAccess, { label: "Create version", description: "Start a build of a definition and expose it through the version API." })], _listTags_dec = [Method(() => versionAccess, { label: "Read tags", description: "Read version tags and normalize their selected build or version identifiers." })], _moveTag_dec = [Method(() => versionAccess, { label: "Move tag", description: "Move a version tag with an optional expected production-build precondition." })], _moveVersionTag_dec = [Method(() => versionAccess, { label: "Move version tag", description: "Move a tag to a selected version using the existing tag-update API." })], _promoteToProd_dec = [Method(() => versionAccess, { label: "Promote build", description: "Promote a completed build with an expected-production-build precondition." })], _promoteVersionToProd_dec = [Method(() => versionAccess, { label: "Promote version", description: "Promote a completed version with an expected-production-build precondition." })], _getBuildDiff_dec = [Method(() => versionAccess, { label: "Compare builds", description: "Compare a build with a selected or default comparison build." })], _getVersionDiff_dec = [Method(() => versionAccess, { label: "Compare versions", description: "Compare the product model represented by two versions." })], _waitForBuild_dec = [Method(() => buildAccess, { label: "Wait for build", description: "Poll a build until it completes or fails, reporting progress and enforcing a timeout." })], _waitForVersionBuild_dec = [Method(() => versionAccess, { label: "Wait for version", description: "Wait for the build backing a version to reach a terminal state." })], _createPermissionProfile_dec = [Method(() => permissionAccess, { label: "Create permission profile", description: "Publish a named permission profile and return its server representation." })], _ensureDefaultProfile_dec = [Method(() => permissionAccess, { label: "Ensure default permissions", description: "Create the default profile whose declared actions are allowed unless a policy denies them." })], _syncPermissionProfileSources_dec = [Method(() => permissionAccess, { label: "Publish permission rules", description: "Publish the product's permission profile source definitions." })], _getVersionPolicies_dec = [Method(() => permissionAccess, { label: "Read compiled rules", description: "Read the compiled permission rules available for a version." })], _getVersionPermissionProfiles_dec = [Method(() => permissionAccess, { label: "Read version permissions", description: "Read the permission profile sources associated with a version." })], _evaluateVersionPolicy_dec = [Method(() => permissionAccess, { label: "Preview permission decision", description: "Preview the permission decision for an action and its supplied context." })];
|
|
9819
10170
|
var ApiClient = class {
|
|
9820
|
-
apiKey;
|
|
9821
|
-
baseUrl;
|
|
9822
10171
|
constructor(apiKey, apiUrl, options) {
|
|
10172
|
+
__runInitializers(_init, 5, this);
|
|
10173
|
+
__publicField(this, "apiKey");
|
|
10174
|
+
__publicField(this, "baseUrl");
|
|
9823
10175
|
this.apiKey = options?.disableLocalApiKeyFallback ? apiKey : resolveAuthTokenForApiUrl(apiKey, apiUrl);
|
|
9824
10176
|
this.baseUrl = apiUrl.replace("wss://", "https://").replace("ws://", "http://").replace(/\/ws$/, "");
|
|
9825
10177
|
}
|
|
@@ -9962,7 +10314,6 @@ ${details.join("\n")}`;
|
|
|
9962
10314
|
}
|
|
9963
10315
|
);
|
|
9964
10316
|
}
|
|
9965
|
-
// ── Sandboxes ──
|
|
9966
10317
|
async listSandboxes() {
|
|
9967
10318
|
const result = await this.request("/control/sandboxes");
|
|
9968
10319
|
return result.items;
|
|
@@ -9988,7 +10339,6 @@ ${details.join("\n")}`;
|
|
|
9988
10339
|
if (existing) return existing;
|
|
9989
10340
|
return this.createSandbox({ name });
|
|
9990
10341
|
}
|
|
9991
|
-
// ── Manifests ──
|
|
9992
10342
|
async listManifests(sandboxId) {
|
|
9993
10343
|
const manifests = [];
|
|
9994
10344
|
let cursor = null;
|
|
@@ -10017,7 +10367,6 @@ ${details.join("\n")}`;
|
|
|
10017
10367
|
})
|
|
10018
10368
|
});
|
|
10019
10369
|
}
|
|
10020
|
-
// ── Builds ──
|
|
10021
10370
|
async listBuilds(sandboxId) {
|
|
10022
10371
|
const result = await this.request(
|
|
10023
10372
|
`/control/sandboxes/${sandboxId}/builds`
|
|
@@ -10120,7 +10469,6 @@ ${details.join("\n")}`;
|
|
|
10120
10469
|
async waitForVersionBuild(versionId, onStatus, timeoutMs = DEFAULT_BUILD_TIMEOUT_MS) {
|
|
10121
10470
|
return this.waitForBuild(versionId, onStatus, timeoutMs);
|
|
10122
10471
|
}
|
|
10123
|
-
// ── Permission Profiles ──
|
|
10124
10472
|
async createPermissionProfile(sandboxId, data) {
|
|
10125
10473
|
const profile = {
|
|
10126
10474
|
...data.rules,
|
|
@@ -10178,6 +10526,36 @@ ${details.join("\n")}`;
|
|
|
10178
10526
|
});
|
|
10179
10527
|
}
|
|
10180
10528
|
};
|
|
10529
|
+
_init = __decoratorStart(null);
|
|
10530
|
+
__decorateElement(_init, 1, "listSandboxes", _listSandboxes_dec, ApiClient);
|
|
10531
|
+
__decorateElement(_init, 1, "getSandbox", _getSandbox_dec, ApiClient);
|
|
10532
|
+
__decorateElement(_init, 1, "createSandbox", _createSandbox_dec, ApiClient);
|
|
10533
|
+
__decorateElement(_init, 1, "findOrCreateSandbox", _findOrCreateSandbox_dec, ApiClient);
|
|
10534
|
+
__decorateElement(_init, 1, "listManifests", _listManifests_dec, ApiClient);
|
|
10535
|
+
__decorateElement(_init, 1, "getManifest", _getManifest_dec, ApiClient);
|
|
10536
|
+
__decorateElement(_init, 1, "uploadManifest", _uploadManifest_dec, ApiClient);
|
|
10537
|
+
__decorateElement(_init, 1, "listBuilds", _listBuilds_dec, ApiClient);
|
|
10538
|
+
__decorateElement(_init, 1, "listVersions", _listVersions_dec, ApiClient);
|
|
10539
|
+
__decorateElement(_init, 1, "getBuild", _getBuild_dec, ApiClient);
|
|
10540
|
+
__decorateElement(_init, 1, "getVersion", _getVersion_dec, ApiClient);
|
|
10541
|
+
__decorateElement(_init, 1, "triggerBuild", _triggerBuild_dec, ApiClient);
|
|
10542
|
+
__decorateElement(_init, 1, "createVersion", _createVersion_dec, ApiClient);
|
|
10543
|
+
__decorateElement(_init, 1, "listTags", _listTags_dec, ApiClient);
|
|
10544
|
+
__decorateElement(_init, 1, "moveTag", _moveTag_dec, ApiClient);
|
|
10545
|
+
__decorateElement(_init, 1, "moveVersionTag", _moveVersionTag_dec, ApiClient);
|
|
10546
|
+
__decorateElement(_init, 1, "promoteToProd", _promoteToProd_dec, ApiClient);
|
|
10547
|
+
__decorateElement(_init, 1, "promoteVersionToProd", _promoteVersionToProd_dec, ApiClient);
|
|
10548
|
+
__decorateElement(_init, 1, "getBuildDiff", _getBuildDiff_dec, ApiClient);
|
|
10549
|
+
__decorateElement(_init, 1, "getVersionDiff", _getVersionDiff_dec, ApiClient);
|
|
10550
|
+
__decorateElement(_init, 1, "waitForBuild", _waitForBuild_dec, ApiClient);
|
|
10551
|
+
__decorateElement(_init, 1, "waitForVersionBuild", _waitForVersionBuild_dec, ApiClient);
|
|
10552
|
+
__decorateElement(_init, 1, "createPermissionProfile", _createPermissionProfile_dec, ApiClient);
|
|
10553
|
+
__decorateElement(_init, 1, "ensureDefaultProfile", _ensureDefaultProfile_dec, ApiClient);
|
|
10554
|
+
__decorateElement(_init, 1, "syncPermissionProfileSources", _syncPermissionProfileSources_dec, ApiClient);
|
|
10555
|
+
__decorateElement(_init, 1, "getVersionPolicies", _getVersionPolicies_dec, ApiClient);
|
|
10556
|
+
__decorateElement(_init, 1, "getVersionPermissionProfiles", _getVersionPermissionProfiles_dec, ApiClient);
|
|
10557
|
+
__decorateElement(_init, 1, "evaluateVersionPolicy", _evaluateVersionPolicy_dec, ApiClient);
|
|
10558
|
+
__decoratorMetadata(_init, ApiClient);
|
|
10181
10559
|
var OnboardingAgentClient = class {
|
|
10182
10560
|
constructor(runId, token, apiUrl) {
|
|
10183
10561
|
this.runId = runId;
|
|
@@ -10978,13 +11356,13 @@ var SignalExit = class extends SignalExitBase {
|
|
|
10978
11356
|
this.#sigListeners = {};
|
|
10979
11357
|
for (const sig of signals) {
|
|
10980
11358
|
this.#sigListeners[sig] = () => {
|
|
10981
|
-
const
|
|
11359
|
+
const listeners2 = this.#process.listeners(sig);
|
|
10982
11360
|
let { count } = this.#emitter;
|
|
10983
11361
|
const p = process10;
|
|
10984
11362
|
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") {
|
|
10985
11363
|
count += p.__signal_exit_emitter__.count;
|
|
10986
11364
|
}
|
|
10987
|
-
if (
|
|
11365
|
+
if (listeners2.length === count) {
|
|
10988
11366
|
this.unload();
|
|
10989
11367
|
const ret = this.#emitter.emit("exit", null, sig);
|
|
10990
11368
|
const s = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
@@ -11184,13 +11562,13 @@ function isWide(x) {
|
|
|
11184
11562
|
}
|
|
11185
11563
|
|
|
11186
11564
|
// ../../node_modules/get-east-asian-width/index.js
|
|
11187
|
-
function
|
|
11565
|
+
function validate2(codePoint) {
|
|
11188
11566
|
if (!Number.isSafeInteger(codePoint)) {
|
|
11189
11567
|
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
11190
11568
|
}
|
|
11191
11569
|
}
|
|
11192
11570
|
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
11193
|
-
|
|
11571
|
+
validate2(codePoint);
|
|
11194
11572
|
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
11195
11573
|
return 2;
|
|
11196
11574
|
}
|
|
@@ -13451,7 +13829,7 @@ var {
|
|
|
13451
13829
|
} = import_index.default;
|
|
13452
13830
|
|
|
13453
13831
|
// package.json
|
|
13454
|
-
var version = "0.4.
|
|
13832
|
+
var version = "0.4.82";
|
|
13455
13833
|
var package_default = {
|
|
13456
13834
|
version};
|
|
13457
13835
|
|
|
@@ -21273,9 +21651,14 @@ Use \`environment.graphql(query, variables?)\` when you need **query/mutation ac
|
|
|
21273
21651
|
}
|
|
21274
21652
|
|
|
21275
21653
|
// src/cli/agent-docs/agents-md.ts
|
|
21654
|
+
init_annotations();
|
|
21276
21655
|
var GRANULAR_AGENTS_BEGIN = "<!-- granular-sdk:begin -->";
|
|
21277
21656
|
var GRANULAR_AGENTS_END = "<!-- granular-sdk:end -->";
|
|
21278
|
-
|
|
21657
|
+
var generateGranularAgentsBlock = Process({
|
|
21658
|
+
description: "Generate repository instructions describing how to work with the project\u2019s Granular integration.",
|
|
21659
|
+
id: "granular-product/authoring/agent-facing-documentation/generate",
|
|
21660
|
+
label: "Generate agent instructions"
|
|
21661
|
+
})(function generateGranularAgentsBlock2(options) {
|
|
21279
21662
|
const manifestPath = options?.manifestGuidePath ?? "docs/granular-manifest.md";
|
|
21280
21663
|
return `${GRANULAR_AGENTS_BEGIN}
|
|
21281
21664
|
|
|
@@ -21289,7 +21672,7 @@ function generateGranularAgentsBlock(options) {
|
|
|
21289
21672
|
**Instruction precedence:** User chat > this section > other content in this file.
|
|
21290
21673
|
|
|
21291
21674
|
${GRANULAR_AGENTS_END}`;
|
|
21292
|
-
}
|
|
21675
|
+
});
|
|
21293
21676
|
function mergeGranularAgentsBlock(existingContent, block) {
|
|
21294
21677
|
const trimmed = existingContent.trimEnd();
|
|
21295
21678
|
if (trimmed.includes(GRANULAR_AGENTS_BEGIN) && trimmed.includes(GRANULAR_AGENTS_END)) {
|
|
@@ -21751,6 +22134,11 @@ function writeSandboxAgentDocFile(projectRoot, manifest2, meta) {
|
|
|
21751
22134
|
}
|
|
21752
22135
|
|
|
21753
22136
|
// src/cli/commands/init.ts
|
|
22137
|
+
init_annotations();
|
|
22138
|
+
var projectSetup = Interface(
|
|
22139
|
+
"granular-product/authoring/cli-local-development/project-setup",
|
|
22140
|
+
{ label: "Project setup", tests: [] }
|
|
22141
|
+
);
|
|
21754
22142
|
async function reportInitOnboarding(label, operation) {
|
|
21755
22143
|
try {
|
|
21756
22144
|
return await withOnboardingRetry(label, operation);
|
|
@@ -21839,7 +22227,10 @@ async function selectStarterTemplate(requestedTemplate) {
|
|
|
21839
22227
|
);
|
|
21840
22228
|
return DEFAULT_STARTER_TEMPLATE_ID;
|
|
21841
22229
|
}
|
|
21842
|
-
|
|
22230
|
+
var initCommand = Method(() => projectSetup, {
|
|
22231
|
+
label: "Initialize project",
|
|
22232
|
+
description: "Create the local product integration files and initial configuration."
|
|
22233
|
+
})(async function initCommand2(projectName, options) {
|
|
21843
22234
|
printHeader();
|
|
21844
22235
|
if (options?.agentDocs && options?.noAgentDocs) {
|
|
21845
22236
|
error("Cannot use --agent-docs and --no-agent-docs together.");
|
|
@@ -22195,7 +22586,7 @@ async function initCommand(projectName, options) {
|
|
|
22195
22586
|
" The seed script shows synchronous batch recording with progress. The effects script shows how external systems plug in."
|
|
22196
22587
|
);
|
|
22197
22588
|
console.log();
|
|
22198
|
-
}
|
|
22589
|
+
});
|
|
22199
22590
|
var DEFAULT_LOCAL_API_KEY2 = "gn_sk_tenant_default_principal_local_e2e_00000000";
|
|
22200
22591
|
function promptSecret(question) {
|
|
22201
22592
|
const rl = readline__namespace.createInterface({
|
|
@@ -22313,6 +22704,166 @@ async function loginCommand(options = {}) {
|
|
|
22313
22704
|
dim("API key saved to .env.local (used by CLI and SDK examples)");
|
|
22314
22705
|
console.log();
|
|
22315
22706
|
}
|
|
22707
|
+
init_annotations();
|
|
22708
|
+
|
|
22709
|
+
// src/cli/commands/version.ts
|
|
22710
|
+
init_annotations();
|
|
22711
|
+
var versionManagement = Interface(
|
|
22712
|
+
"granular-product/authoring/cli-local-development/version-management",
|
|
22713
|
+
{ label: "Versions & tags", tests: [] }
|
|
22714
|
+
);
|
|
22715
|
+
function formatVersionLabel(versionId, versionNumber) {
|
|
22716
|
+
return versionNumber != null ? `v${versionNumber}` : versionId;
|
|
22717
|
+
}
|
|
22718
|
+
function compareBuilds(left, right) {
|
|
22719
|
+
const leftVersion = left.versionNumber ?? Number.NEGATIVE_INFINITY;
|
|
22720
|
+
const rightVersion = right.versionNumber ?? Number.NEGATIVE_INFINITY;
|
|
22721
|
+
if (leftVersion !== rightVersion) {
|
|
22722
|
+
return rightVersion - leftVersion;
|
|
22723
|
+
}
|
|
22724
|
+
return (right.createdAt ?? 0) - (left.createdAt ?? 0);
|
|
22725
|
+
}
|
|
22726
|
+
function resolveCurrentVersion(builds, tags) {
|
|
22727
|
+
if (builds.length === 0) {
|
|
22728
|
+
return null;
|
|
22729
|
+
}
|
|
22730
|
+
const byId = new Map(builds.map((build) => [build.buildId, build]));
|
|
22731
|
+
const currentBuild = builds.find((build) => build.isCurrent);
|
|
22732
|
+
if (currentBuild) {
|
|
22733
|
+
return currentBuild;
|
|
22734
|
+
}
|
|
22735
|
+
const devTarget = tags.find((tag2) => tag2.name === "dev")?.targetVersionId || tags.find((tag2) => tag2.name === "dev")?.targetBuildId;
|
|
22736
|
+
if (devTarget && byId.has(devTarget)) {
|
|
22737
|
+
return byId.get(devTarget);
|
|
22738
|
+
}
|
|
22739
|
+
return [...builds].sort(compareBuilds)[0];
|
|
22740
|
+
}
|
|
22741
|
+
var versionCurrentCommand = Method(() => versionManagement, {
|
|
22742
|
+
label: "Inspect current version",
|
|
22743
|
+
description: "Read the product version selected for the current workspace."
|
|
22744
|
+
})(async function versionCurrentCommand2(options) {
|
|
22745
|
+
const emitJson = options?.json === true;
|
|
22746
|
+
if (!emitJson) {
|
|
22747
|
+
printHeader();
|
|
22748
|
+
}
|
|
22749
|
+
const config = resolveConfig({ requireApiKey: true });
|
|
22750
|
+
if (!config.sandboxId) {
|
|
22751
|
+
throw new Error("No ontology configured. Run `granular init` first.");
|
|
22752
|
+
}
|
|
22753
|
+
const api = new ApiClient(config.apiKey, config.apiUrl);
|
|
22754
|
+
const spin = emitJson ? null : spinner("Resolving current version...");
|
|
22755
|
+
try {
|
|
22756
|
+
const [builds, tags] = await Promise.all([
|
|
22757
|
+
api.listVersions(config.sandboxId),
|
|
22758
|
+
api.listTags(config.sandboxId).catch(() => [])
|
|
22759
|
+
]);
|
|
22760
|
+
const current = resolveCurrentVersion(builds, tags);
|
|
22761
|
+
if (!current) {
|
|
22762
|
+
throw new Error(
|
|
22763
|
+
"No versions exist for this ontology yet. Run `granular build` first."
|
|
22764
|
+
);
|
|
22765
|
+
}
|
|
22766
|
+
const payload = {
|
|
22767
|
+
ontologyId: config.sandboxId,
|
|
22768
|
+
versionId: current.buildId,
|
|
22769
|
+
versionNumber: current.versionNumber ?? null,
|
|
22770
|
+
status: current.status,
|
|
22771
|
+
createdAt: current.createdAt,
|
|
22772
|
+
isCurrent: current.isCurrent ?? false,
|
|
22773
|
+
devVersionId: tags.find((tag2) => tag2.name === "dev")?.targetVersionId || tags.find((tag2) => tag2.name === "dev")?.targetBuildId || null,
|
|
22774
|
+
prodVersionId: tags.find((tag2) => tag2.name === "prod")?.targetVersionId || tags.find((tag2) => tag2.name === "prod")?.targetBuildId || null
|
|
22775
|
+
};
|
|
22776
|
+
if (emitJson) {
|
|
22777
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
22778
|
+
return;
|
|
22779
|
+
}
|
|
22780
|
+
spin?.succeed(" Current version resolved.");
|
|
22781
|
+
console.log();
|
|
22782
|
+
keyValue({
|
|
22783
|
+
"Ontology ID": payload.ontologyId,
|
|
22784
|
+
"Current version": formatVersionLabel(
|
|
22785
|
+
payload.versionId,
|
|
22786
|
+
payload.versionNumber
|
|
22787
|
+
),
|
|
22788
|
+
Status: payload.status,
|
|
22789
|
+
Created: payload.createdAt,
|
|
22790
|
+
"Dev tag": payload.devVersionId || "not set",
|
|
22791
|
+
"Prod tag": payload.prodVersionId || "not set"
|
|
22792
|
+
});
|
|
22793
|
+
console.log();
|
|
22794
|
+
} catch (err) {
|
|
22795
|
+
spin?.fail(` Failed to resolve current version: ${err.message}`);
|
|
22796
|
+
throw err;
|
|
22797
|
+
}
|
|
22798
|
+
});
|
|
22799
|
+
var versionDiffCommand = Method(() => versionManagement, {
|
|
22800
|
+
label: "Compare versions",
|
|
22801
|
+
description: "Compare two product versions and report their semantic differences."
|
|
22802
|
+
})(async function versionDiffCommand2(versionId, againstVersionId, options) {
|
|
22803
|
+
const emitJson = options?.json === true;
|
|
22804
|
+
if (!emitJson) {
|
|
22805
|
+
printHeader();
|
|
22806
|
+
}
|
|
22807
|
+
const config = resolveConfig({ requireApiKey: true });
|
|
22808
|
+
const api = new ApiClient(config.apiKey, config.apiUrl);
|
|
22809
|
+
const spin = emitJson ? null : spinner(
|
|
22810
|
+
againstVersionId ? `Computing diff ${versionId} \u2190 ${againstVersionId}...` : `Computing diff for ${versionId}...`
|
|
22811
|
+
);
|
|
22812
|
+
try {
|
|
22813
|
+
const [version3, diffResult] = await Promise.all([
|
|
22814
|
+
api.getVersion(versionId),
|
|
22815
|
+
api.getVersionDiff(versionId, againstVersionId)
|
|
22816
|
+
]);
|
|
22817
|
+
const baseVersion = diffResult.againstVersionId ? await api.getVersion(diffResult.againstVersionId).catch(() => null) : null;
|
|
22818
|
+
const summary = diffResult.diff.summary;
|
|
22819
|
+
const payload = {
|
|
22820
|
+
versionId: version3.buildId,
|
|
22821
|
+
versionNumber: version3.versionNumber ?? null,
|
|
22822
|
+
againstVersionId: diffResult.againstVersionId,
|
|
22823
|
+
againstVersionNumber: baseVersion?.versionNumber ?? null,
|
|
22824
|
+
summary,
|
|
22825
|
+
entries: diffResult.diff.entries
|
|
22826
|
+
};
|
|
22827
|
+
if (emitJson) {
|
|
22828
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
22829
|
+
return;
|
|
22830
|
+
}
|
|
22831
|
+
spin?.succeed(" Version diff ready.");
|
|
22832
|
+
console.log();
|
|
22833
|
+
keyValue({
|
|
22834
|
+
Version: formatVersionLabel(version3.buildId, version3.versionNumber),
|
|
22835
|
+
"Compared against": baseVersion ? formatVersionLabel(baseVersion.buildId, baseVersion.versionNumber) : diffResult.againstVersionId || "previous version",
|
|
22836
|
+
"Added operations": summary.added,
|
|
22837
|
+
"Changed operations": summary.changed,
|
|
22838
|
+
"Removed operations": summary.removed,
|
|
22839
|
+
"Transition safety": summary.onlyAdditiveChanges ? "additive only" : "breaking changes detected"
|
|
22840
|
+
});
|
|
22841
|
+
if (diffResult.diff.entries.length === 0) {
|
|
22842
|
+
console.log();
|
|
22843
|
+
info("No ontology changes between these versions.");
|
|
22844
|
+
console.log();
|
|
22845
|
+
return;
|
|
22846
|
+
}
|
|
22847
|
+
console.log();
|
|
22848
|
+
step("Semantic diff");
|
|
22849
|
+
console.log();
|
|
22850
|
+
table(
|
|
22851
|
+
["Change", "Kind", "Operation", "Safety"],
|
|
22852
|
+
diffResult.diff.entries.map((entry) => [
|
|
22853
|
+
entry.changeType,
|
|
22854
|
+
entry.kind,
|
|
22855
|
+
entry.label,
|
|
22856
|
+
entry.additive ? "safe-add" : "breaking"
|
|
22857
|
+
])
|
|
22858
|
+
);
|
|
22859
|
+
console.log();
|
|
22860
|
+
} catch (err) {
|
|
22861
|
+
spin?.fail(` Failed to compute diff: ${err.message}`);
|
|
22862
|
+
throw err;
|
|
22863
|
+
}
|
|
22864
|
+
});
|
|
22865
|
+
|
|
22866
|
+
// src/cli/commands/pull.ts
|
|
22316
22867
|
function cleanPermissionProfile(profile) {
|
|
22317
22868
|
const { source: source2, sourcePath, defaultsOwnerName, ...rest } = profile;
|
|
22318
22869
|
return rest;
|
|
@@ -22334,7 +22885,10 @@ function writePermissionProfileFiles(profiles) {
|
|
|
22334
22885
|
}
|
|
22335
22886
|
return written.sort();
|
|
22336
22887
|
}
|
|
22337
|
-
|
|
22888
|
+
var pullCommand = Method(() => versionManagement, {
|
|
22889
|
+
label: "Pull published definition",
|
|
22890
|
+
description: "Download the selected published product definition into the developer workspace."
|
|
22891
|
+
})(async function pullCommand2(versionId) {
|
|
22338
22892
|
printHeader();
|
|
22339
22893
|
const config = resolveConfig({ requireApiKey: true });
|
|
22340
22894
|
if (!config.sandboxId) {
|
|
@@ -22377,8 +22931,168 @@ async function pullCommand(versionId) {
|
|
|
22377
22931
|
spin.fail(` Failed to pull manifest: ${err.message}`);
|
|
22378
22932
|
process.exit(1);
|
|
22379
22933
|
}
|
|
22380
|
-
}
|
|
22934
|
+
});
|
|
22935
|
+
init_src();
|
|
22936
|
+
init_annotations();
|
|
22937
|
+
|
|
22938
|
+
// src/cli/commands/deploy.ts
|
|
22381
22939
|
init_src();
|
|
22940
|
+
init_annotations();
|
|
22941
|
+
var buildPublish = Interface(
|
|
22942
|
+
"granular-product/authoring/cli-local-development/build-publish",
|
|
22943
|
+
{ label: "Build & publish", tests: [] }
|
|
22944
|
+
);
|
|
22945
|
+
var deployCommand = Method(() => buildPublish, {
|
|
22946
|
+
label: "Publish product version",
|
|
22947
|
+
description: "Publish the local product definition and wait for its selected build."
|
|
22948
|
+
})(async function deployCommand2(options = {}) {
|
|
22949
|
+
printHeader();
|
|
22950
|
+
const config = resolveConfig({ requireApiKey: true, requireProject: true });
|
|
22951
|
+
if (!config.sandboxId) {
|
|
22952
|
+
error("No sandbox configured. Run `granular init` first.");
|
|
22953
|
+
process.exit(1);
|
|
22954
|
+
}
|
|
22955
|
+
const api = new ApiClient(config.apiKey, config.apiUrl);
|
|
22956
|
+
step(
|
|
22957
|
+
options.prod ? "Deploy to dev and prod" : "Deploy to dev",
|
|
22958
|
+
`Sandbox ${config.sandboxId}`
|
|
22959
|
+
);
|
|
22960
|
+
console.log();
|
|
22961
|
+
const manifest2 = config.project.manifest;
|
|
22962
|
+
const permissionProfiles = readPermissionProfileFiles();
|
|
22963
|
+
const localPolicyValidation = await compilePolicyBundle({
|
|
22964
|
+
sandboxId: config.sandboxId,
|
|
22965
|
+
effects: extractManifestEffects(manifest2),
|
|
22966
|
+
profileSources: permissionProfiles
|
|
22967
|
+
});
|
|
22968
|
+
if (localPolicyValidation.errors.length > 0) {
|
|
22969
|
+
error("Permission policy validation failed:");
|
|
22970
|
+
for (const error2 of localPolicyValidation.errors) error(` ${error2}`);
|
|
22971
|
+
process.exit(1);
|
|
22972
|
+
}
|
|
22973
|
+
const syncingProfiles = spinner(
|
|
22974
|
+
`Syncing ${permissionProfiles.length} permission profile file(s)...`
|
|
22975
|
+
);
|
|
22976
|
+
try {
|
|
22977
|
+
const result = await api.syncPermissionProfileSources(
|
|
22978
|
+
config.sandboxId,
|
|
22979
|
+
permissionProfiles
|
|
22980
|
+
);
|
|
22981
|
+
syncingProfiles.succeed(
|
|
22982
|
+
` Permission profiles synced: ${brand.secondary(result.digest)}`
|
|
22983
|
+
);
|
|
22984
|
+
} catch (err) {
|
|
22985
|
+
syncingProfiles.fail(
|
|
22986
|
+
` Failed to sync permission profiles: ${err.message}`
|
|
22987
|
+
);
|
|
22988
|
+
process.exit(1);
|
|
22989
|
+
}
|
|
22990
|
+
const uploading = spinner(`Uploading manifest "${manifest2.name}"...`);
|
|
22991
|
+
let uploadedManifest;
|
|
22992
|
+
try {
|
|
22993
|
+
uploadedManifest = await api.uploadManifest(config.sandboxId, manifest2);
|
|
22994
|
+
uploading.succeed(
|
|
22995
|
+
` Manifest uploaded: ${brand.secondary(uploadedManifest.manifestId)}`
|
|
22996
|
+
);
|
|
22997
|
+
} catch (err) {
|
|
22998
|
+
uploading.fail(` Failed to upload manifest: ${err.message}`);
|
|
22999
|
+
process.exit(1);
|
|
23000
|
+
}
|
|
23001
|
+
const building = spinner("Resolving ontology version from manifest...");
|
|
23002
|
+
try {
|
|
23003
|
+
const [versions, tags] = await Promise.all([
|
|
23004
|
+
api.listVersions(config.sandboxId),
|
|
23005
|
+
api.listTags(config.sandboxId).catch(() => [])
|
|
23006
|
+
]);
|
|
23007
|
+
const devTag = tags.find((tag2) => tag2.name === "dev");
|
|
23008
|
+
const prodTag = tags.find((tag2) => tag2.name === "prod");
|
|
23009
|
+
const existingVersion = options.releaseKey ? null : versions.find(
|
|
23010
|
+
(version3) => version3.manifestDigest === uploadedManifest.digest
|
|
23011
|
+
) || null;
|
|
23012
|
+
const existingVersionId = existingVersion?.buildId || null;
|
|
23013
|
+
const devVersionId = devTag?.targetVersionId || devTag?.targetBuildId || null;
|
|
23014
|
+
const reuseDevPromotion = Boolean(
|
|
23015
|
+
options.prod && existingVersion && existingVersion.status === "completed" && existingVersionId && devVersionId === existingVersionId
|
|
23016
|
+
);
|
|
23017
|
+
let completed = existingVersion;
|
|
23018
|
+
let totalTime = 0;
|
|
23019
|
+
let deployedToDev = false;
|
|
23020
|
+
if (reuseDevPromotion) {
|
|
23021
|
+
building.succeed(
|
|
23022
|
+
` Current manifest already matches ${brand.secondary(existingVersionId)} on dev.`
|
|
23023
|
+
);
|
|
23024
|
+
} else {
|
|
23025
|
+
const version3 = await api.createVersion(
|
|
23026
|
+
config.sandboxId,
|
|
23027
|
+
uploadedManifest.manifestId,
|
|
23028
|
+
options.releaseKey
|
|
23029
|
+
);
|
|
23030
|
+
if (version3.createdNewVersion === false && version3.status === "completed") {
|
|
23031
|
+
completed = version3;
|
|
23032
|
+
building.succeed(
|
|
23033
|
+
` Reused ${brand.secondary(version3.buildId)}; the release key is unchanged.`
|
|
23034
|
+
);
|
|
23035
|
+
} else {
|
|
23036
|
+
const startTime = Date.now();
|
|
23037
|
+
building.text = ` Running build for version... ${brand.muted(version3.buildId)}`;
|
|
23038
|
+
completed = await api.waitForVersionBuild(version3.buildId, (status) => {
|
|
23039
|
+
const elapsed = Math.round((Date.now() - startTime) / 1e3);
|
|
23040
|
+
building.text = ` Running build for version... ${brand.muted(`${status} (${elapsed}s)`)}`;
|
|
23041
|
+
});
|
|
23042
|
+
totalTime = Math.round((Date.now() - startTime) / 1e3);
|
|
23043
|
+
deployedToDev = true;
|
|
23044
|
+
building.succeed(
|
|
23045
|
+
` Dev now points to ${brand.secondary(completed.buildId)} (${totalTime}s)`
|
|
23046
|
+
);
|
|
23047
|
+
}
|
|
23048
|
+
}
|
|
23049
|
+
if (!completed) {
|
|
23050
|
+
throw new Error("Could not resolve the current ontology version.");
|
|
23051
|
+
}
|
|
23052
|
+
if (options.prod) {
|
|
23053
|
+
const promoting = spinner("Promoting prod...");
|
|
23054
|
+
await api.promoteVersionToProd(
|
|
23055
|
+
completed.buildId,
|
|
23056
|
+
prodTag?.targetVersionId || prodTag?.targetBuildId || null
|
|
23057
|
+
);
|
|
23058
|
+
promoting.succeed(
|
|
23059
|
+
` Prod now points to ${brand.secondary(completed.buildId)}`
|
|
23060
|
+
);
|
|
23061
|
+
}
|
|
23062
|
+
writeSandboxAgentDocFile(getProjectRoot(), manifest2, {
|
|
23063
|
+
sandboxId: config.sandboxId,
|
|
23064
|
+
apiUrl: config.apiUrl,
|
|
23065
|
+
manifestId: uploadedManifest.manifestId,
|
|
23066
|
+
buildId: completed.buildId
|
|
23067
|
+
});
|
|
23068
|
+
console.log();
|
|
23069
|
+
success(`Deployed ${brand.bold(manifest2.name)} successfully!`);
|
|
23070
|
+
console.log();
|
|
23071
|
+
keyValue({
|
|
23072
|
+
Version: completed.buildId,
|
|
23073
|
+
"Version Number": completed.versionNumber != null ? String(completed.versionNumber) : "N/A",
|
|
23074
|
+
"Build Run": completed.buildRunId || completed.latestBuildRunId || "N/A",
|
|
23075
|
+
Manifest: uploadedManifest.manifestId,
|
|
23076
|
+
"Dev Tag": completed.buildId,
|
|
23077
|
+
"Prod Tag": options.prod ? completed.buildId : prodTag?.targetVersionId || prodTag?.targetBuildId || "unchanged",
|
|
23078
|
+
Release: options.prod ? deployedToDev ? "dev and prod now point to this version" : "prod promoted to the version already on dev" : "dev updated to this version",
|
|
23079
|
+
"Agent doc": "GRANULAR_SANDBOX.md"
|
|
23080
|
+
});
|
|
23081
|
+
console.log(`GRANULAR_RELEASE_CHANGED=${deployedToDev ? "true" : "false"}`);
|
|
23082
|
+
console.log();
|
|
23083
|
+
if (options.prod) {
|
|
23084
|
+
info(
|
|
23085
|
+
"Existing prod environments keep their current version until they are transitioned."
|
|
23086
|
+
);
|
|
23087
|
+
console.log();
|
|
23088
|
+
}
|
|
23089
|
+
} catch (err) {
|
|
23090
|
+
building.fail(` Deploy failed: ${err.message}`);
|
|
23091
|
+
process.exit(1);
|
|
23092
|
+
}
|
|
23093
|
+
});
|
|
23094
|
+
|
|
23095
|
+
// src/cli/commands/build.ts
|
|
22382
23096
|
function uniqueNames(values) {
|
|
22383
23097
|
return [
|
|
22384
23098
|
...new Set(values.map((value) => value?.trim()).filter(Boolean))
|
|
@@ -22455,7 +23169,10 @@ async function createBuildOnboardingReporter(api, runId, sandboxId, connect2) {
|
|
|
22455
23169
|
}
|
|
22456
23170
|
};
|
|
22457
23171
|
}
|
|
22458
|
-
|
|
23172
|
+
var buildCommand = Method(() => buildPublish, {
|
|
23173
|
+
label: "Build product definition",
|
|
23174
|
+
description: "Compile the local product definition and report its build result."
|
|
23175
|
+
})(async function buildCommand2() {
|
|
22459
23176
|
printHeader();
|
|
22460
23177
|
const config = resolveConfig({ requireApiKey: true, requireProject: true });
|
|
22461
23178
|
if (!config.sandboxId) {
|
|
@@ -22803,156 +23520,7 @@ async function buildCommand() {
|
|
|
22803
23520
|
building.fail(` Build failed: ${err.message}`);
|
|
22804
23521
|
process.exit(1);
|
|
22805
23522
|
}
|
|
22806
|
-
}
|
|
22807
|
-
|
|
22808
|
-
// src/cli/commands/deploy.ts
|
|
22809
|
-
init_src();
|
|
22810
|
-
async function deployCommand(options = {}) {
|
|
22811
|
-
printHeader();
|
|
22812
|
-
const config = resolveConfig({ requireApiKey: true, requireProject: true });
|
|
22813
|
-
if (!config.sandboxId) {
|
|
22814
|
-
error("No sandbox configured. Run `granular init` first.");
|
|
22815
|
-
process.exit(1);
|
|
22816
|
-
}
|
|
22817
|
-
const api = new ApiClient(config.apiKey, config.apiUrl);
|
|
22818
|
-
step(
|
|
22819
|
-
options.prod ? "Deploy to dev and prod" : "Deploy to dev",
|
|
22820
|
-
`Sandbox ${config.sandboxId}`
|
|
22821
|
-
);
|
|
22822
|
-
console.log();
|
|
22823
|
-
const manifest2 = config.project.manifest;
|
|
22824
|
-
const permissionProfiles = readPermissionProfileFiles();
|
|
22825
|
-
const localPolicyValidation = await compilePolicyBundle({
|
|
22826
|
-
sandboxId: config.sandboxId,
|
|
22827
|
-
effects: extractManifestEffects(manifest2),
|
|
22828
|
-
profileSources: permissionProfiles
|
|
22829
|
-
});
|
|
22830
|
-
if (localPolicyValidation.errors.length > 0) {
|
|
22831
|
-
error("Permission policy validation failed:");
|
|
22832
|
-
for (const error2 of localPolicyValidation.errors) error(` ${error2}`);
|
|
22833
|
-
process.exit(1);
|
|
22834
|
-
}
|
|
22835
|
-
const syncingProfiles = spinner(
|
|
22836
|
-
`Syncing ${permissionProfiles.length} permission profile file(s)...`
|
|
22837
|
-
);
|
|
22838
|
-
try {
|
|
22839
|
-
const result = await api.syncPermissionProfileSources(
|
|
22840
|
-
config.sandboxId,
|
|
22841
|
-
permissionProfiles
|
|
22842
|
-
);
|
|
22843
|
-
syncingProfiles.succeed(
|
|
22844
|
-
` Permission profiles synced: ${brand.secondary(result.digest)}`
|
|
22845
|
-
);
|
|
22846
|
-
} catch (err) {
|
|
22847
|
-
syncingProfiles.fail(
|
|
22848
|
-
` Failed to sync permission profiles: ${err.message}`
|
|
22849
|
-
);
|
|
22850
|
-
process.exit(1);
|
|
22851
|
-
}
|
|
22852
|
-
const uploading = spinner(`Uploading manifest "${manifest2.name}"...`);
|
|
22853
|
-
let uploadedManifest;
|
|
22854
|
-
try {
|
|
22855
|
-
uploadedManifest = await api.uploadManifest(config.sandboxId, manifest2);
|
|
22856
|
-
uploading.succeed(
|
|
22857
|
-
` Manifest uploaded: ${brand.secondary(uploadedManifest.manifestId)}`
|
|
22858
|
-
);
|
|
22859
|
-
} catch (err) {
|
|
22860
|
-
uploading.fail(` Failed to upload manifest: ${err.message}`);
|
|
22861
|
-
process.exit(1);
|
|
22862
|
-
}
|
|
22863
|
-
const building = spinner("Resolving ontology version from manifest...");
|
|
22864
|
-
try {
|
|
22865
|
-
const [versions, tags] = await Promise.all([
|
|
22866
|
-
api.listVersions(config.sandboxId),
|
|
22867
|
-
api.listTags(config.sandboxId).catch(() => [])
|
|
22868
|
-
]);
|
|
22869
|
-
const devTag = tags.find((tag2) => tag2.name === "dev");
|
|
22870
|
-
const prodTag = tags.find((tag2) => tag2.name === "prod");
|
|
22871
|
-
const existingVersion = options.releaseKey ? null : versions.find(
|
|
22872
|
-
(version3) => version3.manifestDigest === uploadedManifest.digest
|
|
22873
|
-
) || null;
|
|
22874
|
-
const existingVersionId = existingVersion?.buildId || null;
|
|
22875
|
-
const devVersionId = devTag?.targetVersionId || devTag?.targetBuildId || null;
|
|
22876
|
-
const reuseDevPromotion = Boolean(
|
|
22877
|
-
options.prod && existingVersion && existingVersion.status === "completed" && existingVersionId && devVersionId === existingVersionId
|
|
22878
|
-
);
|
|
22879
|
-
let completed = existingVersion;
|
|
22880
|
-
let totalTime = 0;
|
|
22881
|
-
let deployedToDev = false;
|
|
22882
|
-
if (reuseDevPromotion) {
|
|
22883
|
-
building.succeed(
|
|
22884
|
-
` Current manifest already matches ${brand.secondary(existingVersionId)} on dev.`
|
|
22885
|
-
);
|
|
22886
|
-
} else {
|
|
22887
|
-
const version3 = await api.createVersion(
|
|
22888
|
-
config.sandboxId,
|
|
22889
|
-
uploadedManifest.manifestId,
|
|
22890
|
-
options.releaseKey
|
|
22891
|
-
);
|
|
22892
|
-
if (version3.createdNewVersion === false && version3.status === "completed") {
|
|
22893
|
-
completed = version3;
|
|
22894
|
-
building.succeed(
|
|
22895
|
-
` Reused ${brand.secondary(version3.buildId)}; the release key is unchanged.`
|
|
22896
|
-
);
|
|
22897
|
-
} else {
|
|
22898
|
-
const startTime = Date.now();
|
|
22899
|
-
building.text = ` Running build for version... ${brand.muted(version3.buildId)}`;
|
|
22900
|
-
completed = await api.waitForVersionBuild(version3.buildId, (status) => {
|
|
22901
|
-
const elapsed = Math.round((Date.now() - startTime) / 1e3);
|
|
22902
|
-
building.text = ` Running build for version... ${brand.muted(`${status} (${elapsed}s)`)}`;
|
|
22903
|
-
});
|
|
22904
|
-
totalTime = Math.round((Date.now() - startTime) / 1e3);
|
|
22905
|
-
deployedToDev = true;
|
|
22906
|
-
building.succeed(
|
|
22907
|
-
` Dev now points to ${brand.secondary(completed.buildId)} (${totalTime}s)`
|
|
22908
|
-
);
|
|
22909
|
-
}
|
|
22910
|
-
}
|
|
22911
|
-
if (!completed) {
|
|
22912
|
-
throw new Error("Could not resolve the current ontology version.");
|
|
22913
|
-
}
|
|
22914
|
-
if (options.prod) {
|
|
22915
|
-
const promoting = spinner("Promoting prod...");
|
|
22916
|
-
await api.promoteVersionToProd(
|
|
22917
|
-
completed.buildId,
|
|
22918
|
-
prodTag?.targetVersionId || prodTag?.targetBuildId || null
|
|
22919
|
-
);
|
|
22920
|
-
promoting.succeed(
|
|
22921
|
-
` Prod now points to ${brand.secondary(completed.buildId)}`
|
|
22922
|
-
);
|
|
22923
|
-
}
|
|
22924
|
-
writeSandboxAgentDocFile(getProjectRoot(), manifest2, {
|
|
22925
|
-
sandboxId: config.sandboxId,
|
|
22926
|
-
apiUrl: config.apiUrl,
|
|
22927
|
-
manifestId: uploadedManifest.manifestId,
|
|
22928
|
-
buildId: completed.buildId
|
|
22929
|
-
});
|
|
22930
|
-
console.log();
|
|
22931
|
-
success(`Deployed ${brand.bold(manifest2.name)} successfully!`);
|
|
22932
|
-
console.log();
|
|
22933
|
-
keyValue({
|
|
22934
|
-
Version: completed.buildId,
|
|
22935
|
-
"Version Number": completed.versionNumber != null ? String(completed.versionNumber) : "N/A",
|
|
22936
|
-
"Build Run": completed.buildRunId || completed.latestBuildRunId || "N/A",
|
|
22937
|
-
Manifest: uploadedManifest.manifestId,
|
|
22938
|
-
"Dev Tag": completed.buildId,
|
|
22939
|
-
"Prod Tag": options.prod ? completed.buildId : prodTag?.targetVersionId || prodTag?.targetBuildId || "unchanged",
|
|
22940
|
-
Release: options.prod ? deployedToDev ? "dev and prod now point to this version" : "prod promoted to the version already on dev" : "dev updated to this version",
|
|
22941
|
-
"Agent doc": "GRANULAR_SANDBOX.md"
|
|
22942
|
-
});
|
|
22943
|
-
console.log(`GRANULAR_RELEASE_CHANGED=${deployedToDev ? "true" : "false"}`);
|
|
22944
|
-
console.log();
|
|
22945
|
-
if (options.prod) {
|
|
22946
|
-
info(
|
|
22947
|
-
"Existing prod environments keep their current version until they are transitioned."
|
|
22948
|
-
);
|
|
22949
|
-
console.log();
|
|
22950
|
-
}
|
|
22951
|
-
} catch (err) {
|
|
22952
|
-
building.fail(` Deploy failed: ${err.message}`);
|
|
22953
|
-
process.exit(1);
|
|
22954
|
-
}
|
|
22955
|
-
}
|
|
23523
|
+
});
|
|
22956
23524
|
|
|
22957
23525
|
// src/cli/commands/status.ts
|
|
22958
23526
|
function summarizeLocalManifest(project) {
|
|
@@ -23316,7 +23884,15 @@ async function whoamiCommand() {
|
|
|
23316
23884
|
}
|
|
23317
23885
|
console.log();
|
|
23318
23886
|
}
|
|
23319
|
-
|
|
23887
|
+
init_annotations();
|
|
23888
|
+
var localDevelopment = Interface(
|
|
23889
|
+
"granular-product/authoring/cli-local-development/local-development",
|
|
23890
|
+
{ label: "Local development", tests: [] }
|
|
23891
|
+
);
|
|
23892
|
+
var devCommand = Method(() => localDevelopment, {
|
|
23893
|
+
label: "Run development environment",
|
|
23894
|
+
description: "Run the local product integration and publish its development action handlers."
|
|
23895
|
+
})(async function devCommand2() {
|
|
23320
23896
|
printHeader();
|
|
23321
23897
|
const config = resolveConfig({ requireApiKey: true, requireProject: true });
|
|
23322
23898
|
if (!config.sandboxId) {
|
|
@@ -23383,7 +23959,7 @@ async function devCommand() {
|
|
|
23383
23959
|
console.log();
|
|
23384
23960
|
await new Promise(() => {
|
|
23385
23961
|
});
|
|
23386
|
-
}
|
|
23962
|
+
});
|
|
23387
23963
|
|
|
23388
23964
|
// src/cli/commands/document.ts
|
|
23389
23965
|
async function documentCommand() {
|
|
@@ -25775,7 +26351,7 @@ function requireTransientFeedbackItem(value) {
|
|
|
25775
26351
|
}
|
|
25776
26352
|
return item;
|
|
25777
26353
|
}
|
|
25778
|
-
function createFeedPublisher(
|
|
26354
|
+
function createFeedPublisher(publish2) {
|
|
25779
26355
|
const makeHandle = (initial) => {
|
|
25780
26356
|
let current = initial;
|
|
25781
26357
|
let mutationQueue = Promise.resolve();
|
|
@@ -25801,7 +26377,7 @@ function createFeedPublisher(publish) {
|
|
|
25801
26377
|
const reservedOperationId = options.operationId || operationId("feed_transient_update");
|
|
25802
26378
|
const reservedOptions = { ...options };
|
|
25803
26379
|
return enqueueMutation(async () => {
|
|
25804
|
-
const response = await
|
|
26380
|
+
const response = await publish2("feed.transient.update", {
|
|
25805
26381
|
transientId: current.id,
|
|
25806
26382
|
expectedRevision: current.revision,
|
|
25807
26383
|
text: text6,
|
|
@@ -25816,7 +26392,7 @@ function createFeedPublisher(publish) {
|
|
|
25816
26392
|
const reservedOperationId = options.operationId || operationId("feed_transient_settle");
|
|
25817
26393
|
const reservedOptions = { ...options };
|
|
25818
26394
|
return enqueueMutation(async () => {
|
|
25819
|
-
const response = await
|
|
26395
|
+
const response = await publish2("feed.transient.settle", {
|
|
25820
26396
|
transientId: current.id,
|
|
25821
26397
|
expectedRevision: current.revision,
|
|
25822
26398
|
...text6 === void 0 ? {} : { text: text6 },
|
|
@@ -25839,7 +26415,7 @@ function createFeedPublisher(publish) {
|
|
|
25839
26415
|
return {
|
|
25840
26416
|
async feedback(text6, options = {}) {
|
|
25841
26417
|
return requireFeedbackItem(
|
|
25842
|
-
await
|
|
26418
|
+
await publish2("feed.feedback", {
|
|
25843
26419
|
text: text6,
|
|
25844
26420
|
...options,
|
|
25845
26421
|
operationId: options.operationId || operationId("feed_feedback")
|
|
@@ -25848,7 +26424,7 @@ function createFeedPublisher(publish) {
|
|
|
25848
26424
|
},
|
|
25849
26425
|
async transientFeedback(text6, options = {}) {
|
|
25850
26426
|
const item = requireTransientFeedbackItem(
|
|
25851
|
-
await
|
|
26427
|
+
await publish2("feed.transient.create", {
|
|
25852
26428
|
text: text6,
|
|
25853
26429
|
...options,
|
|
25854
26430
|
operationId: options.operationId || operationId("feed_transient_create")
|
|
@@ -27360,11 +27936,11 @@ var Session = class {
|
|
|
27360
27936
|
}
|
|
27361
27937
|
this.eventListeners.get("effects:changed").push(handler);
|
|
27362
27938
|
return () => {
|
|
27363
|
-
const
|
|
27364
|
-
if (
|
|
27939
|
+
const listeners2 = this.eventListeners.get("effects:changed");
|
|
27940
|
+
if (listeners2) {
|
|
27365
27941
|
this.eventListeners.set(
|
|
27366
27942
|
"effects:changed",
|
|
27367
|
-
|
|
27943
|
+
listeners2.filter((h) => h !== handler)
|
|
27368
27944
|
);
|
|
27369
27945
|
}
|
|
27370
27946
|
};
|
|
@@ -27379,11 +27955,11 @@ var Session = class {
|
|
|
27379
27955
|
}
|
|
27380
27956
|
this.eventListeners.get("tools:changed").push(handler);
|
|
27381
27957
|
return () => {
|
|
27382
|
-
const
|
|
27383
|
-
if (
|
|
27958
|
+
const listeners2 = this.eventListeners.get("tools:changed");
|
|
27959
|
+
if (listeners2) {
|
|
27384
27960
|
this.eventListeners.set(
|
|
27385
27961
|
"tools:changed",
|
|
27386
|
-
|
|
27962
|
+
listeners2.filter((h) => h !== handler)
|
|
27387
27963
|
);
|
|
27388
27964
|
}
|
|
27389
27965
|
};
|
|
@@ -29807,6 +30383,7 @@ var WSClient = class {
|
|
|
29807
30383
|
};
|
|
29808
30384
|
|
|
29809
30385
|
// src/client.ts
|
|
30386
|
+
init_annotations();
|
|
29810
30387
|
var DEFAULT_CONVERSATION_SESSION_LIST_LIMIT = 100;
|
|
29811
30388
|
var MAX_CONVERSATION_SESSION_LIST_LIMIT = 500;
|
|
29812
30389
|
function requireUserEnvironmentSequence(value, field) {
|
|
@@ -29948,7 +30525,11 @@ function isUnsupportedEffectCatalogMutation(error2) {
|
|
|
29948
30525
|
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
29949
30526
|
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");
|
|
29950
30527
|
}
|
|
29951
|
-
|
|
30528
|
+
var planRecordObjectsChunks = Process({
|
|
30529
|
+
id: "granular-product/authoring/importers-record-apis/record-objects/plan",
|
|
30530
|
+
label: "Plan record chunks",
|
|
30531
|
+
parent: () => Environment.prototype.recordObjects
|
|
30532
|
+
})(function planRecordObjectsChunks2(records, batchSize) {
|
|
29952
30533
|
const total = records.length;
|
|
29953
30534
|
const size = Math.max(1, Math.min(batchSize, total));
|
|
29954
30535
|
const chunkCount = Math.ceil(total / size);
|
|
@@ -29958,7 +30539,7 @@ function planRecordObjectsChunks(records, batchSize) {
|
|
|
29958
30539
|
plans.push({ chunkIndex, chunkCount, offset, slice });
|
|
29959
30540
|
}
|
|
29960
30541
|
return plans;
|
|
29961
|
-
}
|
|
30542
|
+
});
|
|
29962
30543
|
function preserveRecordObjectRealId(record3) {
|
|
29963
30544
|
const realId = record3.id.trim();
|
|
29964
30545
|
if (!realId) {
|
|
@@ -30183,15 +30764,54 @@ function isGraphQLMutationDocument(query) {
|
|
|
30183
30764
|
}
|
|
30184
30765
|
return false;
|
|
30185
30766
|
}
|
|
30186
|
-
var
|
|
30187
|
-
|
|
30188
|
-
|
|
30189
|
-
|
|
30190
|
-
|
|
30191
|
-
|
|
30192
|
-
|
|
30193
|
-
|
|
30767
|
+
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, _init2;
|
|
30768
|
+
_Environment_decorators = [Block({
|
|
30769
|
+
description: "Expose records, imports, queries, relationships and sessions for one product environment.",
|
|
30770
|
+
id: "granular-product/authoring/importers-record-apis",
|
|
30771
|
+
label: "Environment client",
|
|
30772
|
+
exposedBy: [() => Granular],
|
|
30773
|
+
tests: [
|
|
30774
|
+
"./record-objects.cancellation.test.ts",
|
|
30775
|
+
"./environment.feed.test.ts"
|
|
30776
|
+
],
|
|
30777
|
+
parent: () => Granular
|
|
30778
|
+
})], _queries_dec = [Interface({
|
|
30779
|
+
label: "Queries & search",
|
|
30780
|
+
description: "Query the environment\u2019s graph or search its records."
|
|
30781
|
+
})], _stateChanges_dec = [Interface({
|
|
30782
|
+
label: "User state",
|
|
30783
|
+
description: "Record changes to user state and read the environment\u2019s current state."
|
|
30784
|
+
})], _sessions_dec = [Interface({
|
|
30785
|
+
label: "Sessions",
|
|
30786
|
+
description: "Create, connect, list and close conversations in this environment."
|
|
30787
|
+
})], _relationships_dec = [Interface({
|
|
30788
|
+
label: "Relationships",
|
|
30789
|
+
description: "Define, read, attach and detach relationships between records."
|
|
30790
|
+
})], _imports_dec = [Interface({
|
|
30791
|
+
id: "granular-product/ingestion/importer-lifecycle",
|
|
30792
|
+
label: "Background imports",
|
|
30793
|
+
description: "Submit a background record import and inspect or cancel its progress."
|
|
30794
|
+
})], _records_dec = [Interface({
|
|
30795
|
+
label: "Records",
|
|
30796
|
+
description: "Write customer records into the environment, including bounded batch requests."
|
|
30797
|
+
})], _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({
|
|
30798
|
+
id: "granular-product/authoring/importers-record-apis/record-objects",
|
|
30799
|
+
label: "Write record batches"
|
|
30800
|
+
}), Method(() => _Environment.records)], _executeRecordObjectsChunk_dec = [Process({
|
|
30801
|
+
id: "granular-product/authoring/importers-record-apis/record-objects/write-chunk",
|
|
30802
|
+
label: "Write chunk with retry",
|
|
30803
|
+
parent: () => _Environment.prototype.recordObjects
|
|
30804
|
+
})], _enqueueRecordImport_dec = [Method(() => _Environment.imports)], _listRecordImports_dec = [Method(() => _Environment.imports)], _getRecordImport_dec = [Method(() => _Environment.imports)], _cancelRecordImport_dec = [Method(() => _Environment.imports)];
|
|
30805
|
+
var _Environment = class _Environment {
|
|
30194
30806
|
constructor(granular, envData, apiKey, apiEndpoint, tokenProvider, beforeMutationSend, graphqlIdempotencyKey) {
|
|
30807
|
+
__runInitializers(_init2, 5, this);
|
|
30808
|
+
__publicField(this, "granular");
|
|
30809
|
+
__publicField(this, "envData");
|
|
30810
|
+
__publicField(this, "_apiKey");
|
|
30811
|
+
__publicField(this, "_apiEndpoint");
|
|
30812
|
+
__publicField(this, "_tokenProvider");
|
|
30813
|
+
__publicField(this, "_beforeMutationSend");
|
|
30814
|
+
__publicField(this, "_graphqlIdempotencyKey");
|
|
30195
30815
|
this.granular = granular;
|
|
30196
30816
|
this.envData = envData;
|
|
30197
30817
|
this._apiKey = apiKey;
|
|
@@ -30441,10 +31061,6 @@ var Environment = class _Environment {
|
|
|
30441
31061
|
}
|
|
30442
31062
|
);
|
|
30443
31063
|
}
|
|
30444
|
-
/**
|
|
30445
|
-
* Mirror product-owned workflow state into Granular without making Granular
|
|
30446
|
-
* own the customer application's state machine.
|
|
30447
|
-
*/
|
|
30448
31064
|
async recordState(input) {
|
|
30449
31065
|
const { machine, state, ...target } = input;
|
|
30450
31066
|
if (!machine.trim()) {
|
|
@@ -30716,30 +31332,6 @@ var Environment = class _Environment {
|
|
|
30716
31332
|
const prefix = `${className}_`;
|
|
30717
31333
|
return graphPath.startsWith(prefix) ? graphPath.substring(prefix.length) : graphPath;
|
|
30718
31334
|
}
|
|
30719
|
-
/**
|
|
30720
|
-
* Execute a GraphQL query against the environment's graph.
|
|
30721
|
-
*
|
|
30722
|
-
* The query uses the Granular graph query language (based on Cypher/GraphQL).
|
|
30723
|
-
* Authentication is handled automatically using the SDK's API key.
|
|
30724
|
-
*
|
|
30725
|
-
* @param query - The GraphQL query string
|
|
30726
|
-
* @param variables - Optional variables for the query
|
|
30727
|
-
* @returns The query result data
|
|
30728
|
-
*
|
|
30729
|
-
* @example
|
|
30730
|
-
* ```typescript
|
|
30731
|
-
* // Read the workspace
|
|
30732
|
-
* const result = await env.graphql(
|
|
30733
|
-
* `query { model(path: "workspace") { path label submodels { path label } } }`
|
|
30734
|
-
* );
|
|
30735
|
-
* console.log(result.data);
|
|
30736
|
-
*
|
|
30737
|
-
* // Create a model
|
|
30738
|
-
* const created = await env.graphql(
|
|
30739
|
-
* `mutation { at(path: "workspace") { create_submodel(subpath: "my_node", label: "My Node", prototype: "Model") { model { path label } } } }`
|
|
30740
|
-
* );
|
|
30741
|
-
* ```
|
|
30742
|
-
*/
|
|
30743
31335
|
async graphql(query, variables, options) {
|
|
30744
31336
|
const authToken = await this.resolveAuthToken();
|
|
30745
31337
|
if (this._beforeMutationSend && isGraphQLMutationDocument(query)) {
|
|
@@ -30832,27 +31424,6 @@ var Environment = class _Environment {
|
|
|
30832
31424
|
rank: rankRecordSearchResult(result, normalizedQuery, index)
|
|
30833
31425
|
})).sort((left, right) => left.rank - right.rank).map((item) => item.result).slice(0, limit);
|
|
30834
31426
|
}
|
|
30835
|
-
// ==================== RELATIONSHIP METHODS ====================
|
|
30836
|
-
/**
|
|
30837
|
-
* Define a relationship between two model types.
|
|
30838
|
-
*
|
|
30839
|
-
* Creates both submodels (if they don't exist) and links them with
|
|
30840
|
-
* a RelationshipDef node that encodes cardinality.
|
|
30841
|
-
*
|
|
30842
|
-
* @example
|
|
30843
|
-
* ```typescript
|
|
30844
|
-
* // Author has many Books, Book has one Author
|
|
30845
|
-
* const rel = await env.defineRelationship({
|
|
30846
|
-
* model: 'author',
|
|
30847
|
-
* localSubmodel: 'books',
|
|
30848
|
-
* localIsMany: true,
|
|
30849
|
-
* foreignModel: 'book',
|
|
30850
|
-
* foreignSubmodel: 'author',
|
|
30851
|
-
* foreignIsMany: false,
|
|
30852
|
-
* });
|
|
30853
|
-
* console.log(rel.relationship_kind); // "one_to_many"
|
|
30854
|
-
* ```
|
|
30855
|
-
*/
|
|
30856
31427
|
async defineRelationship(options) {
|
|
30857
31428
|
const result = await this.graphql(
|
|
30858
31429
|
`mutation DefineRelationship(
|
|
@@ -30898,20 +31469,6 @@ var Environment = class _Environment {
|
|
|
30898
31469
|
}
|
|
30899
31470
|
return result.data.at.define_relationship;
|
|
30900
31471
|
}
|
|
30901
|
-
/**
|
|
30902
|
-
* Get all relationships for a model type.
|
|
30903
|
-
*
|
|
30904
|
-
* @param modelPath - The model type path (e.g., "author")
|
|
30905
|
-
* @returns Array of relationships from this model's perspective
|
|
30906
|
-
*
|
|
30907
|
-
* @example
|
|
30908
|
-
* ```typescript
|
|
30909
|
-
* const rels = await env.getRelationships('author');
|
|
30910
|
-
* for (const rel of rels) {
|
|
30911
|
-
* console.log(`${rel.local_submodel.path} -> ${rel.foreign_model.path} (${rel.relationship_kind})`);
|
|
30912
|
-
* }
|
|
30913
|
-
* ```
|
|
30914
|
-
*/
|
|
30915
31472
|
async getRelationships(modelPath) {
|
|
30916
31473
|
const result = await this.graphql(
|
|
30917
31474
|
`query GetRelationships($path: String) {
|
|
@@ -30936,27 +31493,6 @@ var Environment = class _Environment {
|
|
|
30936
31493
|
}
|
|
30937
31494
|
return result.data?.model?.relationships || [];
|
|
30938
31495
|
}
|
|
30939
|
-
/**
|
|
30940
|
-
* Attach a target model to a relationship submodel.
|
|
30941
|
-
*
|
|
30942
|
-
* Handles cardinality automatically:
|
|
30943
|
-
* - "One" side: sets/replaces the reference
|
|
30944
|
-
* - "Many" side: adds the target to the collection
|
|
30945
|
-
*
|
|
30946
|
-
* If the target model doesn't exist, it's created as an instance of the foreign type.
|
|
30947
|
-
* Bidirectional sync is automatic.
|
|
30948
|
-
*
|
|
30949
|
-
* @param modelPath - The model instance path (e.g., "tolkien")
|
|
30950
|
-
* @param submodelPath - The relationship submodel (e.g., "books")
|
|
30951
|
-
* @param targetPath - The target model to attach (e.g., "lord_of_the_rings")
|
|
30952
|
-
*
|
|
30953
|
-
* @example
|
|
30954
|
-
* ```typescript
|
|
30955
|
-
* // Attach a book to an author (many side)
|
|
30956
|
-
* await env.attach('tolkien', 'books', 'lord_of_the_rings');
|
|
30957
|
-
* // This also automatically sets lord_of_the_rings:author -> tolkien
|
|
30958
|
-
* ```
|
|
30959
|
-
*/
|
|
30960
31496
|
async attach(modelPath, submodelPath, targetPath) {
|
|
30961
31497
|
const result = await this.graphql(
|
|
30962
31498
|
`mutation Attach($target: String!) {
|
|
@@ -30976,24 +31512,6 @@ var Environment = class _Environment {
|
|
|
30976
31512
|
);
|
|
30977
31513
|
}
|
|
30978
31514
|
}
|
|
30979
|
-
/**
|
|
30980
|
-
* Detach a target model from a relationship submodel.
|
|
30981
|
-
*
|
|
30982
|
-
* Handles bidirectional cleanup automatically.
|
|
30983
|
-
*
|
|
30984
|
-
* @param modelPath - The model instance path
|
|
30985
|
-
* @param submodelPath - The relationship submodel
|
|
30986
|
-
* @param targetPath - The target to detach (optional for "one" side; omit on "many" side to detach all)
|
|
30987
|
-
*
|
|
30988
|
-
* @example
|
|
30989
|
-
* ```typescript
|
|
30990
|
-
* // Detach a specific book
|
|
30991
|
-
* await env.detach('tolkien', 'books', 'lord_of_the_rings');
|
|
30992
|
-
*
|
|
30993
|
-
* // Detach all books
|
|
30994
|
-
* await env.detach('tolkien', 'books');
|
|
30995
|
-
* ```
|
|
30996
|
-
*/
|
|
30997
31515
|
async detach(modelPath, submodelPath, targetPath) {
|
|
30998
31516
|
const targetArg = targetPath ? `target: "${targetPath}"` : "";
|
|
30999
31517
|
const result = await this.graphql(
|
|
@@ -31013,19 +31531,6 @@ var Environment = class _Environment {
|
|
|
31013
31531
|
);
|
|
31014
31532
|
}
|
|
31015
31533
|
}
|
|
31016
|
-
/**
|
|
31017
|
-
* List all related models through a relationship submodel.
|
|
31018
|
-
*
|
|
31019
|
-
* @param modelPath - The model instance path
|
|
31020
|
-
* @param submodelPath - The relationship submodel
|
|
31021
|
-
* @returns Array of related model references
|
|
31022
|
-
*
|
|
31023
|
-
* @example
|
|
31024
|
-
* ```typescript
|
|
31025
|
-
* const books = await env.listRelated('tolkien', 'books');
|
|
31026
|
-
* console.log(books); // [{ path: "lord_of_the_rings", label: "Lord of the Rings" }, ...]
|
|
31027
|
-
* ```
|
|
31028
|
-
*/
|
|
31029
31534
|
async listRelated(modelPath, submodelPath) {
|
|
31030
31535
|
const result = await this.graphql(
|
|
31031
31536
|
`mutation ListRelated {
|
|
@@ -31447,38 +31952,6 @@ var Environment = class _Environment {
|
|
|
31447
31952
|
}
|
|
31448
31953
|
}
|
|
31449
31954
|
}
|
|
31450
|
-
// ==================== RECORD OBJECT ====================
|
|
31451
|
-
/**
|
|
31452
|
-
* Create or update an instance of a class in the graph.
|
|
31453
|
-
*
|
|
31454
|
-
* Uses `instantiate` under the hood, which has find-or-create semantics:
|
|
31455
|
-
* if an instance with the given `id` already exists for the class it is
|
|
31456
|
-
* returned; otherwise a new instance is created. Fields are then set
|
|
31457
|
-
* (overwriting previous values) and relationships are attached.
|
|
31458
|
-
*
|
|
31459
|
-
* The graph path is derived as `{className}_{id}` to ensure uniqueness
|
|
31460
|
-
* across classes (two objects of different classes may share the same
|
|
31461
|
-
* real-world ID). Relationship targets are also resolved automatically
|
|
31462
|
-
* using the foreign class from the relationship definition.
|
|
31463
|
-
*
|
|
31464
|
-
* @param options - The object specification
|
|
31465
|
-
* @returns The graph path, real-world ID, and creation status
|
|
31466
|
-
*
|
|
31467
|
-
* @example
|
|
31468
|
-
* ```typescript
|
|
31469
|
-
* // Create an author with fields
|
|
31470
|
-
* const result = await env.recordObject({
|
|
31471
|
-
* className: 'author',
|
|
31472
|
-
* id: 'tolkien',
|
|
31473
|
-
* label: 'J.R.R. Tolkien',
|
|
31474
|
-
* fields: { name: 'J.R.R. Tolkien', birth_year: 1892 },
|
|
31475
|
-
* relationships: { books: ['lotr', 'silmarillion'] },
|
|
31476
|
-
* });
|
|
31477
|
-
* // result.path → 'author_tolkien' (internal graph path)
|
|
31478
|
-
* // result.id → 'tolkien' (real-world ID)
|
|
31479
|
-
* // result.created → true
|
|
31480
|
-
* ```
|
|
31481
|
-
*/
|
|
31482
31955
|
async recordObject(options) {
|
|
31483
31956
|
const results = await this.recordObjects([options]);
|
|
31484
31957
|
const result = results[0];
|
|
@@ -31487,24 +31960,6 @@ var Environment = class _Environment {
|
|
|
31487
31960
|
}
|
|
31488
31961
|
return result;
|
|
31489
31962
|
}
|
|
31490
|
-
/**
|
|
31491
|
-
* Batch version of `recordObject()`.
|
|
31492
|
-
*
|
|
31493
|
-
* Sends rows through the control-plane **`/records/batch`** endpoint in **chunks** (default
|
|
31494
|
-
* **100** records per HTTP request) so individual requests stay bounded and gateway timeouts are
|
|
31495
|
-
* unlikely. Each chunk is retried on transient network / worker errors.
|
|
31496
|
-
*
|
|
31497
|
-
* Use the optional second argument to:
|
|
31498
|
-
* - **`batchSize`** — rows per POST (smaller = more progress events; larger = fewer round trips).
|
|
31499
|
-
* - **`concurrency`** — run up to N chunk POSTs in parallel (capped at 16) when you want lower wall time.
|
|
31500
|
-
* - **`onChunkComplete`** — hook for UIs after each chunk succeeds (row order in the returned array
|
|
31501
|
-
* always matches `records`; chunk **completion** order may differ when `concurrency > 1`).
|
|
31502
|
-
*
|
|
31503
|
-
* For **asynchronous** ingestion with worker-side batching and aggregate counters (`queued`,
|
|
31504
|
-
* `completed`, …), use **`enqueueRecordImport`** and poll **`getRecordImport`** /
|
|
31505
|
-
* **`getRecordImportSummary`** — best for very large fire-and-forget loads when immediate
|
|
31506
|
-
* synchronous commit of every row is not required.
|
|
31507
|
-
*/
|
|
31508
31963
|
async recordObjects(records, options) {
|
|
31509
31964
|
options?.signal?.throwIfAborted();
|
|
31510
31965
|
if (!Array.isArray(records) || records.length === 0) {
|
|
@@ -31589,15 +32044,6 @@ var Environment = class _Environment {
|
|
|
31589
32044
|
}
|
|
31590
32045
|
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
31591
32046
|
}
|
|
31592
|
-
/**
|
|
31593
|
-
* Queue a background record import for this environment (async worker pipeline).
|
|
31594
|
-
*
|
|
31595
|
-
* **vs `recordObjects`:** this path accepts the full payload in one request, returns an
|
|
31596
|
-
* **`importId`**, and processes rows in the background — use **`getRecordImport`** /
|
|
31597
|
-
* **`getRecordImportSummary`** for progress. Choose it for large bulk loads where you do not
|
|
31598
|
-
* need every row committed before the HTTP call returns. Use **`recordObjects`** when you need
|
|
31599
|
-
* synchronous upserts and fine-grained chunk progress via **`onChunkComplete`**.
|
|
31600
|
-
*/
|
|
31601
32047
|
async enqueueRecordImport(records, options = {}) {
|
|
31602
32048
|
const recordsToImport = records.map(preserveRecordObjectRealId);
|
|
31603
32049
|
return this.controlPlaneRequest(
|
|
@@ -31614,9 +32060,6 @@ var Environment = class _Environment {
|
|
|
31614
32060
|
}
|
|
31615
32061
|
);
|
|
31616
32062
|
}
|
|
31617
|
-
/**
|
|
31618
|
-
* List queued or completed record imports for this environment.
|
|
31619
|
-
*/
|
|
31620
32063
|
async listRecordImports(status) {
|
|
31621
32064
|
const suffix = status ? `?status=${encodeURIComponent(status)}` : "";
|
|
31622
32065
|
const response = await this.controlPlaneRequest(
|
|
@@ -31639,9 +32082,6 @@ var Environment = class _Environment {
|
|
|
31639
32082
|
const summary = await this.getRecordImportSummary();
|
|
31640
32083
|
return summary.awaitingRecords;
|
|
31641
32084
|
}
|
|
31642
|
-
/**
|
|
31643
|
-
* Fetch a single record import by id.
|
|
31644
|
-
*/
|
|
31645
32085
|
async getRecordImport(importId) {
|
|
31646
32086
|
return this.controlPlaneRequest(
|
|
31647
32087
|
`/control/record-imports/${importId}`
|
|
@@ -31656,9 +32096,6 @@ var Environment = class _Environment {
|
|
|
31656
32096
|
const response = await this.controlPlaneRequest(`/control/record-imports/${importId}/items${suffix}`);
|
|
31657
32097
|
return Array.isArray(response.items) ? response.items : [];
|
|
31658
32098
|
}
|
|
31659
|
-
/**
|
|
31660
|
-
* Cancel a queued/background record import.
|
|
31661
|
-
*/
|
|
31662
32099
|
async cancelRecordImport(importId) {
|
|
31663
32100
|
return this.controlPlaneRequest(
|
|
31664
32101
|
`/control/record-imports/${importId}/cancel`,
|
|
@@ -31668,17 +32105,75 @@ var Environment = class _Environment {
|
|
|
31668
32105
|
);
|
|
31669
32106
|
}
|
|
31670
32107
|
};
|
|
31671
|
-
|
|
31672
|
-
|
|
31673
|
-
|
|
31674
|
-
|
|
31675
|
-
|
|
31676
|
-
|
|
31677
|
-
|
|
31678
|
-
|
|
31679
|
-
|
|
32108
|
+
_init2 = __decoratorStart(null);
|
|
32109
|
+
__decorateElement(_init2, 1, "recordState", _recordState_dec, _Environment);
|
|
32110
|
+
__decorateElement(_init2, 1, "listSessions", _listSessions_dec, _Environment);
|
|
32111
|
+
__decorateElement(_init2, 1, "getUserEnvironmentState", _getUserEnvironmentState_dec, _Environment);
|
|
32112
|
+
__decorateElement(_init2, 1, "createSession", _createSession_dec, _Environment);
|
|
32113
|
+
__decorateElement(_init2, 1, "connectSession", _connectSession_dec, _Environment);
|
|
32114
|
+
__decorateElement(_init2, 1, "closeSession", _closeSession_dec, _Environment);
|
|
32115
|
+
__decorateElement(_init2, 1, "graphql", _graphql_dec, _Environment);
|
|
32116
|
+
__decorateElement(_init2, 1, "searchRecords", _searchRecords_dec, _Environment);
|
|
32117
|
+
__decorateElement(_init2, 1, "defineRelationship", _defineRelationship_dec, _Environment);
|
|
32118
|
+
__decorateElement(_init2, 1, "getRelationships", _getRelationships_dec, _Environment);
|
|
32119
|
+
__decorateElement(_init2, 1, "attach", _attach_dec, _Environment);
|
|
32120
|
+
__decorateElement(_init2, 1, "detach", _detach_dec, _Environment);
|
|
32121
|
+
__decorateElement(_init2, 1, "listRelated", _listRelated_dec, _Environment);
|
|
32122
|
+
__decorateElement(_init2, 1, "recordObject", _recordObject_dec, _Environment);
|
|
32123
|
+
__decorateElement(_init2, 1, "recordObjects", _recordObjects_dec, _Environment);
|
|
32124
|
+
__decorateElement(_init2, 1, "executeRecordObjectsChunk", _executeRecordObjectsChunk_dec, _Environment);
|
|
32125
|
+
__decorateElement(_init2, 1, "enqueueRecordImport", _enqueueRecordImport_dec, _Environment);
|
|
32126
|
+
__decorateElement(_init2, 1, "listRecordImports", _listRecordImports_dec, _Environment);
|
|
32127
|
+
__decorateElement(_init2, 1, "getRecordImport", _getRecordImport_dec, _Environment);
|
|
32128
|
+
__decorateElement(_init2, 1, "cancelRecordImport", _cancelRecordImport_dec, _Environment);
|
|
32129
|
+
__decorateElement(_init2, 13, "queries", _queries_dec, _Environment);
|
|
32130
|
+
__decorateElement(_init2, 13, "stateChanges", _stateChanges_dec, _Environment);
|
|
32131
|
+
__decorateElement(_init2, 13, "sessions", _sessions_dec, _Environment);
|
|
32132
|
+
__decorateElement(_init2, 13, "relationships", _relationships_dec, _Environment);
|
|
32133
|
+
__decorateElement(_init2, 13, "imports", _imports_dec, _Environment);
|
|
32134
|
+
__decorateElement(_init2, 13, "records", _records_dec, _Environment);
|
|
32135
|
+
_Environment = __decorateElement(_init2, 0, "Environment", _Environment_decorators, _Environment);
|
|
32136
|
+
__publicField(_Environment, "queries", __runInitializers(_init2, 8, _Environment)), __runInitializers(_init2, 11, _Environment);
|
|
32137
|
+
__publicField(_Environment, "stateChanges", __runInitializers(_init2, 12, _Environment)), __runInitializers(_init2, 15, _Environment);
|
|
32138
|
+
__publicField(_Environment, "sessions", __runInitializers(_init2, 16, _Environment)), __runInitializers(_init2, 19, _Environment);
|
|
32139
|
+
__publicField(_Environment, "relationships", __runInitializers(_init2, 20, _Environment)), __runInitializers(_init2, 23, _Environment);
|
|
32140
|
+
__publicField(_Environment, "imports", __runInitializers(_init2, 24, _Environment)), __runInitializers(_init2, 27, _Environment);
|
|
32141
|
+
__publicField(_Environment, "records", __runInitializers(_init2, 28, _Environment)), __runInitializers(_init2, 31, _Environment);
|
|
32142
|
+
__runInitializers(_init2, 1, _Environment);
|
|
32143
|
+
var Environment = _Environment;
|
|
32144
|
+
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, _init3;
|
|
32145
|
+
_EnvironmentSession_decorators = [Block({
|
|
32146
|
+
description: "Expose conversation messages, selected data and lifecycle operations for one environment session.",
|
|
32147
|
+
id: "granular-product/authoring/importers-record-apis/session-client",
|
|
32148
|
+
label: "Session client",
|
|
32149
|
+
exposedBy: [() => Environment, () => Granular],
|
|
32150
|
+
tests: [
|
|
32151
|
+
"./environment.feed.test.ts",
|
|
32152
|
+
"./environment.assistant-reply.test.ts"
|
|
32153
|
+
],
|
|
32154
|
+
parent: () => Environment
|
|
32155
|
+
})];
|
|
32156
|
+
var _EnvironmentSession = class _EnvironmentSession extends (_a = Session, _lifecycle_dec = [Interface({
|
|
32157
|
+
label: "Connection lifecycle",
|
|
32158
|
+
description: "Check session readiness and close or disconnect the session client."
|
|
32159
|
+
})], _records_dec2 = [Interface({
|
|
32160
|
+
label: "Session records",
|
|
32161
|
+
description: "Write records or mention an existing record in the current conversation."
|
|
32162
|
+
})], _conversation_dec = [Interface({
|
|
32163
|
+
label: "Conversation data",
|
|
32164
|
+
description: "Read the conversation document and selected data, and publish assistant replies."
|
|
32165
|
+
})], _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) {
|
|
31680
32166
|
constructor(client, environment, clientId, options = {}) {
|
|
31681
32167
|
super(client, clientId, { initialQuota: options.initialQuota });
|
|
32168
|
+
__runInitializers(_init3, 5, this);
|
|
32169
|
+
__publicField(this, "environment");
|
|
32170
|
+
__publicField(this, "sessionDataRoutePrefix");
|
|
32171
|
+
__publicField(this, "sessionDataHeaders");
|
|
32172
|
+
__publicField(this, "beforeMutationSend");
|
|
32173
|
+
__publicField(this, "heartbeatTimer", null);
|
|
32174
|
+
__publicField(this, "heartbeatProbeInFlight", false);
|
|
32175
|
+
/** The last known graph container status, updated by checkReadiness(). */
|
|
32176
|
+
__publicField(this, "graphContainerStatus", null);
|
|
31682
32177
|
this.environment = environment;
|
|
31683
32178
|
this.sessionDataRoutePrefix = options.sessionDataRoutePrefix || "/orchestrator/ws/sessions";
|
|
31684
32179
|
this.sessionDataHeaders = options.sessionDataHeaders || {};
|
|
@@ -31776,9 +32271,6 @@ var EnvironmentSession = class extends Session {
|
|
|
31776
32271
|
get feedback() {
|
|
31777
32272
|
return this.environment.feedback;
|
|
31778
32273
|
}
|
|
31779
|
-
/**
|
|
31780
|
-
* Return a plain JS copy of the synced session heap.
|
|
31781
|
-
*/
|
|
31782
32274
|
getHeap() {
|
|
31783
32275
|
const doc = this.document;
|
|
31784
32276
|
return normalizeHeapSnapshot(doc?.heap);
|
|
@@ -31853,22 +32345,9 @@ var EnvironmentSession = class extends Session {
|
|
|
31853
32345
|
});
|
|
31854
32346
|
return response.json();
|
|
31855
32347
|
}
|
|
31856
|
-
/**
|
|
31857
|
-
* Fetch the live session document from the runtime DO.
|
|
31858
|
-
*
|
|
31859
|
-
* For presentation history use `feed.list()` or `transcript.list()`.
|
|
31860
|
-
* Timeline and job collections are diagnostic/execution data only.
|
|
31861
|
-
*/
|
|
31862
32348
|
async getDocument() {
|
|
31863
32349
|
return this.sessionDataRequest("/document");
|
|
31864
32350
|
}
|
|
31865
|
-
/**
|
|
31866
|
-
* Publish one terminal assistant reply from a trusted server integration.
|
|
31867
|
-
*
|
|
31868
|
-
* This uses the API-key-authenticated HTTP session boundary. Delegated
|
|
31869
|
-
* browser sessions cannot use it and never receive assistant feed-authoring
|
|
31870
|
-
* capability through their WebSocket.
|
|
31871
|
-
*/
|
|
31872
32351
|
async publishAssistantReply(input) {
|
|
31873
32352
|
if (this.sessionDataRoutePrefix === "/sdk/browser-sessions") {
|
|
31874
32353
|
throw new Error(
|
|
@@ -32250,13 +32729,6 @@ var EnvironmentSession = class extends Session {
|
|
|
32250
32729
|
async listFeedback() {
|
|
32251
32730
|
return this.environment.listFeedback();
|
|
32252
32731
|
}
|
|
32253
|
-
/**
|
|
32254
|
-
* Close the session and disconnect from the sandbox.
|
|
32255
|
-
*
|
|
32256
|
-
* Sends `client.goodbye` over WebSocket first, then issues an HTTP fallback
|
|
32257
|
-
* to the runtime goodbye endpoint if no definitive WS-side runtime notify
|
|
32258
|
-
* acknowledgement was observed.
|
|
32259
|
-
*/
|
|
32260
32732
|
async disconnect() {
|
|
32261
32733
|
this.stopHeartbeat();
|
|
32262
32734
|
this.disposeSessionFeed();
|
|
@@ -32300,15 +32772,9 @@ var EnvironmentSession = class extends Session {
|
|
|
32300
32772
|
this.stopHeartbeat();
|
|
32301
32773
|
this.client.disconnect({ reason: "Transport detach" });
|
|
32302
32774
|
}
|
|
32303
|
-
/**
|
|
32304
|
-
* Backwards-compatible alias for `disconnect()`.
|
|
32305
|
-
*/
|
|
32306
32775
|
async close() {
|
|
32307
32776
|
await this.disconnect();
|
|
32308
32777
|
}
|
|
32309
|
-
/**
|
|
32310
|
-
* Check if the graph container is ready and warm.
|
|
32311
|
-
*/
|
|
32312
32778
|
async checkReadiness() {
|
|
32313
32779
|
const result = await this.client.call("client.heartbeat", {});
|
|
32314
32780
|
const containerStatus = result?.graphContainerStatus ?? {
|
|
@@ -32320,6 +32786,24 @@ var EnvironmentSession = class extends Session {
|
|
|
32320
32786
|
return containerStatus;
|
|
32321
32787
|
}
|
|
32322
32788
|
};
|
|
32789
|
+
_init3 = __decoratorStart(_a);
|
|
32790
|
+
__decorateElement(_init3, 1, "getHeap", _getHeap_dec, _EnvironmentSession);
|
|
32791
|
+
__decorateElement(_init3, 1, "getDocument", _getDocument_dec, _EnvironmentSession);
|
|
32792
|
+
__decorateElement(_init3, 1, "publishAssistantReply", _publishAssistantReply_dec, _EnvironmentSession);
|
|
32793
|
+
__decorateElement(_init3, 1, "mentionRecord", _mentionRecord_dec, _EnvironmentSession);
|
|
32794
|
+
__decorateElement(_init3, 1, "recordObjects", _recordObjects_dec2, _EnvironmentSession);
|
|
32795
|
+
__decorateElement(_init3, 1, "disconnect", _disconnect_dec, _EnvironmentSession);
|
|
32796
|
+
__decorateElement(_init3, 1, "close", _close_dec, _EnvironmentSession);
|
|
32797
|
+
__decorateElement(_init3, 1, "checkReadiness", _checkReadiness_dec, _EnvironmentSession);
|
|
32798
|
+
__decorateElement(_init3, 13, "lifecycle", _lifecycle_dec, _EnvironmentSession);
|
|
32799
|
+
__decorateElement(_init3, 13, "records", _records_dec2, _EnvironmentSession);
|
|
32800
|
+
__decorateElement(_init3, 13, "conversation", _conversation_dec, _EnvironmentSession);
|
|
32801
|
+
_EnvironmentSession = __decorateElement(_init3, 0, "EnvironmentSession", _EnvironmentSession_decorators, _EnvironmentSession);
|
|
32802
|
+
__publicField(_EnvironmentSession, "lifecycle", __runInitializers(_init3, 8, _EnvironmentSession)), __runInitializers(_init3, 11, _EnvironmentSession);
|
|
32803
|
+
__publicField(_EnvironmentSession, "records", __runInitializers(_init3, 12, _EnvironmentSession)), __runInitializers(_init3, 15, _EnvironmentSession);
|
|
32804
|
+
__publicField(_EnvironmentSession, "conversation", __runInitializers(_init3, 16, _EnvironmentSession)), __runInitializers(_init3, 19, _EnvironmentSession);
|
|
32805
|
+
__runInitializers(_init3, 1, _EnvironmentSession);
|
|
32806
|
+
var EnvironmentSession = _EnvironmentSession;
|
|
32323
32807
|
var OntologyHandle = class {
|
|
32324
32808
|
granular;
|
|
32325
32809
|
ontologyNameOrId;
|
|
@@ -32371,40 +32855,62 @@ var OntologyHandle = class {
|
|
|
32371
32855
|
};
|
|
32372
32856
|
}
|
|
32373
32857
|
};
|
|
32374
|
-
var
|
|
32375
|
-
|
|
32376
|
-
|
|
32377
|
-
|
|
32378
|
-
|
|
32379
|
-
|
|
32380
|
-
|
|
32381
|
-
|
|
32382
|
-
|
|
32383
|
-
|
|
32384
|
-
|
|
32385
|
-
|
|
32386
|
-
|
|
32387
|
-
|
|
32388
|
-
|
|
32389
|
-
|
|
32390
|
-
|
|
32391
|
-
|
|
32392
|
-
|
|
32393
|
-
|
|
32394
|
-
|
|
32395
|
-
|
|
32396
|
-
sandboxEffectHostPromises = /* @__PURE__ */ new Map();
|
|
32397
|
-
effectHostGenerations = /* @__PURE__ */ new Map();
|
|
32398
|
-
effectHostRecovery = /* @__PURE__ */ new Map();
|
|
32399
|
-
/** Ontology-bound environment importer hooks keyed by the caller's ontology identifier. */
|
|
32400
|
-
ontologyImporters = /* @__PURE__ */ new Map();
|
|
32401
|
-
/** Resolved importer hooks keyed by sandboxId for fast lookups during openEnvironment(). */
|
|
32402
|
-
sandboxImporters = /* @__PURE__ */ new Map();
|
|
32858
|
+
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, _init4;
|
|
32859
|
+
_Granular_decorators = [Block({
|
|
32860
|
+
description: "Authenticate an application and provide access to its environments, sessions and registered action handlers.",
|
|
32861
|
+
id: "granular-product/authoring/sdk-ontology-facade",
|
|
32862
|
+
label: "Granular client",
|
|
32863
|
+
tests: ["./environment.opening.test.ts"],
|
|
32864
|
+
docs: "../README.md"
|
|
32865
|
+
})], _transport_dec = [Interface({
|
|
32866
|
+
label: "HTTP requests",
|
|
32867
|
+
description: "Send authenticated SDK requests to the configured Granular API."
|
|
32868
|
+
})], _effectHosts_dec = [Interface({
|
|
32869
|
+
id: "granular-product/authoring/live-effect-hosts",
|
|
32870
|
+
label: "Application action handlers",
|
|
32871
|
+
description: "Register application functions that Granular may invoke as actions, and disconnect handlers when they are no longer available."
|
|
32872
|
+
})], _sessions_dec2 = [Interface({
|
|
32873
|
+
label: "Sessions",
|
|
32874
|
+
description: "Create, list, connect and close product sessions through the SDK."
|
|
32875
|
+
})], _environmentAccess_dec = [Interface({
|
|
32876
|
+
label: "Environment access",
|
|
32877
|
+
description: "Resolve a user\u2019s assigned environment or open a connection to it."
|
|
32878
|
+
})], _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)];
|
|
32879
|
+
var _Granular = class _Granular {
|
|
32403
32880
|
/**
|
|
32404
32881
|
* Create a new Granular client
|
|
32405
32882
|
* @param options - Client configuration
|
|
32406
32883
|
*/
|
|
32407
32884
|
constructor(options) {
|
|
32885
|
+
__runInitializers(_init4, 5, this);
|
|
32886
|
+
/** Tenant events feed, authenticated with this client's credentials. */
|
|
32887
|
+
__publicField(this, "eventsFeed", new EventsFeed(
|
|
32888
|
+
(path10, options) => this.request(path10, options)
|
|
32889
|
+
));
|
|
32890
|
+
__publicField(this, "apiKey");
|
|
32891
|
+
__publicField(this, "apiUrl");
|
|
32892
|
+
__publicField(this, "httpUrl");
|
|
32893
|
+
__publicField(this, "tokenProvider");
|
|
32894
|
+
__publicField(this, "WebSocketCtor");
|
|
32895
|
+
__publicField(this, "onUnexpectedClose");
|
|
32896
|
+
__publicField(this, "onReconnectError");
|
|
32897
|
+
__publicField(this, "effectHostUrl");
|
|
32898
|
+
__publicField(this, "graphqlIdempotencyKey");
|
|
32899
|
+
__publicField(this, "debugHttp", process.env.GRANULAR_DEBUG_HTTP === "1");
|
|
32900
|
+
/** Sandbox-level effect registry: sandboxId → (effectKey@selector → ToolWithHandler) */
|
|
32901
|
+
__publicField(this, "sandboxEffects", /* @__PURE__ */ new Map());
|
|
32902
|
+
/** Live sandbox-scoped effect hosts keyed by sandboxId */
|
|
32903
|
+
__publicField(this, "sandboxEffectHosts", /* @__PURE__ */ new Map());
|
|
32904
|
+
__publicField(this, "developmentProviders", /* @__PURE__ */ new Map());
|
|
32905
|
+
__publicField(this, "usersProviders", /* @__PURE__ */ new Map());
|
|
32906
|
+
/** In-flight host connection promises to avoid duplicate concurrent connects */
|
|
32907
|
+
__publicField(this, "sandboxEffectHostPromises", /* @__PURE__ */ new Map());
|
|
32908
|
+
__publicField(this, "effectHostGenerations", /* @__PURE__ */ new Map());
|
|
32909
|
+
__publicField(this, "effectHostRecovery", /* @__PURE__ */ new Map());
|
|
32910
|
+
/** Ontology-bound environment importer hooks keyed by the caller's ontology identifier. */
|
|
32911
|
+
__publicField(this, "ontologyImporters", /* @__PURE__ */ new Map());
|
|
32912
|
+
/** Resolved importer hooks keyed by sandboxId for fast lookups during openEnvironment(). */
|
|
32913
|
+
__publicField(this, "sandboxImporters", /* @__PURE__ */ new Map());
|
|
32408
32914
|
const auth = options.token ?? options.apiKey;
|
|
32409
32915
|
if (!auth) {
|
|
32410
32916
|
throw new Error(
|
|
@@ -32452,8 +32958,8 @@ var Granular = class _Granular {
|
|
|
32452
32958
|
sandboxId
|
|
32453
32959
|
);
|
|
32454
32960
|
if (!importer) throw new Error("No environment importer registered.");
|
|
32455
|
-
const
|
|
32456
|
-
await
|
|
32961
|
+
const host2 = await this.ensureSandboxEffectHost(sandboxId);
|
|
32962
|
+
await host2.wsClient.call("environment.importer.register", {});
|
|
32457
32963
|
}
|
|
32458
32964
|
clearEnvironmentImporter(ontologyNameOrId) {
|
|
32459
32965
|
this.ontologyImporters.delete(ontologyNameOrId);
|
|
@@ -32555,29 +33061,6 @@ var Granular = class _Granular {
|
|
|
32555
33061
|
"openEnvironment() requires either userId, granularId, or a user object returned by recordUser()."
|
|
32556
33062
|
);
|
|
32557
33063
|
}
|
|
32558
|
-
/**
|
|
32559
|
-
* Open or resolve an ontology environment for one user without opening a session.
|
|
32560
|
-
*
|
|
32561
|
-
* @example
|
|
32562
|
-
* ```typescript
|
|
32563
|
-
* const environment = await granular.openEnvironment({
|
|
32564
|
-
* ontology: 'my-ontology',
|
|
32565
|
-
* tag: 'dev',
|
|
32566
|
-
* userId: 'user_123',
|
|
32567
|
-
* permissions: ['agent'],
|
|
32568
|
-
* });
|
|
32569
|
-
*
|
|
32570
|
-
* await environment.data.record({
|
|
32571
|
-
* className: 'customer',
|
|
32572
|
-
* id: 'acme',
|
|
32573
|
-
* fields: { name: 'Acme' },
|
|
32574
|
-
* });
|
|
32575
|
-
*
|
|
32576
|
-
* const session = await environment.sessions.create();
|
|
32577
|
-
* const job = await session.submitJob(`return "hello";`);
|
|
32578
|
-
* console.log(await job.result);
|
|
32579
|
-
* ```
|
|
32580
|
-
*/
|
|
32581
33064
|
async openEnvironment(options) {
|
|
32582
33065
|
const resolved = await this.resolveOpenEnvironmentData(
|
|
32583
33066
|
options,
|
|
@@ -32587,11 +33070,6 @@ var Granular = class _Granular {
|
|
|
32587
33070
|
await this.maybeRunEnvironmentImporter(resolved, environment);
|
|
32588
33071
|
return environment;
|
|
32589
33072
|
}
|
|
32590
|
-
/**
|
|
32591
|
-
* Read the active environment selected by Granular for an already-recorded
|
|
32592
|
-
* external user. This is intentionally read-only: browser/login code must
|
|
32593
|
-
* not create subjects or environments as a side effect.
|
|
32594
|
-
*/
|
|
32595
33073
|
async getActiveEnvironmentForUser(options) {
|
|
32596
33074
|
const sandboxId = options.sandboxId.trim();
|
|
32597
33075
|
const tagName = options.tag.trim();
|
|
@@ -32637,13 +33115,6 @@ var Granular = class _Granular {
|
|
|
32637
33115
|
throw error2;
|
|
32638
33116
|
}
|
|
32639
33117
|
}
|
|
32640
|
-
/**
|
|
32641
|
-
* Resolve one exact environment only when Granular confirms that it belongs
|
|
32642
|
-
* to the given external user in the requested sandbox (and, optionally,
|
|
32643
|
-
* tag). This is deliberately read-only: callers use it to keep an already
|
|
32644
|
-
* opened delegated workspace stable while a newer active environment is
|
|
32645
|
-
* being prepared in the background.
|
|
32646
|
-
*/
|
|
32647
33118
|
async getEnvironmentForUser(options) {
|
|
32648
33119
|
const sandboxId = options.sandboxId.trim();
|
|
32649
33120
|
const userId = options.userId.trim();
|
|
@@ -32686,11 +33157,6 @@ var Granular = class _Granular {
|
|
|
32686
33157
|
}
|
|
32687
33158
|
return this.bindEnvironmentHandle(environment);
|
|
32688
33159
|
}
|
|
32689
|
-
/**
|
|
32690
|
-
* Register one reviewed, pre-existing environment as the active workspace
|
|
32691
|
-
* for an external user. This is for a controlled migration only: it does
|
|
32692
|
-
* not create an environment and it does not run an importer.
|
|
32693
|
-
*/
|
|
32694
33160
|
async adoptEnvironmentForUser(options) {
|
|
32695
33161
|
const sandboxId = options.sandboxId.trim();
|
|
32696
33162
|
const tagName = options.tag.trim();
|
|
@@ -32737,11 +33203,6 @@ var Granular = class _Granular {
|
|
|
32737
33203
|
normalizeEnvironmentData(payload.environment)
|
|
32738
33204
|
);
|
|
32739
33205
|
}
|
|
32740
|
-
/**
|
|
32741
|
-
* Deprecated compatibility alias for `openEnvironment()`.
|
|
32742
|
-
*
|
|
32743
|
-
* `connect()` no longer opens a runtime session automatically.
|
|
32744
|
-
*/
|
|
32745
33206
|
async connect(options) {
|
|
32746
33207
|
return this.openEnvironment({
|
|
32747
33208
|
...options,
|
|
@@ -33045,9 +33506,6 @@ var Granular = class _Granular {
|
|
|
33045
33506
|
setupOperationKey: resetKey
|
|
33046
33507
|
};
|
|
33047
33508
|
}
|
|
33048
|
-
/**
|
|
33049
|
-
* List indexed sessions using ownership filters and bounded pagination.
|
|
33050
|
-
*/
|
|
33051
33509
|
async listSessions(options) {
|
|
33052
33510
|
const items = [];
|
|
33053
33511
|
let cursor = options.cursor?.trim() || void 0;
|
|
@@ -33244,10 +33702,6 @@ var Granular = class _Granular {
|
|
|
33244
33702
|
}
|
|
33245
33703
|
return (/* @__PURE__ */ new Date(0)).toISOString();
|
|
33246
33704
|
}
|
|
33247
|
-
/**
|
|
33248
|
-
* Create a new session (conversation) for an existing environment and connect to it.
|
|
33249
|
-
* The runtime graph is shared across all sessions for the same environment.
|
|
33250
|
-
*/
|
|
33251
33705
|
async createSession(options) {
|
|
33252
33706
|
const clientId = options.clientId || `client_${Date.now()}`;
|
|
33253
33707
|
const sessionScope = options.sessionScope?.trim() || void 0;
|
|
@@ -33268,9 +33722,6 @@ var Granular = class _Granular {
|
|
|
33268
33722
|
});
|
|
33269
33723
|
return this.bindWebSocketEnvironmentSession(environment, clientId, session2);
|
|
33270
33724
|
}
|
|
33271
|
-
/**
|
|
33272
|
-
* Connect to an existing open session (same conversation thread) using a freshly minted WebSocket token.
|
|
33273
|
-
*/
|
|
33274
33725
|
async connectSession(options) {
|
|
33275
33726
|
const clientId = options.clientId || `client_${Date.now()}`;
|
|
33276
33727
|
const minted = await this.request(`/ws/sessions/${encodeURIComponent(options.sessionId)}/token`, {
|
|
@@ -33297,7 +33748,6 @@ var Granular = class _Granular {
|
|
|
33297
33748
|
metadata: options?.metadata
|
|
33298
33749
|
});
|
|
33299
33750
|
}
|
|
33300
|
-
/** End a session through the runtime, or disconnect its connected handle. */
|
|
33301
33751
|
async closeSession(sessionId, environment) {
|
|
33302
33752
|
if (environment && environment.sessionId === sessionId) {
|
|
33303
33753
|
await environment.disconnect();
|
|
@@ -33308,9 +33758,6 @@ var Granular = class _Granular {
|
|
|
33308
33758
|
{ method: "POST" }
|
|
33309
33759
|
);
|
|
33310
33760
|
}
|
|
33311
|
-
/**
|
|
33312
|
-
* Re-open a closed session in the index and connect to its existing runtime document.
|
|
33313
|
-
*/
|
|
33314
33761
|
async reopenSession(sessionId, options) {
|
|
33315
33762
|
await this.request(`/control/sessions/${encodeURIComponent(sessionId)}`, {
|
|
33316
33763
|
method: "PATCH",
|
|
@@ -33551,25 +33998,25 @@ var Granular = class _Granular {
|
|
|
33551
33998
|
}
|
|
33552
33999
|
return serialized;
|
|
33553
34000
|
}
|
|
33554
|
-
async publishSandboxEffectCatalog(
|
|
34001
|
+
async publishSandboxEffectCatalog(host2) {
|
|
33555
34002
|
const effects2 = Array.from(
|
|
33556
|
-
this.getSandboxEffectMap(
|
|
34003
|
+
this.getSandboxEffectMap(host2.sandboxId).values()
|
|
33557
34004
|
).map((effect) => this.serializeEffect(effect));
|
|
33558
34005
|
let acceptedCount = 0;
|
|
33559
34006
|
const rejected = [];
|
|
33560
34007
|
try {
|
|
33561
34008
|
await withTimeout(
|
|
33562
|
-
|
|
34009
|
+
host2.wsClient.call("effects.resetCatalog", {}),
|
|
33563
34010
|
EFFECT_CATALOG_SYNC_TIMEOUT_MS,
|
|
33564
|
-
`effects.resetCatalog for sandbox ${
|
|
34011
|
+
`effects.resetCatalog for sandbox ${host2.sandboxId}`
|
|
33565
34012
|
);
|
|
33566
34013
|
for (const batch of chunkItems(effects2, EFFECT_CATALOG_SYNC_BATCH_SIZE)) {
|
|
33567
34014
|
const result = await withTimeout(
|
|
33568
|
-
|
|
34015
|
+
host2.wsClient.call("effects.addCatalog", {
|
|
33569
34016
|
effects: batch
|
|
33570
34017
|
}),
|
|
33571
34018
|
EFFECT_CATALOG_SYNC_TIMEOUT_MS,
|
|
33572
|
-
`effects.addCatalog for sandbox ${
|
|
34019
|
+
`effects.addCatalog for sandbox ${host2.sandboxId}`
|
|
33573
34020
|
);
|
|
33574
34021
|
acceptedCount += typeof result?.acceptedCount === "number" ? result.acceptedCount : 0;
|
|
33575
34022
|
if (Array.isArray(result?.rejected)) {
|
|
@@ -33581,11 +34028,11 @@ var Granular = class _Granular {
|
|
|
33581
34028
|
throw error2;
|
|
33582
34029
|
}
|
|
33583
34030
|
const result = await withTimeout(
|
|
33584
|
-
|
|
34031
|
+
host2.wsClient.call("effects.publishCatalog", {
|
|
33585
34032
|
effects: effects2
|
|
33586
34033
|
}),
|
|
33587
34034
|
EFFECT_CATALOG_SYNC_TIMEOUT_MS,
|
|
33588
|
-
`effects.publishCatalog for sandbox ${
|
|
34035
|
+
`effects.publishCatalog for sandbox ${host2.sandboxId}`
|
|
33589
34036
|
);
|
|
33590
34037
|
acceptedCount = typeof result?.acceptedCount === "number" ? result.acceptedCount : 0;
|
|
33591
34038
|
if (Array.isArray(result?.rejected)) {
|
|
@@ -33597,12 +34044,12 @@ var Granular = class _Granular {
|
|
|
33597
34044
|
(entry) => `${entry.name || "unknown"}: ${entry.reason || "rejected"}`
|
|
33598
34045
|
).join("; ");
|
|
33599
34046
|
throw new Error(
|
|
33600
|
-
`Failed to publish live effects for sandbox ${
|
|
34047
|
+
`Failed to publish live effects for sandbox ${host2.sandboxId}: ${detail}`
|
|
33601
34048
|
);
|
|
33602
34049
|
}
|
|
33603
34050
|
if (rejected.length > 0) {
|
|
33604
34051
|
console.warn(
|
|
33605
|
-
`[Granular] Some live effects were rejected for sandbox ${
|
|
34052
|
+
`[Granular] Some live effects were rejected for sandbox ${host2.sandboxId}:`,
|
|
33606
34053
|
rejected
|
|
33607
34054
|
);
|
|
33608
34055
|
}
|
|
@@ -33611,8 +34058,8 @@ var Granular = class _Granular {
|
|
|
33611
34058
|
let lastError;
|
|
33612
34059
|
for (let attempt = 1; attempt <= EFFECT_CATALOG_SYNC_RETRY_COUNT; attempt += 1) {
|
|
33613
34060
|
try {
|
|
33614
|
-
const
|
|
33615
|
-
await this.publishSandboxEffectCatalog(
|
|
34061
|
+
const host2 = await this.ensureSandboxEffectHost(sandboxId);
|
|
34062
|
+
await this.publishSandboxEffectCatalog(host2);
|
|
33616
34063
|
return;
|
|
33617
34064
|
} catch (error2) {
|
|
33618
34065
|
lastError = error2;
|
|
@@ -33629,11 +34076,11 @@ var Granular = class _Granular {
|
|
|
33629
34076
|
}
|
|
33630
34077
|
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
33631
34078
|
}
|
|
33632
|
-
recoverEffectHost(
|
|
33633
|
-
const sandboxId =
|
|
33634
|
-
if (
|
|
34079
|
+
recoverEffectHost(host2, error2) {
|
|
34080
|
+
const sandboxId = host2.sandboxId;
|
|
34081
|
+
if (host2.recovering || this.sandboxEffectHosts.get(sandboxId) !== host2)
|
|
33635
34082
|
return;
|
|
33636
|
-
|
|
34083
|
+
host2.recovering = true;
|
|
33637
34084
|
this.disconnectSandboxEffectHost(sandboxId);
|
|
33638
34085
|
const state = {
|
|
33639
34086
|
attempt: 0,
|
|
@@ -33656,7 +34103,7 @@ var Granular = class _Granular {
|
|
|
33656
34103
|
);
|
|
33657
34104
|
try {
|
|
33658
34105
|
this.onReconnectError?.({
|
|
33659
|
-
sessionId: `effect-host:${
|
|
34106
|
+
sessionId: `effect-host:${host2.effectClientId}`,
|
|
33660
34107
|
error: reconnectError instanceof Error ? reconnectError.message : String(reconnectError),
|
|
33661
34108
|
timestamp: Date.now(),
|
|
33662
34109
|
terminal: !retryable
|
|
@@ -33709,13 +34156,13 @@ var Granular = class _Granular {
|
|
|
33709
34156
|
)
|
|
33710
34157
|
};
|
|
33711
34158
|
}
|
|
33712
|
-
async recoverSourceCommits(
|
|
34159
|
+
async recoverSourceCommits(host2) {
|
|
33713
34160
|
const stores = new Set(
|
|
33714
|
-
Array.from(this.getSandboxEffectMap(
|
|
34161
|
+
Array.from(this.getSandboxEffectMap(host2.sandboxId).values()).map((effect) => effect.commit?.storage).filter(Boolean)
|
|
33715
34162
|
);
|
|
33716
34163
|
for (const store of stores) {
|
|
33717
34164
|
try {
|
|
33718
|
-
await store.recover(this.effectCommitTransport(),
|
|
34165
|
+
await store.recover(this.effectCommitTransport(), host2.sandboxId);
|
|
33719
34166
|
} catch (error2) {
|
|
33720
34167
|
console.warn(
|
|
33721
34168
|
"[Granular] Source commit delivery remains pending:",
|
|
@@ -33724,43 +34171,43 @@ var Granular = class _Granular {
|
|
|
33724
34171
|
}
|
|
33725
34172
|
}
|
|
33726
34173
|
}
|
|
33727
|
-
startEffectHostHeartbeat(
|
|
33728
|
-
if (
|
|
33729
|
-
clearInterval(
|
|
34174
|
+
startEffectHostHeartbeat(host2) {
|
|
34175
|
+
if (host2.heartbeatTimer) {
|
|
34176
|
+
clearInterval(host2.heartbeatTimer);
|
|
33730
34177
|
}
|
|
33731
|
-
|
|
34178
|
+
host2.heartbeatInFlight = false;
|
|
33732
34179
|
const sendHeartbeat = (failureLabel, recoverOnFailure) => {
|
|
33733
|
-
if (
|
|
34180
|
+
if (host2.heartbeatInFlight || host2.recovering) {
|
|
33734
34181
|
return;
|
|
33735
34182
|
}
|
|
33736
|
-
|
|
33737
|
-
|
|
33738
|
-
console.warn(`${failureLabel} ${
|
|
34183
|
+
host2.heartbeatInFlight = true;
|
|
34184
|
+
host2.wsClient.call("client.heartbeat", {}).then(() => this.recoverSourceCommits(host2)).catch((error2) => {
|
|
34185
|
+
console.warn(`${failureLabel} ${host2.sandboxId}:`, error2);
|
|
33739
34186
|
if (recoverOnFailure) {
|
|
33740
|
-
this.recoverEffectHost(
|
|
34187
|
+
this.recoverEffectHost(host2, error2);
|
|
33741
34188
|
}
|
|
33742
34189
|
}).finally(() => {
|
|
33743
|
-
|
|
34190
|
+
host2.heartbeatInFlight = false;
|
|
33744
34191
|
});
|
|
33745
34192
|
};
|
|
33746
34193
|
sendHeartbeat(
|
|
33747
34194
|
"[Granular] Initial effect host heartbeat failed for sandbox",
|
|
33748
34195
|
false
|
|
33749
34196
|
);
|
|
33750
|
-
|
|
34197
|
+
host2.heartbeatTimer = setInterval(() => {
|
|
33751
34198
|
sendHeartbeat(
|
|
33752
34199
|
"[Granular] Effect host heartbeat failed for sandbox",
|
|
33753
34200
|
true
|
|
33754
34201
|
);
|
|
33755
34202
|
}, 1e4);
|
|
33756
34203
|
}
|
|
33757
|
-
stopEffectHostHeartbeat(
|
|
33758
|
-
if (!
|
|
34204
|
+
stopEffectHostHeartbeat(host2) {
|
|
34205
|
+
if (!host2?.heartbeatTimer) {
|
|
33759
34206
|
return;
|
|
33760
34207
|
}
|
|
33761
|
-
clearInterval(
|
|
33762
|
-
|
|
33763
|
-
|
|
34208
|
+
clearInterval(host2.heartbeatTimer);
|
|
34209
|
+
host2.heartbeatTimer = null;
|
|
34210
|
+
host2.heartbeatInFlight = false;
|
|
33764
34211
|
}
|
|
33765
34212
|
async registerUsers(ontologyNameOrId, handler, options) {
|
|
33766
34213
|
const provider = new UsersProvider(handler, options);
|
|
@@ -33768,8 +34215,8 @@ var Granular = class _Granular {
|
|
|
33768
34215
|
const previous = this.usersProviders.get(sandboxId);
|
|
33769
34216
|
this.usersProviders.set(sandboxId, provider);
|
|
33770
34217
|
try {
|
|
33771
|
-
const
|
|
33772
|
-
if (provider.registration?.providerId !==
|
|
34218
|
+
const host2 = await this.ensureSandboxEffectHost(sandboxId);
|
|
34219
|
+
if (provider.registration?.providerId !== host2.effectClientId) await this.registerUsersOnHost(host2, provider);
|
|
33773
34220
|
if (!provider.registration) throw new Error("User directory registration is no longer live.");
|
|
33774
34221
|
return provider.registration;
|
|
33775
34222
|
} catch (error2) {
|
|
@@ -33780,10 +34227,10 @@ var Granular = class _Granular {
|
|
|
33780
34227
|
throw error2;
|
|
33781
34228
|
}
|
|
33782
34229
|
}
|
|
33783
|
-
async registerUsersOnHost(
|
|
33784
|
-
const registration = await
|
|
33785
|
-
if (this.usersProviders.get(
|
|
33786
|
-
provider.bind(registration,
|
|
34230
|
+
async registerUsersOnHost(host2, provider) {
|
|
34231
|
+
const registration = await host2.wsClient.call("users.register", {});
|
|
34232
|
+
if (this.usersProviders.get(host2.sandboxId) !== provider) throw new Error("User directory registration was replaced.");
|
|
34233
|
+
provider.bind(registration, host2.sandboxId, host2.effectClientId);
|
|
33787
34234
|
}
|
|
33788
34235
|
/** Publish only public setup metadata; product session authority stays in resolveLaunch. */
|
|
33789
34236
|
async registerCustomerSkill(ontologyNameOrId, options) {
|
|
@@ -33835,10 +34282,10 @@ var Granular = class _Granular {
|
|
|
33835
34282
|
const previous = this.developmentProviders.get(sandboxId);
|
|
33836
34283
|
this.developmentProviders.set(sandboxId, provider);
|
|
33837
34284
|
try {
|
|
33838
|
-
const
|
|
34285
|
+
const host2 = await this.ensureSandboxEffectHost(sandboxId);
|
|
33839
34286
|
if (this.developmentProviders.get(sandboxId) !== provider) throw new Error("Development registration was replaced.");
|
|
33840
|
-
if (provider.registration?.providerId !==
|
|
33841
|
-
await this.registerDevelopmentOnHost(
|
|
34287
|
+
if (provider.registration?.providerId !== host2.effectClientId) {
|
|
34288
|
+
await this.registerDevelopmentOnHost(host2, provider);
|
|
33842
34289
|
}
|
|
33843
34290
|
if (!provider.registration) throw new Error("Development provider registration is no longer live.");
|
|
33844
34291
|
return provider.registration;
|
|
@@ -33850,38 +34297,38 @@ var Granular = class _Granular {
|
|
|
33850
34297
|
throw error2;
|
|
33851
34298
|
}
|
|
33852
34299
|
}
|
|
33853
|
-
async registerDevelopmentOnHost(
|
|
33854
|
-
const registration = await
|
|
34300
|
+
async registerDevelopmentOnHost(host2, provider) {
|
|
34301
|
+
const registration = await host2.wsClient.call(
|
|
33855
34302
|
"onboarding.register",
|
|
33856
34303
|
provider.registrationParams()
|
|
33857
34304
|
);
|
|
33858
|
-
if (this.developmentProviders.get(
|
|
34305
|
+
if (this.developmentProviders.get(host2.sandboxId) !== provider)
|
|
33859
34306
|
throw new Error("Development registration was replaced.");
|
|
33860
|
-
provider.bind(registration,
|
|
34307
|
+
provider.bind(registration, host2.sandboxId, host2.effectClientId);
|
|
33861
34308
|
}
|
|
33862
|
-
async synchronizeEffectHost(
|
|
33863
|
-
if (
|
|
33864
|
-
return
|
|
34309
|
+
async synchronizeEffectHost(host2) {
|
|
34310
|
+
if (host2.syncPromise) {
|
|
34311
|
+
return host2.syncPromise;
|
|
33865
34312
|
}
|
|
33866
|
-
|
|
33867
|
-
await
|
|
33868
|
-
clientId:
|
|
34313
|
+
host2.syncPromise = (async () => {
|
|
34314
|
+
await host2.wsClient.call("client.hello", {
|
|
34315
|
+
clientId: host2.clientId,
|
|
33869
34316
|
protocolVersion: "2.0"
|
|
33870
34317
|
});
|
|
33871
|
-
await this.publishSandboxEffectCatalog(
|
|
33872
|
-
if (this.resolveEnvironmentImporter(
|
|
33873
|
-
await
|
|
33874
|
-
const users2 = this.usersProviders.get(
|
|
33875
|
-
if (users2) await this.registerUsersOnHost(
|
|
33876
|
-
const development = this.developmentProviders.get(
|
|
33877
|
-
if (development) await this.registerDevelopmentOnHost(
|
|
33878
|
-
this.startEffectHostHeartbeat(
|
|
34318
|
+
await this.publishSandboxEffectCatalog(host2);
|
|
34319
|
+
if (this.resolveEnvironmentImporter(host2.sandboxId, host2.sandboxId))
|
|
34320
|
+
await host2.wsClient.call("environment.importer.register", {});
|
|
34321
|
+
const users2 = this.usersProviders.get(host2.sandboxId);
|
|
34322
|
+
if (users2) await this.registerUsersOnHost(host2, users2);
|
|
34323
|
+
const development = this.developmentProviders.get(host2.sandboxId);
|
|
34324
|
+
if (development) await this.registerDevelopmentOnHost(host2, development);
|
|
34325
|
+
this.startEffectHostHeartbeat(host2);
|
|
33879
34326
|
})();
|
|
33880
34327
|
try {
|
|
33881
|
-
await
|
|
34328
|
+
await host2.syncPromise;
|
|
33882
34329
|
} finally {
|
|
33883
|
-
if (
|
|
33884
|
-
|
|
34330
|
+
if (host2.syncPromise) {
|
|
34331
|
+
host2.syncPromise = null;
|
|
33885
34332
|
}
|
|
33886
34333
|
}
|
|
33887
34334
|
}
|
|
@@ -33911,7 +34358,7 @@ var Granular = class _Granular {
|
|
|
33911
34358
|
onUnexpectedClose: this.onUnexpectedClose,
|
|
33912
34359
|
onReconnectError: this.onReconnectError
|
|
33913
34360
|
});
|
|
33914
|
-
const
|
|
34361
|
+
const host2 = {
|
|
33915
34362
|
generation: generation2,
|
|
33916
34363
|
sandboxId,
|
|
33917
34364
|
effectClientId,
|
|
@@ -33998,20 +34445,20 @@ var Granular = class _Granular {
|
|
|
33998
34445
|
};
|
|
33999
34446
|
});
|
|
34000
34447
|
wsClient.on("open", () => {
|
|
34001
|
-
void this.synchronizeEffectHost(
|
|
34448
|
+
void this.synchronizeEffectHost(host2).catch((error2) => {
|
|
34002
34449
|
console.error(
|
|
34003
34450
|
`[Granular] Failed to re-sync effect host for sandbox ${sandboxId}:`,
|
|
34004
34451
|
error2
|
|
34005
34452
|
);
|
|
34006
|
-
this.recoverEffectHost(
|
|
34453
|
+
this.recoverEffectHost(host2, error2);
|
|
34007
34454
|
});
|
|
34008
34455
|
});
|
|
34009
34456
|
wsClient.on("disconnect", () => {
|
|
34010
|
-
this.stopEffectHostHeartbeat(
|
|
34457
|
+
this.stopEffectHostHeartbeat(host2);
|
|
34011
34458
|
const users2 = this.usersProviders.get(sandboxId);
|
|
34012
|
-
if (users2?.registration?.providerId ===
|
|
34459
|
+
if (users2?.registration?.providerId === host2.effectClientId) users2.unbind();
|
|
34013
34460
|
const provider = this.developmentProviders.get(sandboxId);
|
|
34014
|
-
if (provider?.registration?.providerId ===
|
|
34461
|
+
if (provider?.registration?.providerId === host2.effectClientId) provider.unbind();
|
|
34015
34462
|
});
|
|
34016
34463
|
try {
|
|
34017
34464
|
await withTimeout(
|
|
@@ -34019,13 +34466,13 @@ var Granular = class _Granular {
|
|
|
34019
34466
|
EFFECT_HOST_CONNECT_TIMEOUT_MS,
|
|
34020
34467
|
`effect host WebSocket connect for sandbox ${sandboxId}`
|
|
34021
34468
|
);
|
|
34022
|
-
await this.synchronizeEffectHost(
|
|
34469
|
+
await this.synchronizeEffectHost(host2);
|
|
34023
34470
|
if ((this.effectHostGenerations.get(sandboxId) || 0) !== generation2)
|
|
34024
34471
|
throw new Error("Effect host connection was canceled");
|
|
34025
|
-
this.sandboxEffectHosts.set(sandboxId,
|
|
34026
|
-
return
|
|
34472
|
+
this.sandboxEffectHosts.set(sandboxId, host2);
|
|
34473
|
+
return host2;
|
|
34027
34474
|
} catch (error2) {
|
|
34028
|
-
this.stopEffectHostHeartbeat(
|
|
34475
|
+
this.stopEffectHostHeartbeat(host2);
|
|
34029
34476
|
wsClient.disconnect({ reason: "Effect host initialization failed" });
|
|
34030
34477
|
throw error2;
|
|
34031
34478
|
}
|
|
@@ -34049,20 +34496,14 @@ var Granular = class _Granular {
|
|
|
34049
34496
|
const recovering = this.effectHostRecovery.get(sandboxId);
|
|
34050
34497
|
if (recovering?.timer) clearTimeout(recovering.timer);
|
|
34051
34498
|
this.effectHostRecovery.delete(sandboxId);
|
|
34052
|
-
const
|
|
34053
|
-
if (!
|
|
34499
|
+
const host2 = this.sandboxEffectHosts.get(sandboxId);
|
|
34500
|
+
if (!host2) {
|
|
34054
34501
|
return;
|
|
34055
34502
|
}
|
|
34056
34503
|
this.sandboxEffectHosts.delete(sandboxId);
|
|
34057
|
-
this.stopEffectHostHeartbeat(
|
|
34058
|
-
|
|
34504
|
+
this.stopEffectHostHeartbeat(host2);
|
|
34505
|
+
host2.wsClient.disconnect();
|
|
34059
34506
|
}
|
|
34060
|
-
/**
|
|
34061
|
-
* Register an effect (tool) for a specific sandbox.
|
|
34062
|
-
*
|
|
34063
|
-
* @param sandboxNameOrId - The name or ID of the sandbox
|
|
34064
|
-
* @param effect - The tool definition and handler
|
|
34065
|
-
*/
|
|
34066
34507
|
async registerEffect(sandboxNameOrId, effect) {
|
|
34067
34508
|
const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
|
|
34068
34509
|
const sandboxId = sandbox.sandboxId;
|
|
@@ -34072,11 +34513,6 @@ var Granular = class _Granular {
|
|
|
34072
34513
|
);
|
|
34073
34514
|
await this.syncSandboxEffectCatalog(sandboxId);
|
|
34074
34515
|
}
|
|
34075
|
-
/**
|
|
34076
|
-
* Register multiple effects (tools) for a specific sandbox.
|
|
34077
|
-
*
|
|
34078
|
-
* batch version of `registerEffect`.
|
|
34079
|
-
*/
|
|
34080
34516
|
async registerEffects(sandboxNameOrId, effects2) {
|
|
34081
34517
|
const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
|
|
34082
34518
|
const sandboxId = sandbox.sandboxId;
|
|
@@ -34086,12 +34522,6 @@ var Granular = class _Granular {
|
|
|
34086
34522
|
}
|
|
34087
34523
|
await this.syncSandboxEffectCatalog(sandboxId);
|
|
34088
34524
|
}
|
|
34089
|
-
/**
|
|
34090
|
-
* Unregister an effect from a sandbox.
|
|
34091
|
-
*
|
|
34092
|
-
* Removes it from the local sandbox registry and updates the
|
|
34093
|
-
* sandbox-scoped live catalog.
|
|
34094
|
-
*/
|
|
34095
34525
|
async unregisterEffect(sandboxNameOrId, name) {
|
|
34096
34526
|
const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
|
|
34097
34527
|
const sandboxId = sandbox.sandboxId;
|
|
@@ -34114,12 +34544,6 @@ var Granular = class _Granular {
|
|
|
34114
34544
|
}
|
|
34115
34545
|
await this.syncSandboxEffectCatalog(sandboxId);
|
|
34116
34546
|
}
|
|
34117
|
-
/**
|
|
34118
|
-
* Disconnect one sandbox-scoped effect host, or all of them when no sandbox is provided.
|
|
34119
|
-
*
|
|
34120
|
-
* This is primarily useful for long-lived helper processes such as generated
|
|
34121
|
-
* `granular-effects.ts` scripts that need to shut down cleanly on SIGINT/SIGTERM.
|
|
34122
|
-
*/
|
|
34123
34547
|
async disconnectEffects(sandboxNameOrId) {
|
|
34124
34548
|
if (sandboxNameOrId) {
|
|
34125
34549
|
const sandbox = await this.findOrCreateSandbox(sandboxNameOrId);
|
|
@@ -34544,9 +34968,6 @@ var Granular = class _Granular {
|
|
|
34544
34968
|
throw new Error(`Ontology not found: ${ontologyNameOrId}`);
|
|
34545
34969
|
return result.items[0].sandboxId;
|
|
34546
34970
|
}
|
|
34547
|
-
/**
|
|
34548
|
-
* Make an authenticated API request
|
|
34549
|
-
*/
|
|
34550
34971
|
async request(path10, options = {}) {
|
|
34551
34972
|
const url = `${this.httpUrl}${path10}`;
|
|
34552
34973
|
if (this.debugHttp) {
|
|
@@ -34596,6 +35017,33 @@ var Granular = class _Granular {
|
|
|
34596
35017
|
throw new Error(`Granular API Error: exhausted retries for ${url}`);
|
|
34597
35018
|
}
|
|
34598
35019
|
};
|
|
35020
|
+
_init4 = __decoratorStart(null);
|
|
35021
|
+
__decorateElement(_init4, 1, "openEnvironment", _openEnvironment_dec, _Granular);
|
|
35022
|
+
__decorateElement(_init4, 1, "getActiveEnvironmentForUser", _getActiveEnvironmentForUser_dec, _Granular);
|
|
35023
|
+
__decorateElement(_init4, 1, "getEnvironmentForUser", _getEnvironmentForUser_dec, _Granular);
|
|
35024
|
+
__decorateElement(_init4, 1, "adoptEnvironmentForUser", _adoptEnvironmentForUser_dec, _Granular);
|
|
35025
|
+
__decorateElement(_init4, 1, "connect", _connect_dec, _Granular);
|
|
35026
|
+
__decorateElement(_init4, 1, "listSessions", _listSessions_dec2, _Granular);
|
|
35027
|
+
__decorateElement(_init4, 1, "createSession", _createSession_dec2, _Granular);
|
|
35028
|
+
__decorateElement(_init4, 1, "connectSession", _connectSession_dec2, _Granular);
|
|
35029
|
+
__decorateElement(_init4, 1, "closeSession", _closeSession_dec2, _Granular);
|
|
35030
|
+
__decorateElement(_init4, 1, "reopenSession", _reopenSession_dec, _Granular);
|
|
35031
|
+
__decorateElement(_init4, 1, "registerEffect", _registerEffect_dec, _Granular);
|
|
35032
|
+
__decorateElement(_init4, 1, "registerEffects", _registerEffects_dec, _Granular);
|
|
35033
|
+
__decorateElement(_init4, 1, "unregisterEffect", _unregisterEffect_dec, _Granular);
|
|
35034
|
+
__decorateElement(_init4, 1, "disconnectEffects", _disconnectEffects_dec, _Granular);
|
|
35035
|
+
__decorateElement(_init4, 1, "request", _request_dec, _Granular);
|
|
35036
|
+
__decorateElement(_init4, 13, "transport", _transport_dec, _Granular);
|
|
35037
|
+
__decorateElement(_init4, 13, "effectHosts", _effectHosts_dec, _Granular);
|
|
35038
|
+
__decorateElement(_init4, 13, "sessions", _sessions_dec2, _Granular);
|
|
35039
|
+
__decorateElement(_init4, 13, "environmentAccess", _environmentAccess_dec, _Granular);
|
|
35040
|
+
_Granular = __decorateElement(_init4, 0, "Granular", _Granular_decorators, _Granular);
|
|
35041
|
+
__publicField(_Granular, "transport", __runInitializers(_init4, 8, _Granular)), __runInitializers(_init4, 11, _Granular);
|
|
35042
|
+
__publicField(_Granular, "effectHosts", __runInitializers(_init4, 12, _Granular)), __runInitializers(_init4, 15, _Granular);
|
|
35043
|
+
__publicField(_Granular, "sessions", __runInitializers(_init4, 16, _Granular)), __runInitializers(_init4, 19, _Granular);
|
|
35044
|
+
__publicField(_Granular, "environmentAccess", __runInitializers(_init4, 20, _Granular)), __runInitializers(_init4, 23, _Granular);
|
|
35045
|
+
__runInitializers(_init4, 1, _Granular);
|
|
35046
|
+
var Granular = _Granular;
|
|
34599
35047
|
|
|
34600
35048
|
// src/agent-harness-templates/action-presentation/0.1.0/manifest.json
|
|
34601
35049
|
var manifest_default = {
|
|
@@ -35248,6 +35696,11 @@ async function connectTestCommand(options) {
|
|
|
35248
35696
|
}
|
|
35249
35697
|
|
|
35250
35698
|
// src/cli/commands/session.ts
|
|
35699
|
+
init_annotations();
|
|
35700
|
+
var sessionJobTools = Interface(
|
|
35701
|
+
"granular-product/authoring/cli-local-development/session-job-tools",
|
|
35702
|
+
{ label: "Sessions & jobs", tests: ["./session.test.ts"] }
|
|
35703
|
+
);
|
|
35251
35704
|
function parseSessionListInteger(value, name) {
|
|
35252
35705
|
const fallback2 = 25;
|
|
35253
35706
|
const minimum = 1;
|
|
@@ -35270,7 +35723,10 @@ function printValue(value, emitJson) {
|
|
|
35270
35723
|
console.log();
|
|
35271
35724
|
}
|
|
35272
35725
|
}
|
|
35273
|
-
|
|
35726
|
+
var sessionHeapCommand = Method(() => sessionJobTools, {
|
|
35727
|
+
label: "Inspect session data",
|
|
35728
|
+
description: "Inspect the records selected into the conversation context."
|
|
35729
|
+
})(async function sessionHeapCommand2(options) {
|
|
35274
35730
|
const emitJson = options.json === true;
|
|
35275
35731
|
if (!emitJson) {
|
|
35276
35732
|
printHeader();
|
|
@@ -35297,8 +35753,11 @@ async function sessionHeapCommand(options) {
|
|
|
35297
35753
|
printValue(payload, emitJson);
|
|
35298
35754
|
}
|
|
35299
35755
|
);
|
|
35300
|
-
}
|
|
35301
|
-
|
|
35756
|
+
});
|
|
35757
|
+
var sessionDocCommand = Method(() => sessionJobTools, {
|
|
35758
|
+
label: "Read session document",
|
|
35759
|
+
description: "Read the selected conversation document."
|
|
35760
|
+
})(async function sessionDocCommand2(options) {
|
|
35302
35761
|
const emitJson = options.json === true;
|
|
35303
35762
|
if (!emitJson) {
|
|
35304
35763
|
printHeader();
|
|
@@ -35327,8 +35786,11 @@ async function sessionDocCommand(options) {
|
|
|
35327
35786
|
printValue(payload, emitJson);
|
|
35328
35787
|
}
|
|
35329
35788
|
);
|
|
35330
|
-
}
|
|
35331
|
-
|
|
35789
|
+
});
|
|
35790
|
+
var sessionCreateCommand = Method(() => sessionJobTools, {
|
|
35791
|
+
label: "Create session",
|
|
35792
|
+
description: "Create a conversation in the selected product environment."
|
|
35793
|
+
})(async function sessionCreateCommand2(options) {
|
|
35332
35794
|
const emitJson = options.json === true;
|
|
35333
35795
|
const requestedEnvironment = options.environment ?? "dev";
|
|
35334
35796
|
if (!emitJson) {
|
|
@@ -35382,8 +35844,11 @@ async function sessionCreateCommand(options) {
|
|
|
35382
35844
|
environment?.client?.disconnect?.();
|
|
35383
35845
|
}
|
|
35384
35846
|
}
|
|
35385
|
-
}
|
|
35386
|
-
|
|
35847
|
+
});
|
|
35848
|
+
var sessionListCommand = Method(() => sessionJobTools, {
|
|
35849
|
+
label: "List sessions",
|
|
35850
|
+
description: "List conversations in the selected access scope."
|
|
35851
|
+
})(async function sessionListCommand2(options) {
|
|
35387
35852
|
const emitJson = options.json === true;
|
|
35388
35853
|
const status = options.status ?? "active";
|
|
35389
35854
|
const allowedStatuses = /* @__PURE__ */ new Set([
|
|
@@ -35464,7 +35929,117 @@ async function sessionListCommand(options) {
|
|
|
35464
35929
|
`Showing ${items.length} session${items.length === 1 ? "" : "s"}.` + (page.nextCursor ? ` Use --cursor ${page.nextCursor} for the next page.` : "")
|
|
35465
35930
|
);
|
|
35466
35931
|
console.log();
|
|
35932
|
+
});
|
|
35933
|
+
|
|
35934
|
+
// src/cli/commands/graphql.ts
|
|
35935
|
+
init_annotations();
|
|
35936
|
+
|
|
35937
|
+
// src/cli/commands/permissions.ts
|
|
35938
|
+
init_src();
|
|
35939
|
+
init_annotations();
|
|
35940
|
+
var queryPermissions = Interface(
|
|
35941
|
+
"granular-product/authoring/cli-local-development/query-permissions",
|
|
35942
|
+
{ label: "Queries & permissions", tests: [] }
|
|
35943
|
+
);
|
|
35944
|
+
function parseJsonObject(value) {
|
|
35945
|
+
if (!value) return {};
|
|
35946
|
+
const parsed = JSON.parse(value);
|
|
35947
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
35948
|
+
throw new Error("Expected a JSON object");
|
|
35949
|
+
}
|
|
35950
|
+
return parsed;
|
|
35467
35951
|
}
|
|
35952
|
+
function resolveEffectKey(manifest2, action, on) {
|
|
35953
|
+
const effects2 = extractManifestEffects(manifest2);
|
|
35954
|
+
const matches = effects2.filter((effect) => {
|
|
35955
|
+
if (effect.name !== action) return false;
|
|
35956
|
+
return on ? effect.attachedClass === on : !effect.attachedClass;
|
|
35957
|
+
});
|
|
35958
|
+
if (matches.length === 1) return matches[0].effectKey;
|
|
35959
|
+
if (matches.length === 0) {
|
|
35960
|
+
throw new Error(
|
|
35961
|
+
on ? `Action "${action}" on "${on}" was not found.` : `Global action "${action}" was not found.`
|
|
35962
|
+
);
|
|
35963
|
+
}
|
|
35964
|
+
throw new Error(`Action "${action}" is ambiguous. Add --on.`);
|
|
35965
|
+
}
|
|
35966
|
+
var permissionsValidateCommand = Method(() => queryPermissions, {
|
|
35967
|
+
label: "Validate permission profiles",
|
|
35968
|
+
description: "Validate the local permission profile definitions before publishing them."
|
|
35969
|
+
})(async function permissionsValidateCommand2() {
|
|
35970
|
+
const config = resolveConfig({ requireProject: true });
|
|
35971
|
+
const manifest2 = config.project.manifest;
|
|
35972
|
+
const profiles = readPermissionProfileFiles();
|
|
35973
|
+
const result = await compilePolicyBundle({
|
|
35974
|
+
sandboxId: config.sandboxId,
|
|
35975
|
+
effects: extractManifestEffects(manifest2),
|
|
35976
|
+
profileSources: profiles
|
|
35977
|
+
});
|
|
35978
|
+
if (result.errors.length > 0) {
|
|
35979
|
+
error("Permission policy validation failed:");
|
|
35980
|
+
for (const error2 of result.errors) error(` ${error2}`);
|
|
35981
|
+
process.exit(1);
|
|
35982
|
+
}
|
|
35983
|
+
success(
|
|
35984
|
+
`Validated ${Object.keys(result.bundle.profiles).length} permission profile(s).`
|
|
35985
|
+
);
|
|
35986
|
+
if (result.warnings.length > 0) {
|
|
35987
|
+
for (const warning of result.warnings) warn(warning);
|
|
35988
|
+
}
|
|
35989
|
+
});
|
|
35990
|
+
var permissionsPreviewCommand = Method(() => queryPermissions, {
|
|
35991
|
+
label: "Preview permission decision",
|
|
35992
|
+
description: "Preview an action permission decision for the selected product version."
|
|
35993
|
+
})(async function permissionsPreviewCommand2(options) {
|
|
35994
|
+
const config = resolveConfig({
|
|
35995
|
+
requireApiKey: Boolean(options.versionId),
|
|
35996
|
+
requireProject: true
|
|
35997
|
+
});
|
|
35998
|
+
if (!options.profile || !options.action) {
|
|
35999
|
+
throw new Error("permissions preview requires --profile and --action");
|
|
36000
|
+
}
|
|
36001
|
+
const requestInput = parseJsonObject(options.input);
|
|
36002
|
+
const objectContext = parseJsonObject(options.object);
|
|
36003
|
+
const stateMachines = parseJsonObject(options.stateMachines);
|
|
36004
|
+
const effectKey = resolveEffectKey(
|
|
36005
|
+
config.project.manifest,
|
|
36006
|
+
options.action,
|
|
36007
|
+
options.on
|
|
36008
|
+
);
|
|
36009
|
+
if (options.versionId) {
|
|
36010
|
+
const api = new ApiClient(config.apiKey, config.apiUrl);
|
|
36011
|
+
const decision2 = await api.evaluateVersionPolicy(options.versionId, {
|
|
36012
|
+
permissionProfileName: options.profile,
|
|
36013
|
+
effectKey,
|
|
36014
|
+
input: requestInput,
|
|
36015
|
+
object: objectContext,
|
|
36016
|
+
stateMachines
|
|
36017
|
+
});
|
|
36018
|
+
keyValue({
|
|
36019
|
+
Decision: decision2.outcome,
|
|
36020
|
+
Matched: (decision2.matches || []).map((match) => match.reason || match.summary || match.id).join("; ") || "none"
|
|
36021
|
+
});
|
|
36022
|
+
return;
|
|
36023
|
+
}
|
|
36024
|
+
const result = await compilePolicyBundle({
|
|
36025
|
+
sandboxId: config.sandboxId,
|
|
36026
|
+
effects: extractManifestEffects(config.project.manifest),
|
|
36027
|
+
profileSources: readPermissionProfileFiles()
|
|
36028
|
+
});
|
|
36029
|
+
if (result.errors.length > 0) {
|
|
36030
|
+
throw new Error(result.errors.join("; "));
|
|
36031
|
+
}
|
|
36032
|
+
const decision = evaluateCompiledPolicyBundle({
|
|
36033
|
+
bundle: result.bundle,
|
|
36034
|
+
profileName: options.profile,
|
|
36035
|
+
effectKey,
|
|
36036
|
+
context: { input: requestInput, object: objectContext, stateMachines }
|
|
36037
|
+
});
|
|
36038
|
+
keyValue({
|
|
36039
|
+
Decision: decision.outcome,
|
|
36040
|
+
Matched: decision.matches.map((match) => match.reason || match.summary || match.id).join("; ") || "none"
|
|
36041
|
+
});
|
|
36042
|
+
});
|
|
35468
36043
|
|
|
35469
36044
|
// src/cli/commands/graphql.ts
|
|
35470
36045
|
function parseVariables(raw) {
|
|
@@ -35482,7 +36057,10 @@ function parseVariables(raw) {
|
|
|
35482
36057
|
}
|
|
35483
36058
|
return parsed;
|
|
35484
36059
|
}
|
|
35485
|
-
|
|
36060
|
+
var graphqlCommand = Method(() => queryPermissions, {
|
|
36061
|
+
label: "Query environment graph",
|
|
36062
|
+
description: "Execute the supplied GraphQL query against the selected product environment."
|
|
36063
|
+
})(async function graphqlCommand2(options) {
|
|
35486
36064
|
const emitJson = options.json === true;
|
|
35487
36065
|
const variables = parseVariables(options.variables);
|
|
35488
36066
|
if (!emitJson) {
|
|
@@ -35524,7 +36102,7 @@ async function graphqlCommand(options) {
|
|
|
35524
36102
|
console.log();
|
|
35525
36103
|
}
|
|
35526
36104
|
);
|
|
35527
|
-
}
|
|
36105
|
+
});
|
|
35528
36106
|
|
|
35529
36107
|
// src/cli/commands/effects.ts
|
|
35530
36108
|
function sortEffects(effects2) {
|
|
@@ -35639,6 +36217,7 @@ async function effectsDiffCommand(options) {
|
|
|
35639
36217
|
}
|
|
35640
36218
|
|
|
35641
36219
|
// src/cli/commands/job.ts
|
|
36220
|
+
init_annotations();
|
|
35642
36221
|
async function waitForStoredJobResult(liveResult, inspect, options = {}) {
|
|
35643
36222
|
let busy = false, failures = 0, finished = false;
|
|
35644
36223
|
let resolveStored, rejectStored;
|
|
@@ -35678,7 +36257,10 @@ async function waitForStoredJobResult(liveResult, inspect, options = {}) {
|
|
|
35678
36257
|
cancel();
|
|
35679
36258
|
}
|
|
35680
36259
|
}
|
|
35681
|
-
|
|
36260
|
+
var jobRunCommand = Method(() => sessionJobTools, {
|
|
36261
|
+
label: "Run code job",
|
|
36262
|
+
description: "Submit code as a job in the selected conversation or environment."
|
|
36263
|
+
})(async function jobRunCommand2(options) {
|
|
35682
36264
|
if (options.runtime && !["promise", "effect"].includes(options.runtime))
|
|
35683
36265
|
throw new Error("--runtime must be promise or effect");
|
|
35684
36266
|
const emitJson = options.json === true;
|
|
@@ -35789,8 +36371,11 @@ async function jobRunCommand(options) {
|
|
|
35789
36371
|
console.log();
|
|
35790
36372
|
}
|
|
35791
36373
|
);
|
|
35792
|
-
}
|
|
35793
|
-
|
|
36374
|
+
});
|
|
36375
|
+
var jobReconcileCommand = Method(() => sessionJobTools, {
|
|
36376
|
+
label: "Reconcile uncertain operation",
|
|
36377
|
+
description: "Reconcile a job operation whose write outcome needs confirmation."
|
|
36378
|
+
})(async function jobReconcileCommand2(operationId2, options) {
|
|
35794
36379
|
await withRuntimeConnection(
|
|
35795
36380
|
{ sessionId: options.session },
|
|
35796
36381
|
async ({ session: session2 }) => {
|
|
@@ -35808,8 +36393,11 @@ async function jobReconcileCommand(operationId2, options) {
|
|
|
35808
36393
|
}
|
|
35809
36394
|
}
|
|
35810
36395
|
);
|
|
35811
|
-
}
|
|
35812
|
-
|
|
36396
|
+
});
|
|
36397
|
+
var jobTypesCommand = Method(() => sessionJobTools, {
|
|
36398
|
+
label: "Read runtime types",
|
|
36399
|
+
description: "Generate the runtime types available to submitted job code."
|
|
36400
|
+
})(async function jobTypesCommand2(options) {
|
|
35813
36401
|
if (!["promise", "effect"].includes(options.runtime || "promise"))
|
|
35814
36402
|
throw new Error("--runtime must be promise or effect");
|
|
35815
36403
|
await withRuntimeConnection(
|
|
@@ -35820,8 +36408,11 @@ async function jobTypesCommand(options) {
|
|
|
35820
36408
|
})
|
|
35821
36409
|
)
|
|
35822
36410
|
);
|
|
35823
|
-
}
|
|
35824
|
-
|
|
36411
|
+
});
|
|
36412
|
+
var jobInspectCommand = Method(() => sessionJobTools, {
|
|
36413
|
+
label: "Inspect job",
|
|
36414
|
+
description: "Read a job and its execution evidence for debugging."
|
|
36415
|
+
})(async function jobInspectCommand2(jobId, options) {
|
|
35825
36416
|
await withRuntimeConnection(
|
|
35826
36417
|
{ sessionId: options.session },
|
|
35827
36418
|
async ({ session: session2 }) => {
|
|
@@ -35934,7 +36525,7 @@ async function jobInspectCommand(jobId, options) {
|
|
|
35934
36525
|
console.log(`Coverage: ${gap}`);
|
|
35935
36526
|
}
|
|
35936
36527
|
);
|
|
35937
|
-
}
|
|
36528
|
+
});
|
|
35938
36529
|
async function jobCommitCommand(commitId, options) {
|
|
35939
36530
|
await withRuntimeConnection(
|
|
35940
36531
|
{ sessionId: options.session },
|
|
@@ -36017,254 +36608,16 @@ async function jobEventsCommand(jobId, options) {
|
|
|
36017
36608
|
);
|
|
36018
36609
|
}
|
|
36019
36610
|
|
|
36020
|
-
// src/cli/commands/permissions.ts
|
|
36021
|
-
init_src();
|
|
36022
|
-
function parseJsonObject(value) {
|
|
36023
|
-
if (!value) return {};
|
|
36024
|
-
const parsed = JSON.parse(value);
|
|
36025
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
36026
|
-
throw new Error("Expected a JSON object");
|
|
36027
|
-
}
|
|
36028
|
-
return parsed;
|
|
36029
|
-
}
|
|
36030
|
-
function resolveEffectKey(manifest2, action, on) {
|
|
36031
|
-
const effects2 = extractManifestEffects(manifest2);
|
|
36032
|
-
const matches = effects2.filter((effect) => {
|
|
36033
|
-
if (effect.name !== action) return false;
|
|
36034
|
-
return on ? effect.attachedClass === on : !effect.attachedClass;
|
|
36035
|
-
});
|
|
36036
|
-
if (matches.length === 1) return matches[0].effectKey;
|
|
36037
|
-
if (matches.length === 0) {
|
|
36038
|
-
throw new Error(
|
|
36039
|
-
on ? `Action "${action}" on "${on}" was not found.` : `Global action "${action}" was not found.`
|
|
36040
|
-
);
|
|
36041
|
-
}
|
|
36042
|
-
throw new Error(`Action "${action}" is ambiguous. Add --on.`);
|
|
36043
|
-
}
|
|
36044
|
-
async function permissionsValidateCommand() {
|
|
36045
|
-
const config = resolveConfig({ requireProject: true });
|
|
36046
|
-
const manifest2 = config.project.manifest;
|
|
36047
|
-
const profiles = readPermissionProfileFiles();
|
|
36048
|
-
const result = await compilePolicyBundle({
|
|
36049
|
-
sandboxId: config.sandboxId,
|
|
36050
|
-
effects: extractManifestEffects(manifest2),
|
|
36051
|
-
profileSources: profiles
|
|
36052
|
-
});
|
|
36053
|
-
if (result.errors.length > 0) {
|
|
36054
|
-
error("Permission policy validation failed:");
|
|
36055
|
-
for (const error2 of result.errors) error(` ${error2}`);
|
|
36056
|
-
process.exit(1);
|
|
36057
|
-
}
|
|
36058
|
-
success(
|
|
36059
|
-
`Validated ${Object.keys(result.bundle.profiles).length} permission profile(s).`
|
|
36060
|
-
);
|
|
36061
|
-
if (result.warnings.length > 0) {
|
|
36062
|
-
for (const warning of result.warnings) warn(warning);
|
|
36063
|
-
}
|
|
36064
|
-
}
|
|
36065
|
-
async function permissionsPreviewCommand(options) {
|
|
36066
|
-
const config = resolveConfig({
|
|
36067
|
-
requireApiKey: Boolean(options.versionId),
|
|
36068
|
-
requireProject: true
|
|
36069
|
-
});
|
|
36070
|
-
if (!options.profile || !options.action) {
|
|
36071
|
-
throw new Error("permissions preview requires --profile and --action");
|
|
36072
|
-
}
|
|
36073
|
-
const requestInput = parseJsonObject(options.input);
|
|
36074
|
-
const objectContext = parseJsonObject(options.object);
|
|
36075
|
-
const stateMachines = parseJsonObject(options.stateMachines);
|
|
36076
|
-
const effectKey = resolveEffectKey(
|
|
36077
|
-
config.project.manifest,
|
|
36078
|
-
options.action,
|
|
36079
|
-
options.on
|
|
36080
|
-
);
|
|
36081
|
-
if (options.versionId) {
|
|
36082
|
-
const api = new ApiClient(config.apiKey, config.apiUrl);
|
|
36083
|
-
const decision2 = await api.evaluateVersionPolicy(options.versionId, {
|
|
36084
|
-
permissionProfileName: options.profile,
|
|
36085
|
-
effectKey,
|
|
36086
|
-
input: requestInput,
|
|
36087
|
-
object: objectContext,
|
|
36088
|
-
stateMachines
|
|
36089
|
-
});
|
|
36090
|
-
keyValue({
|
|
36091
|
-
Decision: decision2.outcome,
|
|
36092
|
-
Matched: (decision2.matches || []).map((match) => match.reason || match.summary || match.id).join("; ") || "none"
|
|
36093
|
-
});
|
|
36094
|
-
return;
|
|
36095
|
-
}
|
|
36096
|
-
const result = await compilePolicyBundle({
|
|
36097
|
-
sandboxId: config.sandboxId,
|
|
36098
|
-
effects: extractManifestEffects(config.project.manifest),
|
|
36099
|
-
profileSources: readPermissionProfileFiles()
|
|
36100
|
-
});
|
|
36101
|
-
if (result.errors.length > 0) {
|
|
36102
|
-
throw new Error(result.errors.join("; "));
|
|
36103
|
-
}
|
|
36104
|
-
const decision = evaluateCompiledPolicyBundle({
|
|
36105
|
-
bundle: result.bundle,
|
|
36106
|
-
profileName: options.profile,
|
|
36107
|
-
effectKey,
|
|
36108
|
-
context: { input: requestInput, object: objectContext, stateMachines }
|
|
36109
|
-
});
|
|
36110
|
-
keyValue({
|
|
36111
|
-
Decision: decision.outcome,
|
|
36112
|
-
Matched: decision.matches.map((match) => match.reason || match.summary || match.id).join("; ") || "none"
|
|
36113
|
-
});
|
|
36114
|
-
}
|
|
36115
|
-
|
|
36116
|
-
// src/cli/commands/version.ts
|
|
36117
|
-
function formatVersionLabel(versionId, versionNumber) {
|
|
36118
|
-
return versionNumber != null ? `v${versionNumber}` : versionId;
|
|
36119
|
-
}
|
|
36120
|
-
function compareBuilds(left, right) {
|
|
36121
|
-
const leftVersion = left.versionNumber ?? Number.NEGATIVE_INFINITY;
|
|
36122
|
-
const rightVersion = right.versionNumber ?? Number.NEGATIVE_INFINITY;
|
|
36123
|
-
if (leftVersion !== rightVersion) {
|
|
36124
|
-
return rightVersion - leftVersion;
|
|
36125
|
-
}
|
|
36126
|
-
return (right.createdAt ?? 0) - (left.createdAt ?? 0);
|
|
36127
|
-
}
|
|
36128
|
-
function resolveCurrentVersion(builds, tags) {
|
|
36129
|
-
if (builds.length === 0) {
|
|
36130
|
-
return null;
|
|
36131
|
-
}
|
|
36132
|
-
const byId = new Map(builds.map((build) => [build.buildId, build]));
|
|
36133
|
-
const currentBuild = builds.find((build) => build.isCurrent);
|
|
36134
|
-
if (currentBuild) {
|
|
36135
|
-
return currentBuild;
|
|
36136
|
-
}
|
|
36137
|
-
const devTarget = tags.find((tag2) => tag2.name === "dev")?.targetVersionId || tags.find((tag2) => tag2.name === "dev")?.targetBuildId;
|
|
36138
|
-
if (devTarget && byId.has(devTarget)) {
|
|
36139
|
-
return byId.get(devTarget);
|
|
36140
|
-
}
|
|
36141
|
-
return [...builds].sort(compareBuilds)[0];
|
|
36142
|
-
}
|
|
36143
|
-
async function versionCurrentCommand(options) {
|
|
36144
|
-
const emitJson = options?.json === true;
|
|
36145
|
-
if (!emitJson) {
|
|
36146
|
-
printHeader();
|
|
36147
|
-
}
|
|
36148
|
-
const config = resolveConfig({ requireApiKey: true });
|
|
36149
|
-
if (!config.sandboxId) {
|
|
36150
|
-
throw new Error("No ontology configured. Run `granular init` first.");
|
|
36151
|
-
}
|
|
36152
|
-
const api = new ApiClient(config.apiKey, config.apiUrl);
|
|
36153
|
-
const spin = emitJson ? null : spinner("Resolving current version...");
|
|
36154
|
-
try {
|
|
36155
|
-
const [builds, tags] = await Promise.all([
|
|
36156
|
-
api.listVersions(config.sandboxId),
|
|
36157
|
-
api.listTags(config.sandboxId).catch(() => [])
|
|
36158
|
-
]);
|
|
36159
|
-
const current = resolveCurrentVersion(builds, tags);
|
|
36160
|
-
if (!current) {
|
|
36161
|
-
throw new Error(
|
|
36162
|
-
"No versions exist for this ontology yet. Run `granular build` first."
|
|
36163
|
-
);
|
|
36164
|
-
}
|
|
36165
|
-
const payload = {
|
|
36166
|
-
ontologyId: config.sandboxId,
|
|
36167
|
-
versionId: current.buildId,
|
|
36168
|
-
versionNumber: current.versionNumber ?? null,
|
|
36169
|
-
status: current.status,
|
|
36170
|
-
createdAt: current.createdAt,
|
|
36171
|
-
isCurrent: current.isCurrent ?? false,
|
|
36172
|
-
devVersionId: tags.find((tag2) => tag2.name === "dev")?.targetVersionId || tags.find((tag2) => tag2.name === "dev")?.targetBuildId || null,
|
|
36173
|
-
prodVersionId: tags.find((tag2) => tag2.name === "prod")?.targetVersionId || tags.find((tag2) => tag2.name === "prod")?.targetBuildId || null
|
|
36174
|
-
};
|
|
36175
|
-
if (emitJson) {
|
|
36176
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
36177
|
-
return;
|
|
36178
|
-
}
|
|
36179
|
-
spin?.succeed(" Current version resolved.");
|
|
36180
|
-
console.log();
|
|
36181
|
-
keyValue({
|
|
36182
|
-
"Ontology ID": payload.ontologyId,
|
|
36183
|
-
"Current version": formatVersionLabel(
|
|
36184
|
-
payload.versionId,
|
|
36185
|
-
payload.versionNumber
|
|
36186
|
-
),
|
|
36187
|
-
Status: payload.status,
|
|
36188
|
-
Created: payload.createdAt,
|
|
36189
|
-
"Dev tag": payload.devVersionId || "not set",
|
|
36190
|
-
"Prod tag": payload.prodVersionId || "not set"
|
|
36191
|
-
});
|
|
36192
|
-
console.log();
|
|
36193
|
-
} catch (err) {
|
|
36194
|
-
spin?.fail(` Failed to resolve current version: ${err.message}`);
|
|
36195
|
-
throw err;
|
|
36196
|
-
}
|
|
36197
|
-
}
|
|
36198
|
-
async function versionDiffCommand(versionId, againstVersionId, options) {
|
|
36199
|
-
const emitJson = options?.json === true;
|
|
36200
|
-
if (!emitJson) {
|
|
36201
|
-
printHeader();
|
|
36202
|
-
}
|
|
36203
|
-
const config = resolveConfig({ requireApiKey: true });
|
|
36204
|
-
const api = new ApiClient(config.apiKey, config.apiUrl);
|
|
36205
|
-
const spin = emitJson ? null : spinner(
|
|
36206
|
-
againstVersionId ? `Computing diff ${versionId} \u2190 ${againstVersionId}...` : `Computing diff for ${versionId}...`
|
|
36207
|
-
);
|
|
36208
|
-
try {
|
|
36209
|
-
const [version3, diffResult] = await Promise.all([
|
|
36210
|
-
api.getVersion(versionId),
|
|
36211
|
-
api.getVersionDiff(versionId, againstVersionId)
|
|
36212
|
-
]);
|
|
36213
|
-
const baseVersion = diffResult.againstVersionId ? await api.getVersion(diffResult.againstVersionId).catch(() => null) : null;
|
|
36214
|
-
const summary = diffResult.diff.summary;
|
|
36215
|
-
const payload = {
|
|
36216
|
-
versionId: version3.buildId,
|
|
36217
|
-
versionNumber: version3.versionNumber ?? null,
|
|
36218
|
-
againstVersionId: diffResult.againstVersionId,
|
|
36219
|
-
againstVersionNumber: baseVersion?.versionNumber ?? null,
|
|
36220
|
-
summary,
|
|
36221
|
-
entries: diffResult.diff.entries
|
|
36222
|
-
};
|
|
36223
|
-
if (emitJson) {
|
|
36224
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
36225
|
-
return;
|
|
36226
|
-
}
|
|
36227
|
-
spin?.succeed(" Version diff ready.");
|
|
36228
|
-
console.log();
|
|
36229
|
-
keyValue({
|
|
36230
|
-
Version: formatVersionLabel(version3.buildId, version3.versionNumber),
|
|
36231
|
-
"Compared against": baseVersion ? formatVersionLabel(baseVersion.buildId, baseVersion.versionNumber) : diffResult.againstVersionId || "previous version",
|
|
36232
|
-
"Added operations": summary.added,
|
|
36233
|
-
"Changed operations": summary.changed,
|
|
36234
|
-
"Removed operations": summary.removed,
|
|
36235
|
-
"Transition safety": summary.onlyAdditiveChanges ? "additive only" : "breaking changes detected"
|
|
36236
|
-
});
|
|
36237
|
-
if (diffResult.diff.entries.length === 0) {
|
|
36238
|
-
console.log();
|
|
36239
|
-
info("No ontology changes between these versions.");
|
|
36240
|
-
console.log();
|
|
36241
|
-
return;
|
|
36242
|
-
}
|
|
36243
|
-
console.log();
|
|
36244
|
-
step("Semantic diff");
|
|
36245
|
-
console.log();
|
|
36246
|
-
table(
|
|
36247
|
-
["Change", "Kind", "Operation", "Safety"],
|
|
36248
|
-
diffResult.diff.entries.map((entry) => [
|
|
36249
|
-
entry.changeType,
|
|
36250
|
-
entry.kind,
|
|
36251
|
-
entry.label,
|
|
36252
|
-
entry.additive ? "safe-add" : "breaking"
|
|
36253
|
-
])
|
|
36254
|
-
);
|
|
36255
|
-
console.log();
|
|
36256
|
-
} catch (err) {
|
|
36257
|
-
spin?.fail(` Failed to compute diff: ${err.message}`);
|
|
36258
|
-
throw err;
|
|
36259
|
-
}
|
|
36260
|
-
}
|
|
36261
|
-
|
|
36262
36611
|
// src/cli/commands/tag.ts
|
|
36612
|
+
init_annotations();
|
|
36263
36613
|
function renderVersionTarget(versionId) {
|
|
36264
36614
|
if (!versionId) return "not set";
|
|
36265
36615
|
return versionId;
|
|
36266
36616
|
}
|
|
36267
|
-
|
|
36617
|
+
var tagListCommand = Method(() => versionManagement, {
|
|
36618
|
+
label: "List tags",
|
|
36619
|
+
description: "List a product's version tags and their selected versions."
|
|
36620
|
+
})(async function tagListCommand2() {
|
|
36268
36621
|
printHeader();
|
|
36269
36622
|
const config = resolveConfig({ requireApiKey: true });
|
|
36270
36623
|
if (!config.sandboxId) {
|
|
@@ -36296,8 +36649,11 @@ async function tagListCommand() {
|
|
|
36296
36649
|
spin.fail(` Failed to load tags: ${err.message}`);
|
|
36297
36650
|
process.exit(1);
|
|
36298
36651
|
}
|
|
36299
|
-
}
|
|
36300
|
-
|
|
36652
|
+
});
|
|
36653
|
+
var tagMoveCommand = Method(() => versionManagement, {
|
|
36654
|
+
label: "Move tag",
|
|
36655
|
+
description: "Move a product tag to the requested version with the supplied preconditions."
|
|
36656
|
+
})(async function tagMoveCommand2(tagName, versionId) {
|
|
36301
36657
|
printHeader();
|
|
36302
36658
|
const config = resolveConfig({ requireApiKey: true });
|
|
36303
36659
|
if (!config.sandboxId) {
|
|
@@ -36343,7 +36699,7 @@ async function tagMoveCommand(tagName, versionId) {
|
|
|
36343
36699
|
spin.fail(` Failed to move tag: ${err.message}`);
|
|
36344
36700
|
process.exit(1);
|
|
36345
36701
|
}
|
|
36346
|
-
}
|
|
36702
|
+
});
|
|
36347
36703
|
|
|
36348
36704
|
// src/cli/commands/check.ts
|
|
36349
36705
|
init_src();
|