@stackbone/sdk 0.1.0-alpha.5 → 0.1.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/call-connector-CYDw_yG5.d.cts +118 -0
- package/call-connector-CYDw_yG5.d.ts +118 -0
- package/connect.cjs +270 -0
- package/connect.cjs.map +1 -0
- package/connect.d.cts +94 -0
- package/connect.d.ts +94 -0
- package/connect.js +257 -0
- package/connect.js.map +1 -0
- package/index.cjs +486 -96
- package/index.cjs.map +1 -1
- package/index.d.cts +401 -19
- package/index.d.ts +401 -19
- package/index.js +481 -98
- package/index.js.map +1 -1
- package/observability/index.cjs +1 -268
- package/observability/index.cjs.map +1 -1
- package/observability/index.d.cts +1 -96
- package/observability/index.d.ts +1 -96
- package/observability/index.js +2 -264
- package/observability/index.js.map +1 -1
- package/package.json +33 -1
- package/stackbone-sdk-0.1.0-alpha.7.tgz +0 -0
- package/workflow-scheduler-DXCNKDOS.d.cts +119 -0
- package/workflow-scheduler-DXCNKDOS.d.ts +119 -0
- package/workflow.cjs +17417 -0
- package/workflow.cjs.map +1 -0
- package/workflow.d.cts +207 -0
- package/workflow.d.ts +207 -0
- package/workflow.js +17392 -0
- package/workflow.js.map +1 -0
- package/stackbone-sdk-0.1.0-alpha.5.tgz +0 -0
package/index.cjs
CHANGED
|
@@ -2373,7 +2373,7 @@ var require_luxon = __commonJS({
|
|
|
2373
2373
|
return new Formatter2(locale, opts);
|
|
2374
2374
|
}
|
|
2375
2375
|
static parseFormat(fmt) {
|
|
2376
|
-
let
|
|
2376
|
+
let current3 = null, currentFull = "", bracketed = false;
|
|
2377
2377
|
const splits = [];
|
|
2378
2378
|
for (let i2 = 0; i2 < fmt.length; i2++) {
|
|
2379
2379
|
const c2 = fmt.charAt(i2);
|
|
@@ -2384,12 +2384,12 @@ var require_luxon = __commonJS({
|
|
|
2384
2384
|
val: currentFull === "" ? "'" : currentFull
|
|
2385
2385
|
});
|
|
2386
2386
|
}
|
|
2387
|
-
|
|
2387
|
+
current3 = null;
|
|
2388
2388
|
currentFull = "";
|
|
2389
2389
|
bracketed = !bracketed;
|
|
2390
2390
|
} else if (bracketed) {
|
|
2391
2391
|
currentFull += c2;
|
|
2392
|
-
} else if (c2 ===
|
|
2392
|
+
} else if (c2 === current3) {
|
|
2393
2393
|
currentFull += c2;
|
|
2394
2394
|
} else {
|
|
2395
2395
|
if (currentFull.length > 0) {
|
|
@@ -2399,7 +2399,7 @@ var require_luxon = __commonJS({
|
|
|
2399
2399
|
});
|
|
2400
2400
|
}
|
|
2401
2401
|
currentFull = c2;
|
|
2402
|
-
|
|
2402
|
+
current3 = c2;
|
|
2403
2403
|
}
|
|
2404
2404
|
}
|
|
2405
2405
|
if (currentFull.length > 0) {
|
|
@@ -3129,28 +3129,28 @@ var require_luxon = __commonJS({
|
|
|
3129
3129
|
__name(durationToMillis, "durationToMillis");
|
|
3130
3130
|
function normalizeValues(matrix, vals) {
|
|
3131
3131
|
const factor = durationToMillis(matrix, vals) < 0 ? -1 : 1;
|
|
3132
|
-
orderedUnits$1.reduceRight((previous,
|
|
3133
|
-
if (!isUndefined(vals[
|
|
3132
|
+
orderedUnits$1.reduceRight((previous, current3) => {
|
|
3133
|
+
if (!isUndefined(vals[current3])) {
|
|
3134
3134
|
if (previous) {
|
|
3135
3135
|
const previousVal = vals[previous] * factor;
|
|
3136
|
-
const conv = matrix[
|
|
3136
|
+
const conv = matrix[current3][previous];
|
|
3137
3137
|
const rollUp = Math.floor(previousVal / conv);
|
|
3138
|
-
vals[
|
|
3138
|
+
vals[current3] += rollUp * factor;
|
|
3139
3139
|
vals[previous] -= rollUp * conv * factor;
|
|
3140
3140
|
}
|
|
3141
|
-
return
|
|
3141
|
+
return current3;
|
|
3142
3142
|
} else {
|
|
3143
3143
|
return previous;
|
|
3144
3144
|
}
|
|
3145
3145
|
}, null);
|
|
3146
|
-
orderedUnits$1.reduce((previous,
|
|
3147
|
-
if (!isUndefined(vals[
|
|
3146
|
+
orderedUnits$1.reduce((previous, current3) => {
|
|
3147
|
+
if (!isUndefined(vals[current3])) {
|
|
3148
3148
|
if (previous) {
|
|
3149
3149
|
const fraction = vals[previous] % 1;
|
|
3150
3150
|
vals[previous] -= fraction;
|
|
3151
|
-
vals[
|
|
3151
|
+
vals[current3] += fraction * matrix[previous][current3];
|
|
3152
3152
|
}
|
|
3153
|
-
return
|
|
3153
|
+
return current3;
|
|
3154
3154
|
} else {
|
|
3155
3155
|
return previous;
|
|
3156
3156
|
}
|
|
@@ -4263,21 +4263,21 @@ var require_luxon = __commonJS({
|
|
|
4263
4263
|
* @return {Array}
|
|
4264
4264
|
*/
|
|
4265
4265
|
static merge(intervals) {
|
|
4266
|
-
const [found, final] = intervals.sort((a2, b2) => a2.s - b2.s).reduce(([sofar,
|
|
4267
|
-
if (!
|
|
4266
|
+
const [found, final] = intervals.sort((a2, b2) => a2.s - b2.s).reduce(([sofar, current3], item) => {
|
|
4267
|
+
if (!current3) {
|
|
4268
4268
|
return [
|
|
4269
4269
|
sofar,
|
|
4270
4270
|
item
|
|
4271
4271
|
];
|
|
4272
|
-
} else if (
|
|
4272
|
+
} else if (current3.overlaps(item) || current3.abutsStart(item)) {
|
|
4273
4273
|
return [
|
|
4274
4274
|
sofar,
|
|
4275
|
-
|
|
4275
|
+
current3.union(item)
|
|
4276
4276
|
];
|
|
4277
4277
|
} else {
|
|
4278
4278
|
return [
|
|
4279
4279
|
sofar.concat([
|
|
4280
|
-
|
|
4280
|
+
current3
|
|
4281
4281
|
]),
|
|
4282
4282
|
item
|
|
4283
4283
|
];
|
|
@@ -5209,7 +5209,7 @@ var require_luxon = __commonJS({
|
|
|
5209
5209
|
}
|
|
5210
5210
|
__name(possiblyCachedLocalWeekData, "possiblyCachedLocalWeekData");
|
|
5211
5211
|
function clone(inst, alts) {
|
|
5212
|
-
const
|
|
5212
|
+
const current3 = {
|
|
5213
5213
|
ts: inst.ts,
|
|
5214
5214
|
zone: inst.zone,
|
|
5215
5215
|
c: inst.c,
|
|
@@ -5218,9 +5218,9 @@ var require_luxon = __commonJS({
|
|
|
5218
5218
|
invalid: inst.invalid
|
|
5219
5219
|
};
|
|
5220
5220
|
return new DateTime({
|
|
5221
|
-
...
|
|
5221
|
+
...current3,
|
|
5222
5222
|
...alts,
|
|
5223
|
-
old:
|
|
5223
|
+
old: current3
|
|
5224
5224
|
});
|
|
5225
5225
|
}
|
|
5226
5226
|
__name(clone, "clone");
|
|
@@ -8225,7 +8225,7 @@ var require_expression = __commonJS({
|
|
|
8225
8225
|
return schedule;
|
|
8226
8226
|
}, "prev");
|
|
8227
8227
|
CronExpression.prototype.hasNext = function() {
|
|
8228
|
-
var
|
|
8228
|
+
var current3 = this._currentDate;
|
|
8229
8229
|
var hasIterated = this._hasIterated;
|
|
8230
8230
|
try {
|
|
8231
8231
|
this._findSchedule();
|
|
@@ -8233,12 +8233,12 @@ var require_expression = __commonJS({
|
|
|
8233
8233
|
} catch (err3) {
|
|
8234
8234
|
return false;
|
|
8235
8235
|
} finally {
|
|
8236
|
-
this._currentDate =
|
|
8236
|
+
this._currentDate = current3;
|
|
8237
8237
|
this._hasIterated = hasIterated;
|
|
8238
8238
|
}
|
|
8239
8239
|
};
|
|
8240
8240
|
CronExpression.prototype.hasPrev = function() {
|
|
8241
|
-
var
|
|
8241
|
+
var current3 = this._currentDate;
|
|
8242
8242
|
var hasIterated = this._hasIterated;
|
|
8243
8243
|
try {
|
|
8244
8244
|
this._findSchedule(true);
|
|
@@ -8246,7 +8246,7 @@ var require_expression = __commonJS({
|
|
|
8246
8246
|
} catch (err3) {
|
|
8247
8247
|
return false;
|
|
8248
8248
|
} finally {
|
|
8249
|
-
this._currentDate =
|
|
8249
|
+
this._currentDate = current3;
|
|
8250
8250
|
this._hasIterated = hasIterated;
|
|
8251
8251
|
}
|
|
8252
8252
|
};
|
|
@@ -8753,9 +8753,11 @@ var CAPABILITIES = [
|
|
|
8753
8753
|
"prompts.basic",
|
|
8754
8754
|
// `connections.actions`: the agent → control-plane connectors proxy
|
|
8755
8755
|
// (feature connectors-connections-automations). Role-based naming per repo
|
|
8756
|
-
// convention. `client.
|
|
8756
|
+
// convention. `client.legacyConnections.list()` / `.invoke(connector, action, args)`
|
|
8757
8757
|
// run against the proxy; the agent container never sees a credential. The
|
|
8758
|
-
// v13 bump reintroduces this capability after v12 removed it.
|
|
8758
|
+
// v13 bump reintroduces this capability after v12 removed it. The capability
|
|
8759
|
+
// string stays `connections.actions` (it names the wire domain, not the
|
|
8760
|
+
// renamed SDK accessor).
|
|
8759
8761
|
"connections.actions"
|
|
8760
8762
|
];
|
|
8761
8763
|
var MODULE_CAPABILITIES = {
|
|
@@ -8772,10 +8774,11 @@ var MODULE_CAPABILITIES = {
|
|
|
8772
8774
|
// row is still declared here because the table is shared with the cloud
|
|
8773
8775
|
// contract / Studio capability advertisement.
|
|
8774
8776
|
prompts: "prompts.basic",
|
|
8775
|
-
// `client.
|
|
8776
|
-
// agent POSTs to `/api/v1/agent/connections/*` with its agent JWT and the
|
|
8777
|
+
// `client.legacyConnections` is a control-plane PROXY surface (like queues):
|
|
8778
|
+
// the agent POSTs to `/api/v1/agent/connections/*` with its agent JWT and the
|
|
8777
8779
|
// control plane runs the connector action with credentials resolved in
|
|
8778
|
-
// memory. Gated against `connections.actions`.
|
|
8780
|
+
// memory. Gated against `connections.actions`. The map key stays `connections`
|
|
8781
|
+
// (it is the module id shared with the cloud contract, not the SDK accessor).
|
|
8779
8782
|
connections: "connections.actions"
|
|
8780
8783
|
};
|
|
8781
8784
|
var contractBuildNameSchema = zod.z.enum([
|
|
@@ -8877,7 +8880,8 @@ var journalTerminalStatusSchema = zod.z.enum([
|
|
|
8877
8880
|
]);
|
|
8878
8881
|
var journalJobStatusSchema = zod.z.enum([
|
|
8879
8882
|
...journalTerminalStatusSchema.options,
|
|
8880
|
-
"running"
|
|
8883
|
+
"running",
|
|
8884
|
+
"lost"
|
|
8881
8885
|
]);
|
|
8882
8886
|
var jobStatusSchema = zod.z.enum([
|
|
8883
8887
|
...bullmqJobStatusSchema.options,
|
|
@@ -8979,6 +8983,27 @@ zod.z.object({
|
|
|
8979
8983
|
queue: zod.z.string(),
|
|
8980
8984
|
status: jobStatusSchema
|
|
8981
8985
|
});
|
|
8986
|
+
zod.z.object({
|
|
8987
|
+
items: zod.z.array(bullmqJobSchema)
|
|
8988
|
+
});
|
|
8989
|
+
zod.z.object({
|
|
8990
|
+
purged: zod.z.number().int().nonnegative()
|
|
8991
|
+
});
|
|
8992
|
+
zod.z.object({
|
|
8993
|
+
payload: jsonObject(),
|
|
8994
|
+
retries: zod.z.number().int().nonnegative().optional(),
|
|
8995
|
+
delay: zod.z.number().int().nonnegative().optional()
|
|
8996
|
+
});
|
|
8997
|
+
zod.z.object({
|
|
8998
|
+
message_id: zod.z.string(),
|
|
8999
|
+
queue: queueNameSchema
|
|
9000
|
+
});
|
|
9001
|
+
zod.z.object({
|
|
9002
|
+
name: queueNameSchema
|
|
9003
|
+
});
|
|
9004
|
+
zod.z.object({
|
|
9005
|
+
limit: zod.z.coerce.number().int().min(1).max(50).default(10)
|
|
9006
|
+
});
|
|
8982
9007
|
|
|
8983
9008
|
// ../shared/validators/src/lib/agents/queue-jobs.ts
|
|
8984
9009
|
var MAX_JOB_ATTEMPTS = 20;
|
|
@@ -9172,9 +9197,9 @@ function createContractStore(resolved = resolveConfig({})) {
|
|
|
9172
9197
|
function peek(baseUrl) {
|
|
9173
9198
|
if (!baseUrl || baseUrl.trim() === "") return null;
|
|
9174
9199
|
const key = normaliseBaseUrl(baseUrl);
|
|
9175
|
-
const
|
|
9176
|
-
if (!
|
|
9177
|
-
return
|
|
9200
|
+
const cached2 = lastResolved.get(key);
|
|
9201
|
+
if (!cached2 || cached2.error) return null;
|
|
9202
|
+
return cached2.data;
|
|
9178
9203
|
}
|
|
9179
9204
|
__name(peek, "peek");
|
|
9180
9205
|
function gatingEnabled() {
|
|
@@ -9440,9 +9465,9 @@ var HttpClient = class {
|
|
|
9440
9465
|
if (jwt && !requestHeaders.has("Authorization")) {
|
|
9441
9466
|
requestHeaders.set("Authorization", `Bearer ${jwt}`);
|
|
9442
9467
|
}
|
|
9443
|
-
const
|
|
9444
|
-
if (
|
|
9445
|
-
requestHeaders.set("X-Stackbone-Installation-Id",
|
|
9468
|
+
const installationId2 = resolveInstallationId(this.resolved);
|
|
9469
|
+
if (installationId2 && !requestHeaders.has("X-Stackbone-Installation-Id")) {
|
|
9470
|
+
requestHeaders.set("X-Stackbone-Installation-Id", installationId2);
|
|
9446
9471
|
}
|
|
9447
9472
|
const body = serializeBody(method, options.body, requestHeaders);
|
|
9448
9473
|
let lastError = null;
|
|
@@ -9937,10 +9962,10 @@ var ApprovalFacade = class {
|
|
|
9937
9962
|
const fallback = onTimeoutToFallback(options.onTimeout);
|
|
9938
9963
|
const callbackUrl = options.onDecide;
|
|
9939
9964
|
try {
|
|
9940
|
-
const rows = await
|
|
9965
|
+
const rows = await this._getDatabase().runShared((db) => db`
|
|
9941
9966
|
INSERT INTO stackbone_platform.approvals (
|
|
9942
9967
|
topic, payload, callback_url, idempotency_key,
|
|
9943
|
-
fallback, metadata, timeout_at
|
|
9968
|
+
fallback, metadata, run_id, requested_by_step_id, timeout_at
|
|
9944
9969
|
) VALUES (
|
|
9945
9970
|
${options.topic},
|
|
9946
9971
|
${JSON.stringify(options.payload ?? {})}::jsonb,
|
|
@@ -9948,6 +9973,8 @@ var ApprovalFacade = class {
|
|
|
9948
9973
|
${options.idempotencyKey ?? null},
|
|
9949
9974
|
${fallback},
|
|
9950
9975
|
${JSON.stringify(options.metadata ?? {})}::jsonb,
|
|
9976
|
+
${options.runId ?? null}::uuid,
|
|
9977
|
+
${options.requestedByStepId ?? null}::uuid,
|
|
9951
9978
|
now() + (${timeoutMs}::int * interval '1 millisecond')
|
|
9952
9979
|
)
|
|
9953
9980
|
ON CONFLICT (workspace_id, topic, idempotency_key)
|
|
@@ -9956,7 +9983,7 @@ var ApprovalFacade = class {
|
|
|
9956
9983
|
RETURNING id, callback_url,
|
|
9957
9984
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS created_at,
|
|
9958
9985
|
to_char(timeout_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS timeout_at
|
|
9959
|
-
|
|
9986
|
+
`);
|
|
9960
9987
|
const row = rows[0];
|
|
9961
9988
|
if (!row) {
|
|
9962
9989
|
return err({
|
|
@@ -9991,13 +10018,13 @@ var ApprovalFacade = class {
|
|
|
9991
10018
|
const patch = reason ? {
|
|
9992
10019
|
cancelReason: reason
|
|
9993
10020
|
} : {};
|
|
9994
|
-
await
|
|
10021
|
+
await this._getDatabase().runShared((db) => db`
|
|
9995
10022
|
UPDATE stackbone_platform.approvals
|
|
9996
10023
|
SET status = 'cancelled',
|
|
9997
10024
|
decided_at = now(),
|
|
9998
10025
|
metadata = metadata || ${JSON.stringify(patch)}::jsonb
|
|
9999
10026
|
WHERE id = ${approvalId}::uuid AND status = 'pending'
|
|
10000
|
-
|
|
10027
|
+
`);
|
|
10001
10028
|
return ok(void 0);
|
|
10002
10029
|
} catch (cause) {
|
|
10003
10030
|
return err({
|
|
@@ -10017,14 +10044,14 @@ var ApprovalFacade = class {
|
|
|
10017
10044
|
const sql = this.sql();
|
|
10018
10045
|
if (sql.error) return err(sql.error);
|
|
10019
10046
|
try {
|
|
10020
|
-
const rows = await
|
|
10047
|
+
const rows = await this._getDatabase().runShared((db) => db`
|
|
10021
10048
|
SELECT id, topic, status, payload, metadata,
|
|
10022
10049
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS created_at,
|
|
10023
10050
|
to_char(timeout_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS timeout_at
|
|
10024
10051
|
FROM stackbone_platform.approvals
|
|
10025
10052
|
WHERE id = ${approvalId}::uuid
|
|
10026
10053
|
LIMIT 1
|
|
10027
|
-
|
|
10054
|
+
`);
|
|
10028
10055
|
const row = rows[0];
|
|
10029
10056
|
if (!row) {
|
|
10030
10057
|
return err({
|
|
@@ -10049,7 +10076,7 @@ var ApprovalFacade = class {
|
|
|
10049
10076
|
if (sql.error) return err(sql.error);
|
|
10050
10077
|
const limit = clampLimit(options.limit);
|
|
10051
10078
|
try {
|
|
10052
|
-
const rows = await
|
|
10079
|
+
const rows = await this._getDatabase().runShared((db) => db`
|
|
10053
10080
|
SELECT id, topic, status, payload, metadata,
|
|
10054
10081
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS created_at,
|
|
10055
10082
|
to_char(timeout_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS timeout_at
|
|
@@ -10058,7 +10085,7 @@ var ApprovalFacade = class {
|
|
|
10058
10085
|
AND (${options.topic ?? null}::text IS NULL OR topic = ${options.topic ?? null})
|
|
10059
10086
|
ORDER BY created_at DESC, id DESC
|
|
10060
10087
|
LIMIT ${limit}
|
|
10061
|
-
|
|
10088
|
+
`);
|
|
10062
10089
|
return ok({
|
|
10063
10090
|
items: rows.map((row) => toRecord(row))
|
|
10064
10091
|
});
|
|
@@ -10180,7 +10207,7 @@ var ConfigFacade = class {
|
|
|
10180
10207
|
void this._resolved;
|
|
10181
10208
|
}
|
|
10182
10209
|
async get(key) {
|
|
10183
|
-
if (!key.trim()) {
|
|
10210
|
+
if (!String(key).trim()) {
|
|
10184
10211
|
return err({
|
|
10185
10212
|
code: "config_invalid_request",
|
|
10186
10213
|
message: "`key` is required."
|
|
@@ -10191,7 +10218,7 @@ var ConfigFacade = class {
|
|
|
10191
10218
|
if (!payload.data || !(key in payload.data)) {
|
|
10192
10219
|
return err({
|
|
10193
10220
|
code: "config_not_found",
|
|
10194
|
-
message: `Config key \`${key}\` is not set for this agent.`,
|
|
10221
|
+
message: `Config key \`${String(key)}\` is not set for this agent.`,
|
|
10195
10222
|
meta: {
|
|
10196
10223
|
key
|
|
10197
10224
|
}
|
|
@@ -10220,13 +10247,24 @@ var ConfigFacade = class {
|
|
|
10220
10247
|
}
|
|
10221
10248
|
return ok(out);
|
|
10222
10249
|
}
|
|
10250
|
+
/**
|
|
10251
|
+
* Returns the agent's entire config payload as one typed object. An
|
|
10252
|
+
* absent/null `agent_config` row resolves to `ok({})` — an empty config is
|
|
10253
|
+
* "no config set", consistent with the facade reading the singleton row.
|
|
10254
|
+
* Reads stay an unvalidated SELECT (no AJV on the read path).
|
|
10255
|
+
*/
|
|
10256
|
+
async getAll() {
|
|
10257
|
+
const payload = await this.loadPayload();
|
|
10258
|
+
if (payload.error) return err(payload.error);
|
|
10259
|
+
return ok(payload.data ?? {});
|
|
10260
|
+
}
|
|
10223
10261
|
async loadPayload() {
|
|
10224
10262
|
const sql = this.sql();
|
|
10225
10263
|
if (sql.error) return err(sql.error);
|
|
10226
10264
|
try {
|
|
10227
|
-
const rows = await
|
|
10265
|
+
const rows = await this._getDatabase().runShared((db) => db`
|
|
10228
10266
|
SELECT payload FROM stackbone_platform.agent_config WHERE id = 1
|
|
10229
|
-
|
|
10267
|
+
`);
|
|
10230
10268
|
return ok(rows[0]?.payload ?? null);
|
|
10231
10269
|
} catch (cause) {
|
|
10232
10270
|
return err({
|
|
@@ -10300,6 +10338,10 @@ function isPoolTerminatedError(error) {
|
|
|
10300
10338
|
return typeof code === "string" && POOL_TERMINATED_ERROR_CODES.has(code);
|
|
10301
10339
|
}
|
|
10302
10340
|
__name(isPoolTerminatedError, "isPoolTerminatedError");
|
|
10341
|
+
function invalidatePoolHandle() {
|
|
10342
|
+
cachedHandle = null;
|
|
10343
|
+
}
|
|
10344
|
+
__name(invalidatePoolHandle, "invalidatePoolHandle");
|
|
10303
10345
|
async function runWithColdStartRetry(firstAttempt, retryAttempt) {
|
|
10304
10346
|
try {
|
|
10305
10347
|
return await firstAttempt();
|
|
@@ -10401,21 +10443,21 @@ function buildProxy(steps, seed, rootCall, gate) {
|
|
|
10401
10443
|
}
|
|
10402
10444
|
__name(buildProxy, "buildProxy");
|
|
10403
10445
|
function replayChain(seed, steps) {
|
|
10404
|
-
let
|
|
10446
|
+
let current3 = seed;
|
|
10405
10447
|
for (const step of steps) {
|
|
10406
|
-
if (
|
|
10448
|
+
if (current3 === null || current3 === void 0) return current3;
|
|
10407
10449
|
if (step.kind === "get") {
|
|
10408
|
-
|
|
10450
|
+
current3 = current3[step.key];
|
|
10409
10451
|
continue;
|
|
10410
10452
|
}
|
|
10411
|
-
const parent =
|
|
10453
|
+
const parent = current3;
|
|
10412
10454
|
const fn = parent[step.key];
|
|
10413
10455
|
if (typeof fn !== "function") {
|
|
10414
10456
|
throw new TypeError(`[stackbone/sdk] cold-start retry could not replay "${step.key}": not a function on the rebuilt handle`);
|
|
10415
10457
|
}
|
|
10416
|
-
|
|
10458
|
+
current3 = fn.apply(parent, step.args);
|
|
10417
10459
|
}
|
|
10418
|
-
return
|
|
10460
|
+
return current3;
|
|
10419
10461
|
}
|
|
10420
10462
|
__name(replayChain, "replayChain");
|
|
10421
10463
|
|
|
@@ -10468,6 +10510,48 @@ var DatabaseModule = class {
|
|
|
10468
10510
|
// a half-baked tx. The contract gate fires before the first attempt.
|
|
10469
10511
|
transaction = /* @__PURE__ */ __name((...args) => withColdStartRetry(() => getDatabaseHandle(this._databaseUrl).transaction(...args), this._gate), "transaction");
|
|
10470
10512
|
/**
|
|
10513
|
+
* Cross-surface raw-SQL runner carrying the SAME cold-start resilience the
|
|
10514
|
+
* query-builder verbs above get. Sibling agent-local surfaces (`approval`,
|
|
10515
|
+
* `config`, `secrets`, `prompts`) that issue tagged-template queries over the
|
|
10516
|
+
* shared postgres-js `Sql` MUST execute them through this instead of caching
|
|
10517
|
+
* `shared().$client` once and calling it directly. Otherwise a dead pooled
|
|
10518
|
+
* socket — Fly Machines suspending the Machine between invokes, or a
|
|
10519
|
+
* WSL2/Docker localhost relay dropping an idle connection during a long LLM
|
|
10520
|
+
* step — surfaces as an unretried `CONNECTION_ENDED`/`ECONNRESET`. That is
|
|
10521
|
+
* exactly the asymmetry that let `client.approval.request` fail while the
|
|
10522
|
+
* `client.database.insert` right before it recovered.
|
|
10523
|
+
*
|
|
10524
|
+
* `fn` receives a FRESH `$client` on each attempt, so the single retry runs
|
|
10525
|
+
* against the rebuilt pool. Whole-operation granularity is replayed as a
|
|
10526
|
+
* unit — pass a multi-statement `sql.begin(...)` transaction or a helper that
|
|
10527
|
+
* fires several queries and the replay re-runs all of it; postgres-js never
|
|
10528
|
+
* commits a half-applied tx, so that is safe. SQLSTATE application errors
|
|
10529
|
+
* pass straight through without a retry. Like `shared()`/`raw()`, the
|
|
10530
|
+
* contract gate is intentionally NOT consulted here — gating surfaces gate at
|
|
10531
|
+
* their own call sites.
|
|
10532
|
+
*/
|
|
10533
|
+
runShared(fn) {
|
|
10534
|
+
return withColdStartRetry(() => fn(getDatabaseHandle(this._databaseUrl).$client));
|
|
10535
|
+
}
|
|
10536
|
+
/**
|
|
10537
|
+
* `Result`-shaped sibling of `runShared` for surfaces whose driver swallows
|
|
10538
|
+
* the dead-socket error into a returned `Result.err.cause` instead of
|
|
10539
|
+
* throwing it — today only `client.rag`, whose `RagPipeline` returns a
|
|
10540
|
+
* `Result` rather than throwing. `attempt` runs once; if it comes back with a
|
|
10541
|
+
* pool-terminated `cause`, the pool is rebuilt and `attempt` replays exactly
|
|
10542
|
+
* once, then its result (success or the fresh error) is returned verbatim.
|
|
10543
|
+
* The `Result` contract is preserved end to end: a still-dead socket on the
|
|
10544
|
+
* replay surfaces as the surface's own `Result.err`, never as a raw throw.
|
|
10545
|
+
*/
|
|
10546
|
+
async runSharedResult(attempt) {
|
|
10547
|
+
const first = await attempt();
|
|
10548
|
+
if (!first.error || !isPoolTerminatedError(first.error.cause)) return first;
|
|
10549
|
+
process.stderr.write(`[stackbone/sdk] database cold-start reconnect: rebuilding pool after ${first.error.cause.code ?? "unknown"}
|
|
10550
|
+
`);
|
|
10551
|
+
invalidatePoolHandle();
|
|
10552
|
+
return attempt();
|
|
10553
|
+
}
|
|
10554
|
+
/**
|
|
10471
10555
|
* Canonical accessor for the **shared-handles pattern**. Returns the
|
|
10472
10556
|
* process-wide Drizzle handle backing `client.database`. Cross-surface
|
|
10473
10557
|
* SDK consumers (RAG today, memory / queues tomorrow) call this — never
|
|
@@ -10569,12 +10653,12 @@ var PromptsFacade = class {
|
|
|
10569
10653
|
const sql = this.sql();
|
|
10570
10654
|
if (sql.error) return err(sql.error);
|
|
10571
10655
|
try {
|
|
10572
|
-
const head = await fetchHead(
|
|
10656
|
+
const head = await this._getDatabase().runShared((db) => fetchHead(db, key));
|
|
10573
10657
|
if (!head) {
|
|
10574
10658
|
return err(notFound(key));
|
|
10575
10659
|
}
|
|
10576
10660
|
if (options?.version !== void 0 && options.version !== head.current_version) {
|
|
10577
|
-
const content = await fetchVersionContent(
|
|
10661
|
+
const content = await this._getDatabase().runShared((db) => fetchVersionContent(db, key, options.version));
|
|
10578
10662
|
if (content === null) {
|
|
10579
10663
|
return err({
|
|
10580
10664
|
code: "prompts_not_found",
|
|
@@ -10625,7 +10709,7 @@ var PromptsFacade = class {
|
|
|
10625
10709
|
const sql = this.sql();
|
|
10626
10710
|
if (sql.error) return err(sql.error);
|
|
10627
10711
|
try {
|
|
10628
|
-
const rows = await
|
|
10712
|
+
const rows = await this._getDatabase().runShared((db) => db`
|
|
10629
10713
|
SELECT p.key, p.name, p.description, p.current_version, p.metadata,
|
|
10630
10714
|
p.created_at, p.updated_at, v.content
|
|
10631
10715
|
FROM stackbone_platform.prompts p
|
|
@@ -10634,7 +10718,7 @@ var PromptsFacade = class {
|
|
|
10634
10718
|
WHERE p.deleted_at IS NULL
|
|
10635
10719
|
ORDER BY p.key
|
|
10636
10720
|
LIMIT ${limit}
|
|
10637
|
-
|
|
10721
|
+
`);
|
|
10638
10722
|
return ok({
|
|
10639
10723
|
items: rows.map((row) => rowToPrompt(row, row.current_version, row.content))
|
|
10640
10724
|
});
|
|
@@ -10661,7 +10745,7 @@ var PromptsFacade = class {
|
|
|
10661
10745
|
if (sql.error) return err(sql.error);
|
|
10662
10746
|
const variables = extractVars(request.template);
|
|
10663
10747
|
try {
|
|
10664
|
-
const head = await
|
|
10748
|
+
const head = await this._getDatabase().runShared((db) => db.begin(async (tx) => {
|
|
10665
10749
|
await tx`
|
|
10666
10750
|
INSERT INTO stackbone_platform.prompts
|
|
10667
10751
|
(key, name, description, current_version, metadata)
|
|
@@ -10689,7 +10773,7 @@ var PromptsFacade = class {
|
|
|
10689
10773
|
WHERE p.key = ${request.key}
|
|
10690
10774
|
`;
|
|
10691
10775
|
return rows[0];
|
|
10692
|
-
});
|
|
10776
|
+
}));
|
|
10693
10777
|
if (!head) {
|
|
10694
10778
|
return err({
|
|
10695
10779
|
code: "prompts_unavailable",
|
|
@@ -10722,7 +10806,7 @@ var PromptsFacade = class {
|
|
|
10722
10806
|
const sql = this.sql();
|
|
10723
10807
|
if (sql.error) return err(sql.error);
|
|
10724
10808
|
try {
|
|
10725
|
-
const head = await
|
|
10809
|
+
const head = await this._getDatabase().runShared((db) => db.begin(async (tx) => {
|
|
10726
10810
|
await tx`SELECT pg_advisory_xact_lock(hashtext(${`prompts:${key}`}))`;
|
|
10727
10811
|
const existing = await tx`
|
|
10728
10812
|
SELECT p.key, p.name, p.description, p.current_version, p.metadata,
|
|
@@ -10733,11 +10817,11 @@ var PromptsFacade = class {
|
|
|
10733
10817
|
WHERE p.key = ${key} AND p.deleted_at IS NULL
|
|
10734
10818
|
LIMIT 1
|
|
10735
10819
|
`;
|
|
10736
|
-
const
|
|
10737
|
-
if (!
|
|
10738
|
-
let nextVersion =
|
|
10820
|
+
const current3 = existing[0];
|
|
10821
|
+
if (!current3) return null;
|
|
10822
|
+
let nextVersion = current3.current_version;
|
|
10739
10823
|
if (options.template !== void 0) {
|
|
10740
|
-
nextVersion =
|
|
10824
|
+
nextVersion = current3.current_version + 1;
|
|
10741
10825
|
const variables = extractVars(options.template);
|
|
10742
10826
|
await tx`
|
|
10743
10827
|
INSERT INTO stackbone_platform.prompt_versions
|
|
@@ -10751,8 +10835,8 @@ var PromptsFacade = class {
|
|
|
10751
10835
|
await tx`
|
|
10752
10836
|
UPDATE stackbone_platform.prompts
|
|
10753
10837
|
SET current_version = ${nextVersion},
|
|
10754
|
-
name = ${options.name ??
|
|
10755
|
-
description = ${options.description !== void 0 ? options.description :
|
|
10838
|
+
name = ${options.name ?? current3.name},
|
|
10839
|
+
description = ${options.description !== void 0 ? options.description : current3.description},
|
|
10756
10840
|
metadata = COALESCE(${options.metadata !== void 0 ? JSON.stringify(options.metadata) : null}::jsonb, metadata),
|
|
10757
10841
|
updated_at = now()
|
|
10758
10842
|
WHERE key = ${key}
|
|
@@ -10766,7 +10850,7 @@ var PromptsFacade = class {
|
|
|
10766
10850
|
WHERE p.key = ${key}
|
|
10767
10851
|
`;
|
|
10768
10852
|
return rows[0] ?? null;
|
|
10769
|
-
});
|
|
10853
|
+
}));
|
|
10770
10854
|
if (head === null) {
|
|
10771
10855
|
return err(notFound(key));
|
|
10772
10856
|
}
|
|
@@ -10781,12 +10865,12 @@ var PromptsFacade = class {
|
|
|
10781
10865
|
const sql = this.sql();
|
|
10782
10866
|
if (sql.error) return err(sql.error);
|
|
10783
10867
|
try {
|
|
10784
|
-
const rows = await
|
|
10868
|
+
const rows = await this._getDatabase().runShared((db) => db`
|
|
10785
10869
|
UPDATE stackbone_platform.prompts
|
|
10786
10870
|
SET deleted_at = now(), updated_at = now()
|
|
10787
10871
|
WHERE key = ${key} AND deleted_at IS NULL
|
|
10788
10872
|
RETURNING key
|
|
10789
|
-
|
|
10873
|
+
`);
|
|
10790
10874
|
const deleted = rows.length;
|
|
10791
10875
|
if (deleted === 0) {
|
|
10792
10876
|
return err(notFound(key));
|
|
@@ -11174,7 +11258,7 @@ async function createDocument(sql, args) {
|
|
|
11174
11258
|
`;
|
|
11175
11259
|
const insertedDoc = await tx`
|
|
11176
11260
|
INSERT INTO stackbone_platform.rag_documents (collection_id, source, content_hash, metadata)
|
|
11177
|
-
VALUES (${collectionId}, ${args.source}, ${args.contentHash}, ${
|
|
11261
|
+
VALUES (${collectionId}, ${args.source}, ${args.contentHash}, ${JSON.stringify(args.metadata)}::jsonb)
|
|
11178
11262
|
RETURNING id
|
|
11179
11263
|
`;
|
|
11180
11264
|
const documentId = insertedDoc[0]?.id;
|
|
@@ -11870,8 +11954,10 @@ var RagModule = class {
|
|
|
11870
11954
|
const sql = this.sql();
|
|
11871
11955
|
if (sql.error) return err(sql.error);
|
|
11872
11956
|
try {
|
|
11873
|
-
await
|
|
11874
|
-
|
|
11957
|
+
await this._getDatabase().runShared(async (db) => {
|
|
11958
|
+
await db`DROP TABLE IF EXISTS rag_chunks`;
|
|
11959
|
+
await db`DROP TABLE IF EXISTS _rag_meta`;
|
|
11960
|
+
});
|
|
11875
11961
|
return ok(void 0);
|
|
11876
11962
|
} catch (cause) {
|
|
11877
11963
|
return err(toRagError(cause, "Reset failed"));
|
|
@@ -11921,13 +12007,15 @@ var RagModule = class {
|
|
|
11921
12007
|
}
|
|
11922
12008
|
}
|
|
11923
12009
|
async withPipeline(embedder, run) {
|
|
11924
|
-
|
|
11925
|
-
|
|
11926
|
-
|
|
11927
|
-
embedder
|
|
11928
|
-
|
|
12010
|
+
return this._getDatabase().runSharedResult(async () => {
|
|
12011
|
+
const pipeline = new RagPipeline({
|
|
12012
|
+
sqlProvider: /* @__PURE__ */ __name(() => this.sql(), "sqlProvider"),
|
|
12013
|
+
...embedder && {
|
|
12014
|
+
embedder
|
|
12015
|
+
}
|
|
12016
|
+
});
|
|
12017
|
+
return await run(pipeline);
|
|
11929
12018
|
});
|
|
11930
|
-
return await run(pipeline);
|
|
11931
12019
|
}
|
|
11932
12020
|
};
|
|
11933
12021
|
function countChunks(request) {
|
|
@@ -15810,12 +15898,12 @@ var SecretsFacade = class {
|
|
|
15810
15898
|
if (sql.error) return err(sql.error);
|
|
15811
15899
|
let rows;
|
|
15812
15900
|
try {
|
|
15813
|
-
rows = await
|
|
15901
|
+
rows = await this._getDatabase().runShared((db) => db`
|
|
15814
15902
|
SELECT version, nonce, ciphertext
|
|
15815
15903
|
FROM stackbone_platform.secrets
|
|
15816
15904
|
WHERE name = ${name}
|
|
15817
15905
|
LIMIT 1
|
|
15818
|
-
|
|
15906
|
+
`);
|
|
15819
15907
|
} catch (cause) {
|
|
15820
15908
|
return err({
|
|
15821
15909
|
code: "secrets_unavailable",
|
|
@@ -15861,11 +15949,11 @@ var SecretsFacade = class {
|
|
|
15861
15949
|
if (sql.error) return err(sql.error);
|
|
15862
15950
|
let rows;
|
|
15863
15951
|
try {
|
|
15864
|
-
rows = await
|
|
15952
|
+
rows = await this._getDatabase().runShared((db) => db`
|
|
15865
15953
|
SELECT name, version, nonce, ciphertext
|
|
15866
15954
|
FROM stackbone_platform.secrets
|
|
15867
15955
|
WHERE name = ANY(${names})
|
|
15868
|
-
|
|
15956
|
+
`);
|
|
15869
15957
|
} catch (cause) {
|
|
15870
15958
|
return err({
|
|
15871
15959
|
code: "secrets_unavailable",
|
|
@@ -15929,6 +16017,99 @@ var SecretsFacade = class {
|
|
|
15929
16017
|
}
|
|
15930
16018
|
}
|
|
15931
16019
|
};
|
|
16020
|
+
function agentRegistry() {
|
|
16021
|
+
const raw = process.env["AGENT_URLS"];
|
|
16022
|
+
if (!raw) {
|
|
16023
|
+
throw new Error("AGENT_URLS is not set. The emulator injects it; run this workflow through `stackbone dev`.");
|
|
16024
|
+
}
|
|
16025
|
+
return JSON.parse(raw);
|
|
16026
|
+
}
|
|
16027
|
+
__name(agentRegistry, "agentRegistry");
|
|
16028
|
+
function resolveAgentHost(name) {
|
|
16029
|
+
const registry = agentRegistry();
|
|
16030
|
+
const host = registry[name];
|
|
16031
|
+
if (!host) {
|
|
16032
|
+
throw new Error(`Unknown agent "${name}". Known agents: ${Object.keys(registry).join(", ")}`);
|
|
16033
|
+
}
|
|
16034
|
+
return host;
|
|
16035
|
+
}
|
|
16036
|
+
__name(resolveAgentHost, "resolveAgentHost");
|
|
16037
|
+
function signWorkflowHeaders() {
|
|
16038
|
+
const secret = process.env["HMAC_SECRET"] ?? "";
|
|
16039
|
+
const timestamp = String(Date.now());
|
|
16040
|
+
const signature = crypto$1.createHmac("sha256", secret).update(timestamp).digest("hex");
|
|
16041
|
+
return {
|
|
16042
|
+
"x-stackbone-timestamp": timestamp,
|
|
16043
|
+
"x-stackbone-workflow-signature": signature
|
|
16044
|
+
};
|
|
16045
|
+
}
|
|
16046
|
+
__name(signWorkflowHeaders, "signWorkflowHeaders");
|
|
16047
|
+
|
|
16048
|
+
// src/surfaces/external/agents/lazy-agent.ts
|
|
16049
|
+
var EVE_CLIENT_MODULE = "eve/client";
|
|
16050
|
+
async function buildEveClient(name) {
|
|
16051
|
+
const host = resolveAgentHost(name);
|
|
16052
|
+
const { Client } = await import(EVE_CLIENT_MODULE);
|
|
16053
|
+
return new Client({
|
|
16054
|
+
host,
|
|
16055
|
+
headers: /* @__PURE__ */ __name(() => signWorkflowHeaders(), "headers")
|
|
16056
|
+
});
|
|
16057
|
+
}
|
|
16058
|
+
__name(buildEveClient, "buildEveClient");
|
|
16059
|
+
function seedSessionState(seed) {
|
|
16060
|
+
if (typeof seed === "string") return {
|
|
16061
|
+
continuationToken: seed,
|
|
16062
|
+
streamIndex: 0
|
|
16063
|
+
};
|
|
16064
|
+
return seed ?? {
|
|
16065
|
+
streamIndex: 0
|
|
16066
|
+
};
|
|
16067
|
+
}
|
|
16068
|
+
__name(seedSessionState, "seedSessionState");
|
|
16069
|
+
function lazyAgentSession(getClient, seed) {
|
|
16070
|
+
const seededState = seedSessionState(seed);
|
|
16071
|
+
let real;
|
|
16072
|
+
let opened;
|
|
16073
|
+
const session = /* @__PURE__ */ __name(() => {
|
|
16074
|
+
real ??= getClient().then((client) => client.session(seed)).then((s2) => {
|
|
16075
|
+
opened = s2;
|
|
16076
|
+
return s2;
|
|
16077
|
+
}).catch((error) => {
|
|
16078
|
+
real = void 0;
|
|
16079
|
+
throw error;
|
|
16080
|
+
});
|
|
16081
|
+
return real;
|
|
16082
|
+
}, "session");
|
|
16083
|
+
return {
|
|
16084
|
+
get state() {
|
|
16085
|
+
return opened ? opened.state : seededState;
|
|
16086
|
+
},
|
|
16087
|
+
async send(input) {
|
|
16088
|
+
return (await session()).send(input);
|
|
16089
|
+
},
|
|
16090
|
+
async *stream(options) {
|
|
16091
|
+
yield* (await session()).stream(options);
|
|
16092
|
+
}
|
|
16093
|
+
};
|
|
16094
|
+
}
|
|
16095
|
+
__name(lazyAgentSession, "lazyAgentSession");
|
|
16096
|
+
function lazyAgent(name) {
|
|
16097
|
+
let client;
|
|
16098
|
+
const getClient = /* @__PURE__ */ __name(() => {
|
|
16099
|
+
client ??= buildEveClient(name).catch((error) => {
|
|
16100
|
+
client = void 0;
|
|
16101
|
+
throw error;
|
|
16102
|
+
});
|
|
16103
|
+
return client;
|
|
16104
|
+
}, "getClient");
|
|
16105
|
+
return {
|
|
16106
|
+
session(state) {
|
|
16107
|
+
return lazyAgentSession(getClient, state);
|
|
16108
|
+
}
|
|
16109
|
+
};
|
|
16110
|
+
}
|
|
16111
|
+
__name(lazyAgent, "lazyAgent");
|
|
16112
|
+
var agent = /* @__PURE__ */ __name((name) => lazyAgent(name), "agent");
|
|
15932
16113
|
var AiModule = class {
|
|
15933
16114
|
static {
|
|
15934
16115
|
__name(this, "AiModule");
|
|
@@ -16259,6 +16440,95 @@ function mapApiError(raw, model) {
|
|
|
16259
16440
|
};
|
|
16260
16441
|
}
|
|
16261
16442
|
__name(mapApiError, "mapApiError");
|
|
16443
|
+
var TIMESTAMP_HEADER = "x-stackbone-timestamp";
|
|
16444
|
+
var SIGNATURE_HEADER2 = "x-stackbone-workflow-signature";
|
|
16445
|
+
function signBrokerHeaders() {
|
|
16446
|
+
const secret = process.env["HMAC_SECRET"] ?? "";
|
|
16447
|
+
const timestamp = String(Date.now());
|
|
16448
|
+
const signature = crypto$1.createHmac("sha256", secret).update(timestamp).digest("hex");
|
|
16449
|
+
return {
|
|
16450
|
+
[TIMESTAMP_HEADER]: timestamp,
|
|
16451
|
+
[SIGNATURE_HEADER2]: signature
|
|
16452
|
+
};
|
|
16453
|
+
}
|
|
16454
|
+
__name(signBrokerHeaders, "signBrokerHeaders");
|
|
16455
|
+
function brokerBaseUrl() {
|
|
16456
|
+
const url = process.env["STACKBONE_API_URL"];
|
|
16457
|
+
if (!url) {
|
|
16458
|
+
throw new Error("STACKBONE_API_URL is not set. The Stackbone runtime injects the broker base URL; run this agent through `stackbone dev`.");
|
|
16459
|
+
}
|
|
16460
|
+
return url.replace(/\/+$/, "");
|
|
16461
|
+
}
|
|
16462
|
+
__name(brokerBaseUrl, "brokerBaseUrl");
|
|
16463
|
+
function installationId() {
|
|
16464
|
+
const id = process.env["STACKBONE_INSTALLATION_ID"];
|
|
16465
|
+
if (!id) {
|
|
16466
|
+
throw new Error("STACKBONE_INSTALLATION_ID is not set. The Stackbone runtime injects it; run this agent through `stackbone dev`.");
|
|
16467
|
+
}
|
|
16468
|
+
return id;
|
|
16469
|
+
}
|
|
16470
|
+
__name(installationId, "installationId");
|
|
16471
|
+
|
|
16472
|
+
// src/surfaces/external/connect/call-connector.ts
|
|
16473
|
+
var EXECUTE_PATH = "/api/connect/execute";
|
|
16474
|
+
function connectorCallError(code, message) {
|
|
16475
|
+
const error = new Error(message);
|
|
16476
|
+
error.code = code;
|
|
16477
|
+
return error;
|
|
16478
|
+
}
|
|
16479
|
+
__name(connectorCallError, "connectorCallError");
|
|
16480
|
+
function errorFromBody(status, body) {
|
|
16481
|
+
if (body && body.ok === false && body.error && typeof body.error.code === "string") {
|
|
16482
|
+
return connectorCallError(body.error.code, body.error.message ?? `Stackbone Connect broker rejected the call (code "${body.error.code}").`);
|
|
16483
|
+
}
|
|
16484
|
+
return connectorCallError("credential_error", `Stackbone Connect broker responded ${status}.`);
|
|
16485
|
+
}
|
|
16486
|
+
__name(errorFromBody, "errorFromBody");
|
|
16487
|
+
async function callConnector(connector, operation, args, opts) {
|
|
16488
|
+
const principal = opts?.principal ?? {
|
|
16489
|
+
type: "app"
|
|
16490
|
+
};
|
|
16491
|
+
const url = `${brokerBaseUrl()}${EXECUTE_PATH}`;
|
|
16492
|
+
const body = JSON.stringify({
|
|
16493
|
+
connector,
|
|
16494
|
+
operation,
|
|
16495
|
+
args: args ?? {},
|
|
16496
|
+
principal,
|
|
16497
|
+
installationId: installationId()
|
|
16498
|
+
});
|
|
16499
|
+
let response;
|
|
16500
|
+
try {
|
|
16501
|
+
response = await fetch(url, {
|
|
16502
|
+
method: "POST",
|
|
16503
|
+
headers: {
|
|
16504
|
+
"content-type": "application/json",
|
|
16505
|
+
...signBrokerHeaders()
|
|
16506
|
+
},
|
|
16507
|
+
body
|
|
16508
|
+
});
|
|
16509
|
+
} catch (cause) {
|
|
16510
|
+
throw connectorCallError("execute_failed", `Stackbone Connect broker is unreachable: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
16511
|
+
}
|
|
16512
|
+
const parsed = await response.json().catch(() => null);
|
|
16513
|
+
if (!response.ok || parsed && parsed.ok === false) {
|
|
16514
|
+
throw errorFromBody(response.status, parsed ?? null);
|
|
16515
|
+
}
|
|
16516
|
+
if (!parsed || parsed.ok !== true) {
|
|
16517
|
+
throw connectorCallError("invalid_output", "Stackbone Connect broker returned a malformed execute response.");
|
|
16518
|
+
}
|
|
16519
|
+
return parsed.output;
|
|
16520
|
+
}
|
|
16521
|
+
__name(callConnector, "callConnector");
|
|
16522
|
+
var connectorHandle = /* @__PURE__ */ __name((id) => new Proxy(/* @__PURE__ */ Object.create(null), {
|
|
16523
|
+
get(_target, prop) {
|
|
16524
|
+
if (typeof prop !== "string" || prop === "then") return void 0;
|
|
16525
|
+
if (prop === "call") {
|
|
16526
|
+
return (operation, args, opts) => callConnector(id, operation, args, opts);
|
|
16527
|
+
}
|
|
16528
|
+
return (args, opts) => callConnector(id, prop, args, opts);
|
|
16529
|
+
}
|
|
16530
|
+
}), "connectorHandle");
|
|
16531
|
+
var connection = /* @__PURE__ */ __name((id) => connectorHandle(id), "connection");
|
|
16262
16532
|
var R2_ENDPOINT_HOST_SUFFIX = ".r2.cloudflarestorage.com";
|
|
16263
16533
|
function createS3CompatClient(options) {
|
|
16264
16534
|
return new clientS3.S3Client({
|
|
@@ -16688,6 +16958,8 @@ var QueuesModule = class {
|
|
|
16688
16958
|
this._http = _http;
|
|
16689
16959
|
this._gate = gate ?? createModuleGate("queues", resolved);
|
|
16690
16960
|
}
|
|
16961
|
+
/** @deprecated Classic v2 only. Prefer `startWorkflow(name, input)` from
|
|
16962
|
+
* `@stackbone/sdk/workflow` (a job → a workflow run on the World). */
|
|
16691
16963
|
async publish(request) {
|
|
16692
16964
|
return withGate(this._gate, async () => {
|
|
16693
16965
|
const body = {
|
|
@@ -16706,6 +16978,8 @@ var QueuesModule = class {
|
|
|
16706
16978
|
});
|
|
16707
16979
|
});
|
|
16708
16980
|
}
|
|
16981
|
+
/** @deprecated Classic v2 only. Prefer `scheduleWorkflow(name, input, cron)`
|
|
16982
|
+
* from `@stackbone/sdk/workflow` (a cron → a workflow run on the World). */
|
|
16709
16983
|
async schedule(request) {
|
|
16710
16984
|
return withGate(this._gate, async () => {
|
|
16711
16985
|
const body = {
|
|
@@ -16724,6 +16998,8 @@ var QueuesModule = class {
|
|
|
16724
16998
|
});
|
|
16725
16999
|
});
|
|
16726
17000
|
}
|
|
17001
|
+
/** @deprecated Classic v2 only. Prefer `unschedule(name)` from
|
|
17002
|
+
* `@stackbone/sdk/workflow`. */
|
|
16727
17003
|
async unschedule(request) {
|
|
16728
17004
|
return withGate(this._gate, async () => this._http.request({
|
|
16729
17005
|
method: "POST",
|
|
@@ -16735,6 +17011,8 @@ var QueuesModule = class {
|
|
|
16735
17011
|
errorMapping: ERROR_MAPPING2
|
|
16736
17012
|
}));
|
|
16737
17013
|
}
|
|
17014
|
+
/** @deprecated Classic v2 only. Prefer `listSchedules()` from
|
|
17015
|
+
* `@stackbone/sdk/workflow`. */
|
|
16738
17016
|
async listSchedules() {
|
|
16739
17017
|
return withGate(this._gate, async () => this._http.request({
|
|
16740
17018
|
method: "GET",
|
|
@@ -16759,7 +17037,7 @@ var StackboneClient = class {
|
|
|
16759
17037
|
_secrets;
|
|
16760
17038
|
_config;
|
|
16761
17039
|
_queues;
|
|
16762
|
-
|
|
17040
|
+
_legacyConnections;
|
|
16763
17041
|
_memory;
|
|
16764
17042
|
_prompts;
|
|
16765
17043
|
_httpClient;
|
|
@@ -16813,16 +17091,59 @@ var StackboneClient = class {
|
|
|
16813
17091
|
return this._queues;
|
|
16814
17092
|
}
|
|
16815
17093
|
/**
|
|
16816
|
-
*
|
|
16817
|
-
* `list` / `invoke` make
|
|
16818
|
-
*
|
|
17094
|
+
* Legacy surface — the agent's handle on the workspace's connector connections
|
|
17095
|
+
* under the OLD connector model. `list` / `invoke(connector, action, args)` make
|
|
17096
|
+
* authenticated calls to the control-plane connectors proxy
|
|
17097
|
+
* (`/api/v1/agent/connections/*`); the credentials never enter the agent
|
|
16819
17098
|
* container. Gated against `connections.actions` so the handshake-blocked /
|
|
16820
17099
|
* capability-missing paths are exercised the same way as the other gated
|
|
16821
17100
|
* surfaces.
|
|
17101
|
+
*
|
|
17102
|
+
* Named `legacyConnections` (not `connections`) so it no longer sits one letter
|
|
17103
|
+
* from the new peer-free `connection(id)` entrypoint above — the two connector
|
|
17104
|
+
* entrypoints are now unambiguous. Behaviour is unchanged from the old
|
|
17105
|
+
* `connections` member.
|
|
16822
17106
|
*/
|
|
16823
|
-
get
|
|
16824
|
-
this.
|
|
16825
|
-
return this.
|
|
17107
|
+
get legacyConnections() {
|
|
17108
|
+
this._legacyConnections ??= new ConnectionsModule(this.resolved, this.http(), createModuleGate("connections", this.resolved, this._contractStore));
|
|
17109
|
+
return this._legacyConnections;
|
|
17110
|
+
}
|
|
17111
|
+
/**
|
|
17112
|
+
* Peer-free connector entrypoint — `stackbone.connection(id)` selects a Stackbone
|
|
17113
|
+
* Connect connector by its verbatim id and returns a typed handle whose generated
|
|
17114
|
+
* operations (`.sendMail({ ... })`, typed via the `StackboneConnections` registry)
|
|
17115
|
+
* and dynamic `.call(operation, args)` escape hatch both resolve to the same broker
|
|
17116
|
+
* call (`POST /api/connect/execute`, HMAC scheme A). It is a plain HMAC fetch — it
|
|
17117
|
+
* imports NO `eve` peer — so it is wired directly onto the client with no lazy
|
|
17118
|
+
* loading and pulls no new peer into the main barrel.
|
|
17119
|
+
*
|
|
17120
|
+
* This is the namespaced form of the top-level `connection(...)` export (now
|
|
17121
|
+
* `@deprecated`); both delegate to the same implementation. Distinct from the
|
|
17122
|
+
* plural `connections` surface above, which is the control-plane connectors proxy
|
|
17123
|
+
* (`list` / `invoke`).
|
|
17124
|
+
*/
|
|
17125
|
+
get connection() {
|
|
17126
|
+
return connection;
|
|
17127
|
+
}
|
|
17128
|
+
/**
|
|
17129
|
+
* Namespaced sibling-agent entrypoint — `stackbone.agent(id)` selects a sibling
|
|
17130
|
+
* eve agent by its verbatim name and returns a lazy eve `Client`, so a workflow
|
|
17131
|
+
* step delegates with `stackbone.agent('support').session().send({ ... })`. The
|
|
17132
|
+
* name is typed against the augmentable `AgentRegistry` (declared names
|
|
17133
|
+
* autocomplete, a typo is a compile error).
|
|
17134
|
+
*
|
|
17135
|
+
* Peer isolation is load-bearing: selecting the agent and opening a session are
|
|
17136
|
+
* synchronous and import NO `eve` peer — only the session's already-async leaves
|
|
17137
|
+
* (`send` / `stream`) resolve `eve/client` via dynamic import on first use. So a
|
|
17138
|
+
* tool-only agent that imports `@stackbone/sdk` and never calls `agent(...)` never
|
|
17139
|
+
* eager-loads the optional `eve` peer and cannot crash-loop on a missing dep.
|
|
17140
|
+
*
|
|
17141
|
+
* This is the namespaced form of the top-level `eveAgent(...)` export (now
|
|
17142
|
+
* `@deprecated`) on the `@stackbone/sdk/workflow` subpath; both produce the same
|
|
17143
|
+
* signed workflow→agent call and the same eve `Client` API.
|
|
17144
|
+
*/
|
|
17145
|
+
get agent() {
|
|
17146
|
+
return agent;
|
|
16826
17147
|
}
|
|
16827
17148
|
/**
|
|
16828
17149
|
* Pending surface — runtime not built. Every method returns
|
|
@@ -16991,7 +17312,9 @@ var SDK_ERROR_CODE_PREFIXES = {
|
|
|
16991
17312
|
"unavailable"
|
|
16992
17313
|
],
|
|
16993
17314
|
/**
|
|
16994
|
-
* `client.
|
|
17315
|
+
* `client.legacyConnections` — the agent → control plane connectors proxy
|
|
17316
|
+
* (legacy connector model). The `connections_*` code prefix stays stable (it
|
|
17317
|
+
* names the wire domain, not the client accessor). Both
|
|
16995
17318
|
* methods (`list`, `invoke`) hit the `/api/v1/agent/connections/*` endpoints
|
|
16996
17319
|
* over `HttpClient`, so the full status→domain remap (`connections_unauthorized`,
|
|
16997
17320
|
* `connections_not_found`, `connections_unavailable`, …) is in play. The agent
|
|
@@ -17172,6 +17495,9 @@ function assertCapabilityShape(name, capability) {
|
|
|
17172
17495
|
}
|
|
17173
17496
|
__name(assertCapabilityShape, "assertCapabilityShape");
|
|
17174
17497
|
|
|
17498
|
+
// src/runtime/define-workspace.ts
|
|
17499
|
+
var defineWorkspace = /* @__PURE__ */ __name((workspace) => workspace, "defineWorkspace");
|
|
17500
|
+
|
|
17175
17501
|
// src/runtime/logger.ts
|
|
17176
17502
|
var writeLine = /* @__PURE__ */ __name((stream, level, msg, bindings, meta, now) => {
|
|
17177
17503
|
const record = {
|
|
@@ -17209,6 +17535,65 @@ function getInvocationContext() {
|
|
|
17209
17535
|
return storage.getStore();
|
|
17210
17536
|
}
|
|
17211
17537
|
__name(getInvocationContext, "getInvocationContext");
|
|
17538
|
+
function runWithCallerId(id, fn, options) {
|
|
17539
|
+
const context = {
|
|
17540
|
+
runId: id,
|
|
17541
|
+
invocationId: options?.invocationId ?? id,
|
|
17542
|
+
// Only attach `handler` when supplied: `exactOptionalPropertyTypes` forbids
|
|
17543
|
+
// an explicit `undefined` on an optional property.
|
|
17544
|
+
...options?.handler !== void 0 ? {
|
|
17545
|
+
handler: options.handler
|
|
17546
|
+
} : {}
|
|
17547
|
+
};
|
|
17548
|
+
return runWithInvocationContext(context, fn);
|
|
17549
|
+
}
|
|
17550
|
+
__name(runWithCallerId, "runWithCallerId");
|
|
17551
|
+
|
|
17552
|
+
// src/runtime/workflow-starter.ts
|
|
17553
|
+
var current;
|
|
17554
|
+
function setWorkflowStarter(starter) {
|
|
17555
|
+
current = starter;
|
|
17556
|
+
}
|
|
17557
|
+
__name(setWorkflowStarter, "setWorkflowStarter");
|
|
17558
|
+
function getWorkflowStarter() {
|
|
17559
|
+
if (!current) {
|
|
17560
|
+
throw new Error("No workflow starter is bound. `startWorkflow` / `startWorkflowAndWait` can only be called from inside a running workflow \u2014 the runtime binds the starter on its first dispatch.");
|
|
17561
|
+
}
|
|
17562
|
+
return current;
|
|
17563
|
+
}
|
|
17564
|
+
__name(getWorkflowStarter, "getWorkflowStarter");
|
|
17565
|
+
|
|
17566
|
+
// src/runtime/workflow-scheduler.ts
|
|
17567
|
+
var current2;
|
|
17568
|
+
function setWorkflowScheduler(scheduler) {
|
|
17569
|
+
current2 = scheduler;
|
|
17570
|
+
}
|
|
17571
|
+
__name(setWorkflowScheduler, "setWorkflowScheduler");
|
|
17572
|
+
function getWorkflowScheduler() {
|
|
17573
|
+
if (!current2) {
|
|
17574
|
+
throw new Error("No workflow scheduler is bound. `scheduleWorkflow` / `unschedule` / `listSchedules` can only be called inside a running workflow runtime \u2014 the runtime binds the scheduler on its first dispatch.");
|
|
17575
|
+
}
|
|
17576
|
+
return current2;
|
|
17577
|
+
}
|
|
17578
|
+
__name(getWorkflowScheduler, "getWorkflowScheduler");
|
|
17579
|
+
|
|
17580
|
+
// src/runtime/ambient-client.ts
|
|
17581
|
+
var cached;
|
|
17582
|
+
function resolveAmbientClient() {
|
|
17583
|
+
cached ??= createClient();
|
|
17584
|
+
return cached;
|
|
17585
|
+
}
|
|
17586
|
+
__name(resolveAmbientClient, "resolveAmbientClient");
|
|
17587
|
+
var stackbone = new Proxy({}, {
|
|
17588
|
+
get(_target, prop) {
|
|
17589
|
+
const client = resolveAmbientClient();
|
|
17590
|
+
const value = Reflect.get(client, prop, client);
|
|
17591
|
+
return typeof value === "function" ? value.bind(client) : value;
|
|
17592
|
+
},
|
|
17593
|
+
has(_target, prop) {
|
|
17594
|
+
return Reflect.has(resolveAmbientClient(), prop);
|
|
17595
|
+
}
|
|
17596
|
+
});
|
|
17212
17597
|
var patched = /* @__PURE__ */ new WeakSet();
|
|
17213
17598
|
function installInvocationConsoleCapture(options = {}) {
|
|
17214
17599
|
const target = options.console ?? console;
|
|
@@ -17274,9 +17659,7 @@ var STORED_TO_SDK_ENV = {
|
|
|
17274
17659
|
S3_REGION: "STACKBONE_S3_REGION",
|
|
17275
17660
|
// OpenRouter (`client.ai`) — identity.
|
|
17276
17661
|
OPENROUTER_API_KEY: "OPENROUTER_API_KEY",
|
|
17277
|
-
OPENROUTER_BASE_URL: "OPENROUTER_BASE_URL"
|
|
17278
|
-
// Axiom (observability) — identity.
|
|
17279
|
-
AXIOM_TOKEN: "AXIOM_TOKEN"
|
|
17662
|
+
OPENROUTER_BASE_URL: "OPENROUTER_BASE_URL"
|
|
17280
17663
|
};
|
|
17281
17664
|
function rehydrateSystemSecretsRows(env, rows, cipher, databaseUrl) {
|
|
17282
17665
|
const applied = [];
|
|
@@ -17520,13 +17903,20 @@ exports.analyzeAgentSchemas = analyzeAgentSchemas;
|
|
|
17520
17903
|
exports.createClient = createClient;
|
|
17521
17904
|
exports.createStructuredLogger = createStructuredLogger;
|
|
17522
17905
|
exports.defineAgent = defineAgent;
|
|
17906
|
+
exports.defineWorkspace = defineWorkspace;
|
|
17523
17907
|
exports.getInvocationContext = getInvocationContext;
|
|
17908
|
+
exports.getWorkflowScheduler = getWorkflowScheduler;
|
|
17909
|
+
exports.getWorkflowStarter = getWorkflowStarter;
|
|
17524
17910
|
exports.installInvocationConsoleCapture = installInvocationConsoleCapture;
|
|
17525
17911
|
exports.invokeRequestSchema = invokeRequestSchema;
|
|
17526
17912
|
exports.isReservedErrorCode = isReservedErrorCode;
|
|
17527
17913
|
exports.isSdkErrorCode = isSdkErrorCode;
|
|
17528
17914
|
exports.loadSystemSecretsIntoEnv = loadSystemSecretsIntoEnv;
|
|
17529
17915
|
exports.rehydrateSystemSecretsRows = rehydrateSystemSecretsRows;
|
|
17916
|
+
exports.runWithCallerId = runWithCallerId;
|
|
17530
17917
|
exports.runWithInvocationContext = runWithInvocationContext;
|
|
17918
|
+
exports.setWorkflowScheduler = setWorkflowScheduler;
|
|
17919
|
+
exports.setWorkflowStarter = setWorkflowStarter;
|
|
17920
|
+
exports.stackbone = stackbone;
|
|
17531
17921
|
//# sourceMappingURL=index.cjs.map
|
|
17532
17922
|
//# sourceMappingURL=index.cjs.map
|