@alook/daemon 0.1.49 → 0.1.51
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/README.md +7 -5
- package/dist/cli/index.js +642 -166
- package/dist/index.js +642 -166
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -19499,7 +19499,7 @@ __export(exports_community_machine_schema, {
|
|
|
19499
19499
|
DIAGNOSTIC_REPORT_FAILURE_CODES: () => DIAGNOSTIC_REPORT_FAILURE_CODES
|
|
19500
19500
|
});
|
|
19501
19501
|
|
|
19502
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19502
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/entity.js
|
|
19503
19503
|
var entityKind = Symbol.for("drizzle:entityKind");
|
|
19504
19504
|
var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
19505
19505
|
function is(value, type) {
|
|
@@ -19524,7 +19524,7 @@ function is(value, type) {
|
|
|
19524
19524
|
return false;
|
|
19525
19525
|
}
|
|
19526
19526
|
|
|
19527
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19527
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/column.js
|
|
19528
19528
|
class Column {
|
|
19529
19529
|
constructor(table, config2) {
|
|
19530
19530
|
this.table = table;
|
|
@@ -19574,7 +19574,7 @@ class Column {
|
|
|
19574
19574
|
}
|
|
19575
19575
|
}
|
|
19576
19576
|
|
|
19577
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19577
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/column-builder.js
|
|
19578
19578
|
class ColumnBuilder {
|
|
19579
19579
|
static [entityKind] = "ColumnBuilder";
|
|
19580
19580
|
config;
|
|
@@ -19630,20 +19630,20 @@ class ColumnBuilder {
|
|
|
19630
19630
|
}
|
|
19631
19631
|
}
|
|
19632
19632
|
|
|
19633
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19633
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/table.utils.js
|
|
19634
19634
|
var TableName = Symbol.for("drizzle:Name");
|
|
19635
19635
|
|
|
19636
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19636
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/tracing-utils.js
|
|
19637
19637
|
function iife(fn, ...args) {
|
|
19638
19638
|
return fn(...args);
|
|
19639
19639
|
}
|
|
19640
19640
|
|
|
19641
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19641
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/pg-core/unique-constraint.js
|
|
19642
19642
|
function uniqueKeyName(table, columns) {
|
|
19643
19643
|
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
19644
19644
|
}
|
|
19645
19645
|
|
|
19646
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19646
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/pg-core/columns/common.js
|
|
19647
19647
|
class PgColumn extends Column {
|
|
19648
19648
|
constructor(table, config2) {
|
|
19649
19649
|
if (!config2.uniqueName) {
|
|
@@ -19692,7 +19692,7 @@ class ExtraConfigColumn extends PgColumn {
|
|
|
19692
19692
|
}
|
|
19693
19693
|
}
|
|
19694
19694
|
|
|
19695
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19695
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
19696
19696
|
class PgEnumObjectColumn extends PgColumn {
|
|
19697
19697
|
static [entityKind] = "PgEnumObjectColumn";
|
|
19698
19698
|
enum;
|
|
@@ -19722,7 +19722,7 @@ class PgEnumColumn extends PgColumn {
|
|
|
19722
19722
|
}
|
|
19723
19723
|
}
|
|
19724
19724
|
|
|
19725
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19725
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/subquery.js
|
|
19726
19726
|
class Subquery {
|
|
19727
19727
|
static [entityKind] = "Subquery";
|
|
19728
19728
|
constructor(sql, fields, alias, isWith = false, usedTables = []) {
|
|
@@ -19737,10 +19737,10 @@ class Subquery {
|
|
|
19737
19737
|
}
|
|
19738
19738
|
}
|
|
19739
19739
|
|
|
19740
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19741
|
-
var version2 = "0.45.
|
|
19740
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/version.js
|
|
19741
|
+
var version2 = "0.45.4";
|
|
19742
19742
|
|
|
19743
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19743
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/tracing.js
|
|
19744
19744
|
var otel;
|
|
19745
19745
|
var rawTracer;
|
|
19746
19746
|
var tracer = {
|
|
@@ -19767,10 +19767,10 @@ var tracer = {
|
|
|
19767
19767
|
}
|
|
19768
19768
|
};
|
|
19769
19769
|
|
|
19770
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19770
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/view-common.js
|
|
19771
19771
|
var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
19772
19772
|
|
|
19773
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19773
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/table.js
|
|
19774
19774
|
var Schema = Symbol.for("drizzle:Schema");
|
|
19775
19775
|
var Columns = Symbol.for("drizzle:Columns");
|
|
19776
19776
|
var ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
@@ -19808,7 +19808,7 @@ class Table {
|
|
|
19808
19808
|
}
|
|
19809
19809
|
}
|
|
19810
19810
|
|
|
19811
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
19811
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sql/sql.js
|
|
19812
19812
|
function isSQLWrapper(value) {
|
|
19813
19813
|
return value !== null && value !== undefined && typeof value.getSQL === "function";
|
|
19814
19814
|
}
|
|
@@ -20171,7 +20171,7 @@ Subquery.prototype.getSQL = function() {
|
|
|
20171
20171
|
return new SQL([this]);
|
|
20172
20172
|
};
|
|
20173
20173
|
|
|
20174
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20174
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/alias.js
|
|
20175
20175
|
class ColumnAliasProxyHandler {
|
|
20176
20176
|
constructor(table) {
|
|
20177
20177
|
this.table = table;
|
|
@@ -20227,12 +20227,12 @@ class TableAliasProxyHandler {
|
|
|
20227
20227
|
}
|
|
20228
20228
|
}
|
|
20229
20229
|
|
|
20230
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20230
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/alias.js
|
|
20231
20231
|
function alias(table, alias2) {
|
|
20232
20232
|
return new Proxy(table, new TableAliasProxyHandler(alias2, false));
|
|
20233
20233
|
}
|
|
20234
20234
|
|
|
20235
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20235
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/checks.js
|
|
20236
20236
|
class CheckBuilder {
|
|
20237
20237
|
constructor(name, value) {
|
|
20238
20238
|
this.name = name;
|
|
@@ -20259,7 +20259,7 @@ function check2(name, value) {
|
|
|
20259
20259
|
return new CheckBuilder(name, value);
|
|
20260
20260
|
}
|
|
20261
20261
|
|
|
20262
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20262
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/utils.js
|
|
20263
20263
|
function getColumnNameAndConfig(a, b) {
|
|
20264
20264
|
return {
|
|
20265
20265
|
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
@@ -20268,7 +20268,7 @@ function getColumnNameAndConfig(a, b) {
|
|
|
20268
20268
|
}
|
|
20269
20269
|
var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder;
|
|
20270
20270
|
|
|
20271
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20271
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
|
|
20272
20272
|
class ForeignKeyBuilder {
|
|
20273
20273
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
20274
20274
|
reference;
|
|
@@ -20336,7 +20336,7 @@ function foreignKey(config2) {
|
|
|
20336
20336
|
return new ForeignKeyBuilder(mappedConfig);
|
|
20337
20337
|
}
|
|
20338
20338
|
|
|
20339
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20339
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/unique-constraint.js
|
|
20340
20340
|
function uniqueKeyName2(table, columns) {
|
|
20341
20341
|
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
20342
20342
|
}
|
|
@@ -20381,7 +20381,7 @@ class UniqueConstraint {
|
|
|
20381
20381
|
}
|
|
20382
20382
|
}
|
|
20383
20383
|
|
|
20384
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20384
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/common.js
|
|
20385
20385
|
class SQLiteColumnBuilder extends ColumnBuilder {
|
|
20386
20386
|
static [entityKind] = "SQLiteColumnBuilder";
|
|
20387
20387
|
foreignKeyConfigs = [];
|
|
@@ -20432,7 +20432,7 @@ class SQLiteColumn extends Column {
|
|
|
20432
20432
|
static [entityKind] = "SQLiteColumn";
|
|
20433
20433
|
}
|
|
20434
20434
|
|
|
20435
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20435
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/blob.js
|
|
20436
20436
|
class SQLiteBigIntBuilder extends SQLiteColumnBuilder {
|
|
20437
20437
|
static [entityKind] = "SQLiteBigIntBuilder";
|
|
20438
20438
|
constructor(name) {
|
|
@@ -20520,7 +20520,7 @@ function blob(a, b) {
|
|
|
20520
20520
|
return new SQLiteBlobBufferBuilder(name);
|
|
20521
20521
|
}
|
|
20522
20522
|
|
|
20523
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20523
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/custom.js
|
|
20524
20524
|
class SQLiteCustomColumnBuilder extends SQLiteColumnBuilder {
|
|
20525
20525
|
static [entityKind] = "SQLiteCustomColumnBuilder";
|
|
20526
20526
|
constructor(name, fieldConfig, customTypeParams) {
|
|
@@ -20561,7 +20561,7 @@ function customType(customTypeParams) {
|
|
|
20561
20561
|
};
|
|
20562
20562
|
}
|
|
20563
20563
|
|
|
20564
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20564
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/integer.js
|
|
20565
20565
|
class SQLiteBaseIntegerBuilder extends SQLiteColumnBuilder {
|
|
20566
20566
|
static [entityKind] = "SQLiteBaseIntegerBuilder";
|
|
20567
20567
|
constructor(name, dataType, columnType) {
|
|
@@ -20663,7 +20663,7 @@ function integer2(a, b) {
|
|
|
20663
20663
|
return new SQLiteIntegerBuilder(name);
|
|
20664
20664
|
}
|
|
20665
20665
|
|
|
20666
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20666
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
|
|
20667
20667
|
class SQLiteNumericBuilder extends SQLiteColumnBuilder {
|
|
20668
20668
|
static [entityKind] = "SQLiteNumericBuilder";
|
|
20669
20669
|
constructor(name) {
|
|
@@ -20733,7 +20733,7 @@ function numeric(a, b) {
|
|
|
20733
20733
|
return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
|
|
20734
20734
|
}
|
|
20735
20735
|
|
|
20736
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20736
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/real.js
|
|
20737
20737
|
class SQLiteRealBuilder extends SQLiteColumnBuilder {
|
|
20738
20738
|
static [entityKind] = "SQLiteRealBuilder";
|
|
20739
20739
|
constructor(name) {
|
|
@@ -20754,7 +20754,7 @@ function real(name) {
|
|
|
20754
20754
|
return new SQLiteRealBuilder(name ?? "");
|
|
20755
20755
|
}
|
|
20756
20756
|
|
|
20757
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20757
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/text.js
|
|
20758
20758
|
class SQLiteTextBuilder extends SQLiteColumnBuilder {
|
|
20759
20759
|
static [entityKind] = "SQLiteTextBuilder";
|
|
20760
20760
|
constructor(name, config2) {
|
|
@@ -20809,7 +20809,7 @@ function text(a, b = {}) {
|
|
|
20809
20809
|
return new SQLiteTextBuilder(name, config2);
|
|
20810
20810
|
}
|
|
20811
20811
|
|
|
20812
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20812
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/all.js
|
|
20813
20813
|
function getSQLiteColumnBuilders() {
|
|
20814
20814
|
return {
|
|
20815
20815
|
blob,
|
|
@@ -20821,7 +20821,7 @@ function getSQLiteColumnBuilders() {
|
|
|
20821
20821
|
};
|
|
20822
20822
|
}
|
|
20823
20823
|
|
|
20824
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20824
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/table.js
|
|
20825
20825
|
var InlineForeignKeys = Symbol.for("drizzle:SQLiteInlineForeignKeys");
|
|
20826
20826
|
|
|
20827
20827
|
class SQLiteTable extends Table {
|
|
@@ -20855,7 +20855,7 @@ var sqliteTable = (name, columns, extraConfig) => {
|
|
|
20855
20855
|
return sqliteTableBase(name, columns, extraConfig);
|
|
20856
20856
|
};
|
|
20857
20857
|
|
|
20858
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20858
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/indexes.js
|
|
20859
20859
|
class IndexBuilderOn {
|
|
20860
20860
|
constructor(name, unique2) {
|
|
20861
20861
|
this.name = name;
|
|
@@ -20901,7 +20901,7 @@ function uniqueIndex(name) {
|
|
|
20901
20901
|
return new IndexBuilderOn(name, true);
|
|
20902
20902
|
}
|
|
20903
20903
|
|
|
20904
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20904
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/primary-keys.js
|
|
20905
20905
|
function primaryKey(...config2) {
|
|
20906
20906
|
if (config2[0].columns) {
|
|
20907
20907
|
return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
|
|
@@ -20936,7 +20936,7 @@ class PrimaryKey {
|
|
|
20936
20936
|
}
|
|
20937
20937
|
}
|
|
20938
20938
|
|
|
20939
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20939
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
20940
20940
|
function bindIfParam(value, column) {
|
|
20941
20941
|
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
20942
20942
|
return new Param(value, column);
|
|
@@ -20964,7 +20964,7 @@ function isNotNull(value) {
|
|
|
20964
20964
|
return sql`${value} is not null`;
|
|
20965
20965
|
}
|
|
20966
20966
|
|
|
20967
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
20967
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sql/expressions/select.js
|
|
20968
20968
|
function desc(column) {
|
|
20969
20969
|
return sql`${column} desc`;
|
|
20970
20970
|
}
|
|
@@ -24953,46 +24953,8 @@ var communityFunnelAnalyticsEvent = sqliteTable("community_funnel_analytics_even
|
|
|
24953
24953
|
index("idx_community_funnel_analytics_owner_claimed_created").on(t.ownerUserId, t.claimedAt, t.createdAt)
|
|
24954
24954
|
]);
|
|
24955
24955
|
|
|
24956
|
-
// ../shared/src/db/product-analytics-schema.ts
|
|
24957
|
-
var exports_product_analytics_schema = {};
|
|
24958
|
-
__export(exports_product_analytics_schema, {
|
|
24959
|
-
productAnalyticsEvent: () => productAnalyticsEvent,
|
|
24960
|
-
PRODUCT_ANALYTICS_EVENTS: () => PRODUCT_ANALYTICS_EVENTS
|
|
24961
|
-
});
|
|
24962
|
-
var PRODUCT_ANALYTICS_EVENTS = [
|
|
24963
|
-
"landing_cta_clicked",
|
|
24964
|
-
"login_page_view",
|
|
24965
|
-
"sign_up",
|
|
24966
|
-
"sign_in_success",
|
|
24967
|
-
"sign_in_failed",
|
|
24968
|
-
"onboarding_enter_clicked",
|
|
24969
|
-
"onboarding_first_message",
|
|
24970
|
-
"invitation_link_visit"
|
|
24971
|
-
];
|
|
24972
|
-
var productAnalyticsEvent = sqliteTable("product_analytics_event", {
|
|
24973
|
-
id: text("id").primaryKey(),
|
|
24974
|
-
eventName: text("event_name").notNull().$type(),
|
|
24975
|
-
actorUserId: text("actor_user_id").references(() => user.id, { onDelete: "cascade" }),
|
|
24976
|
-
serverId: text("server_id").references(() => communityServer.id, { onDelete: "cascade" }),
|
|
24977
|
-
sourceId: text("source_id"),
|
|
24978
|
-
dedupeKey: text("dedupe_key").notNull(),
|
|
24979
|
-
clientId: text("client_id").notNull(),
|
|
24980
|
-
sessionId: text("session_id").notNull(),
|
|
24981
|
-
method: text("method"),
|
|
24982
|
-
accountKind: text("account_kind").$type(),
|
|
24983
|
-
ctaName: text("cta_name"),
|
|
24984
|
-
failureStage: text("failure_stage").$type(),
|
|
24985
|
-
createdAt: text("created_at").notNull(),
|
|
24986
|
-
deliveryStatus: text("delivery_status").notNull().default("pending").$type(),
|
|
24987
|
-
deliveryReason: text("delivery_reason"),
|
|
24988
|
-
attemptedAt: text("attempted_at")
|
|
24989
|
-
}, (t) => [
|
|
24990
|
-
uniqueIndex("uq_product_analytics_dedupe").on(t.dedupeKey),
|
|
24991
|
-
index("idx_product_analytics_actor_server_event").on(t.actorUserId, t.serverId, t.eventName)
|
|
24992
|
-
]);
|
|
24993
|
-
|
|
24994
24956
|
// ../shared/src/db/index.ts
|
|
24995
|
-
var allSchema = { ...exports_schema, ...exports_community_schema, ...exports_community_machine_schema, ...exports_product_plan_schema, ...exports_billing_schema, ...exports_community_funnel_analytics_schema
|
|
24957
|
+
var allSchema = { ...exports_schema, ...exports_community_schema, ...exports_community_machine_schema, ...exports_product_plan_schema, ...exports_billing_schema, ...exports_community_funnel_analytics_schema };
|
|
24996
24958
|
// ../shared/src/community-server-rail.ts
|
|
24997
24959
|
var MAX_SERVER_RAIL_COMMANDS = 3;
|
|
24998
24960
|
var idSchema = exports_external.string().trim().min(1);
|
|
@@ -32594,14 +32556,16 @@ class OpenCodeServiceLane {
|
|
|
32594
32556
|
if (!this.identity || this.identity.generation !== generation || this.isProcessClosed(this.identity.process)) {
|
|
32595
32557
|
if (/EADDRINUSE|address already in use/i.test(this.stderrBuffer))
|
|
32596
32558
|
throw new OpenCodePortBindError("OpenCode service port bind raced");
|
|
32597
|
-
|
|
32559
|
+
const process2 = this.identity?.process;
|
|
32560
|
+
const detail = scrubDriverErrorMessage(this.stderrBuffer.replaceAll(this.password, "[redacted]"), "no native stderr");
|
|
32561
|
+
throw new Error(`OpenCode service exited before readiness (code=${process2?.exitCode ?? "unknown"}, signal=${process2?.signalCode ?? "none"}): ${detail}`);
|
|
32598
32562
|
}
|
|
32599
32563
|
try {
|
|
32600
32564
|
const healthTimeoutMs = Math.max(1, Math.min(1000, deadline - Date.now(), this.options.requestTimeoutMs ?? REQUEST_TIMEOUT_MS));
|
|
32601
|
-
const { response, body } = await this.fetchJsonWithTimeout(
|
|
32565
|
+
const { response, body } = await this.fetchJsonWithTimeout(this.healthPath, { method: "GET" }, "health", healthTimeoutMs);
|
|
32602
32566
|
if (response.ok) {
|
|
32603
32567
|
const health = record5(body);
|
|
32604
|
-
if (health
|
|
32568
|
+
if (!this.acceptsHealth(health)) {
|
|
32605
32569
|
throw new OpenCodeIncompatibleError("Installed OpenCode service did not report healthy status");
|
|
32606
32570
|
}
|
|
32607
32571
|
await this.verifyOpenApi();
|
|
@@ -32618,12 +32582,27 @@ class OpenCodeServiceLane {
|
|
|
32618
32582
|
throw new Error("OpenCode service readiness timed out");
|
|
32619
32583
|
}
|
|
32620
32584
|
async verifyOpenApi() {
|
|
32621
|
-
const { response, body } = await this.fetchJsonWithTimeout(
|
|
32585
|
+
const { response, body } = await this.fetchJsonWithTimeout(this.openApiPath, { method: "GET" }, "OpenAPI");
|
|
32622
32586
|
if (!response.ok)
|
|
32623
32587
|
throw new OpenCodeIncompatibleError("Installed OpenCode service does not expose its OpenAPI document");
|
|
32624
32588
|
const document = record5(body);
|
|
32625
32589
|
const paths = record5(document?.paths);
|
|
32626
|
-
const required2 =
|
|
32590
|
+
const required2 = this.requiredApiPaths;
|
|
32591
|
+
if (!paths || required2.some((path10) => !record5(paths[path10]))) {
|
|
32592
|
+
throw new OpenCodeIncompatibleError("Installed OpenCode service is missing required session capabilities");
|
|
32593
|
+
}
|
|
32594
|
+
}
|
|
32595
|
+
get healthPath() {
|
|
32596
|
+
return "/global/health";
|
|
32597
|
+
}
|
|
32598
|
+
get openApiPath() {
|
|
32599
|
+
return "/doc";
|
|
32600
|
+
}
|
|
32601
|
+
acceptsHealth(health) {
|
|
32602
|
+
return health?.healthy === true;
|
|
32603
|
+
}
|
|
32604
|
+
get requiredApiPaths() {
|
|
32605
|
+
return [
|
|
32627
32606
|
"/api/session",
|
|
32628
32607
|
"/api/session/active",
|
|
32629
32608
|
"/api/session/{sessionID}/prompt",
|
|
@@ -32635,12 +32614,12 @@ class OpenCodeServiceLane {
|
|
|
32635
32614
|
"/api/session/{sessionID}/permission/{requestID}/reply",
|
|
32636
32615
|
"/api/event"
|
|
32637
32616
|
];
|
|
32638
|
-
|
|
32639
|
-
|
|
32640
|
-
|
|
32617
|
+
}
|
|
32618
|
+
get selectedModel() {
|
|
32619
|
+
return parseModelRef(resolveLaunchFieldsOrDefault(this.ctx.config.runtimeConfig).model);
|
|
32641
32620
|
}
|
|
32642
32621
|
async openSession(resumeId) {
|
|
32643
|
-
const model =
|
|
32622
|
+
const model = this.selectedModel;
|
|
32644
32623
|
if (resumeId) {
|
|
32645
32624
|
const { response: response2, body: body2 } = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(resumeId)}`, { method: "GET" }, "session resume");
|
|
32646
32625
|
if (response2.status === 404) {
|
|
@@ -32983,7 +32962,7 @@ class OpenCodeServiceLane {
|
|
|
32983
32962
|
async handleLiveEvent(value) {
|
|
32984
32963
|
const event = record5(value);
|
|
32985
32964
|
const data = record5(event?.data);
|
|
32986
|
-
if (event?.type !==
|
|
32965
|
+
if (event?.type !== this.permissionEventType || data?.sessionID !== this.sessionId)
|
|
32987
32966
|
return;
|
|
32988
32967
|
if (typeof data.id !== "string" || !/^per/.test(data.id)) {
|
|
32989
32968
|
throw new OpenCodeProtocolError("OpenCode emitted a malformed permission request");
|
|
@@ -33006,13 +32985,19 @@ class OpenCodeServiceLane {
|
|
|
33006
32985
|
}
|
|
33007
32986
|
}
|
|
33008
32987
|
}
|
|
32988
|
+
get permissionEventType() {
|
|
32989
|
+
return "permission.v2.asked";
|
|
32990
|
+
}
|
|
32991
|
+
get permissionReply() {
|
|
32992
|
+
return { reply: "once" };
|
|
32993
|
+
}
|
|
33009
32994
|
async replyPermission(requestId) {
|
|
33010
32995
|
if (this.handledPermissions.has(requestId))
|
|
33011
32996
|
return;
|
|
33012
32997
|
const existing = this.permissionFlights.get(requestId);
|
|
33013
32998
|
if (existing)
|
|
33014
32999
|
return existing;
|
|
33015
|
-
const flight = this.requestNoContent(`/api/session/${encodeURIComponent(this.sessionId)}/permission/${encodeURIComponent(requestId)}/reply`, "POST",
|
|
33000
|
+
const flight = this.requestNoContent(`/api/session/${encodeURIComponent(this.sessionId)}/permission/${encodeURIComponent(requestId)}/reply`, "POST", this.permissionReply, "permission reply").catch((error62) => {
|
|
33016
33001
|
if (!(error62 instanceof OpenCodeHttpError) || error62.status !== 404)
|
|
33017
33002
|
throw error62;
|
|
33018
33003
|
}).then(() => {
|
|
@@ -33389,6 +33374,28 @@ async function legacyOpenCodeApiEnvironment(environment, model) {
|
|
|
33389
33374
|
return credential?.type === "api" && typeof credential.key === "string" && credential.key.trim() ? { [name]: credential.key } : {};
|
|
33390
33375
|
}
|
|
33391
33376
|
|
|
33377
|
+
// agent-driver/dist/adapters/opencode/compatibility.js
|
|
33378
|
+
var OPEN_CODE_V1 = {
|
|
33379
|
+
major: 1,
|
|
33380
|
+
modelArgs: ["models", "--pure"],
|
|
33381
|
+
serviceArgs: ["serve", "--pure"],
|
|
33382
|
+
sessionListArgs: (maxCount) => ["session", "list", "--format", "json", "--max-count", String(maxCount), "--pure"]
|
|
33383
|
+
};
|
|
33384
|
+
var OPEN_CODE_V2 = {
|
|
33385
|
+
major: 2,
|
|
33386
|
+
modelArgs: ["models", "--standalone"],
|
|
33387
|
+
serviceArgs: ["serve"],
|
|
33388
|
+
sessionListArgs: (maxCount) => ["api", "--standalone", "GET", `/api/session?parentID=null&order=desc&limit=${maxCount}`]
|
|
33389
|
+
};
|
|
33390
|
+
function resolveOpenCodeCompatibility(version3) {
|
|
33391
|
+
const match = version3?.trim().match(/^(?:opencode\s+)?v?(\d+)\.\d+\.\d+(?:[-+][\w.-]+)?$/i);
|
|
33392
|
+
if (match?.[1] === "1")
|
|
33393
|
+
return OPEN_CODE_V1;
|
|
33394
|
+
if (match?.[1] === "2")
|
|
33395
|
+
return OPEN_CODE_V2;
|
|
33396
|
+
throw new Error("Installed OpenCode CLI version is unrecognized or has an unsupported major version");
|
|
33397
|
+
}
|
|
33398
|
+
|
|
33392
33399
|
// agent-driver/dist/adapters/opencode/recent-context.js
|
|
33393
33400
|
var OPENCODE_DISCOVERY_TIMEOUT_MS = 15000;
|
|
33394
33401
|
var OPENCODE_DISCOVERY_OUTPUT_MAX_BYTES = 4 * 1024 * 1024;
|
|
@@ -33422,6 +33429,7 @@ async function discoverOpenCodeRecentContext(request, dependencies = {}) {
|
|
|
33422
33429
|
const collector = new RecentContextCollector(request, "unavailable");
|
|
33423
33430
|
if (collector.satisfied)
|
|
33424
33431
|
return collector.result();
|
|
33432
|
+
const compatibility = dependencies.compatibility ?? OPEN_CODE_V1;
|
|
33425
33433
|
const startedAt = Date.now();
|
|
33426
33434
|
const timeoutMs = dependencies.timeoutMs ?? OPENCODE_DISCOVERY_TIMEOUT_MS;
|
|
33427
33435
|
let remainingOutputBytes = dependencies.outputMaxBytes ?? OPENCODE_DISCOVERY_OUTPUT_MAX_BYTES;
|
|
@@ -33430,7 +33438,7 @@ async function discoverOpenCodeRecentContext(request, dependencies = {}) {
|
|
|
33430
33438
|
const remainingTimeoutMs = timeoutMs - (Date.now() - startedAt);
|
|
33431
33439
|
if (remainingTimeoutMs <= 0)
|
|
33432
33440
|
throw new Error("OpenCode discovery timed out");
|
|
33433
|
-
const spec = resolveSpawnSpec("opencode", [
|
|
33441
|
+
const spec = resolveSpawnSpec("opencode", [...compatibility.sessionListArgs(maxCount)], request.command);
|
|
33434
33442
|
const commandOutput = await collectCommandOutput(spec.command, spec.args, spec.shell, dependencies, remainingTimeoutMs, remainingOutputBytes);
|
|
33435
33443
|
remainingOutputBytes -= commandOutput.outputBytes;
|
|
33436
33444
|
let parsed;
|
|
@@ -33439,14 +33447,17 @@ async function discoverOpenCodeRecentContext(request, dependencies = {}) {
|
|
|
33439
33447
|
} catch {
|
|
33440
33448
|
throw new Error("OpenCode session listing returned invalid JSON");
|
|
33441
33449
|
}
|
|
33450
|
+
if (compatibility.major === 2)
|
|
33451
|
+
parsed = asRecord(parsed)?.data;
|
|
33442
33452
|
if (!Array.isArray(parsed))
|
|
33443
33453
|
throw new Error("OpenCode session listing returned an invalid response");
|
|
33444
33454
|
for (const value of parsed) {
|
|
33445
33455
|
const session2 = asRecord(value);
|
|
33446
33456
|
if (!session2)
|
|
33447
33457
|
continue;
|
|
33448
|
-
const modifiedAt = session2.updated ?? session2.updatedAt;
|
|
33449
|
-
|
|
33458
|
+
const modifiedAt = compatibility.major === 2 ? asRecord(session2.time)?.updated : session2.updated ?? session2.updatedAt;
|
|
33459
|
+
const projectPath = compatibility.major === 2 ? asRecord(session2.location)?.directory : session2.directory;
|
|
33460
|
+
collector.add({ projectPath, modifiedAt });
|
|
33450
33461
|
}
|
|
33451
33462
|
if (collector.satisfied || parsed.length < maxCount)
|
|
33452
33463
|
break;
|
|
@@ -33458,6 +33469,419 @@ async function discoverOpenCodeRecentContext(request, dependencies = {}) {
|
|
|
33458
33469
|
return collector.result();
|
|
33459
33470
|
}
|
|
33460
33471
|
|
|
33472
|
+
// agent-driver/dist/adapters/opencode/v2-service-lane.js
|
|
33473
|
+
class OpenCodeV2ServiceLane extends OpenCodeServiceLane {
|
|
33474
|
+
root = null;
|
|
33475
|
+
v2AdmissionTail = Promise.resolve();
|
|
33476
|
+
v2EvaluationTimer;
|
|
33477
|
+
v2Evaluating = false;
|
|
33478
|
+
projectedMessages = new Set;
|
|
33479
|
+
liveTools = new Map;
|
|
33480
|
+
settledTools = new Set;
|
|
33481
|
+
usage = new SettledUsageProjector;
|
|
33482
|
+
get healthPath() {
|
|
33483
|
+
return "/api/info";
|
|
33484
|
+
}
|
|
33485
|
+
get openApiPath() {
|
|
33486
|
+
return "/openapi.json";
|
|
33487
|
+
}
|
|
33488
|
+
acceptsHealth(health) {
|
|
33489
|
+
if (typeof health?.version !== "string" || !Number.isInteger(health.pid) || Number(health.pid) < 1)
|
|
33490
|
+
return false;
|
|
33491
|
+
try {
|
|
33492
|
+
return resolveOpenCodeCompatibility(health.version).major === 2;
|
|
33493
|
+
} catch {
|
|
33494
|
+
return false;
|
|
33495
|
+
}
|
|
33496
|
+
}
|
|
33497
|
+
get requiredApiPaths() {
|
|
33498
|
+
return [
|
|
33499
|
+
"/api/session",
|
|
33500
|
+
"/api/session/active",
|
|
33501
|
+
"/api/session/{sessionID}",
|
|
33502
|
+
"/api/session/{sessionID}/prompt",
|
|
33503
|
+
"/api/session/{sessionID}/inbox",
|
|
33504
|
+
"/api/session/{sessionID}/message",
|
|
33505
|
+
"/api/session/{sessionID}/message/{messageID}",
|
|
33506
|
+
"/api/session/{sessionID}/interrupt",
|
|
33507
|
+
"/api/session/{sessionID}/model",
|
|
33508
|
+
"/api/session/{sessionID}/permission",
|
|
33509
|
+
"/api/session/{sessionID}/permission/{requestID}/reply",
|
|
33510
|
+
"/api/event"
|
|
33511
|
+
];
|
|
33512
|
+
}
|
|
33513
|
+
get selectedModel() {
|
|
33514
|
+
const model = super.selectedModel;
|
|
33515
|
+
if (typeof model?.id !== "string")
|
|
33516
|
+
return model;
|
|
33517
|
+
const hash2 = model.id.lastIndexOf("#");
|
|
33518
|
+
return hash2 > 0 && hash2 < model.id.length - 1 ? { ...model, id: model.id.slice(0, hash2), variant: model.id.slice(hash2 + 1) } : model;
|
|
33519
|
+
}
|
|
33520
|
+
get permissionEventType() {
|
|
33521
|
+
return "permission.asked";
|
|
33522
|
+
}
|
|
33523
|
+
get permissionReply() {
|
|
33524
|
+
return { decision: "once" };
|
|
33525
|
+
}
|
|
33526
|
+
protocolFailure(message2, cause) {
|
|
33527
|
+
super.protocolFailure(cause === undefined ? message2 : `${message2}: ${scrubDriverErrorMessage(cause)}`);
|
|
33528
|
+
}
|
|
33529
|
+
async primeHistory() {}
|
|
33530
|
+
startStreams() {
|
|
33531
|
+
const identity = this.identity;
|
|
33532
|
+
this.liveTask = this.runLiveStream(identity).catch((error62) => {
|
|
33533
|
+
if (!this.stopping)
|
|
33534
|
+
this.protocolFailure("OpenCode CLI v2 live stream failed", error62);
|
|
33535
|
+
});
|
|
33536
|
+
}
|
|
33537
|
+
async recoverPendingPermissions() {
|
|
33538
|
+
await super.recoverPendingPermissions();
|
|
33539
|
+
const root = this.root;
|
|
33540
|
+
if (root)
|
|
33541
|
+
for (const message2 of await this.messagesAfter(root))
|
|
33542
|
+
this.projectTools(message2);
|
|
33543
|
+
this.schedule();
|
|
33544
|
+
}
|
|
33545
|
+
async handleLiveEvent(value) {
|
|
33546
|
+
await super.handleLiveEvent(value);
|
|
33547
|
+
const event = record5(value);
|
|
33548
|
+
const data = record5(event?.data);
|
|
33549
|
+
if (data?.sessionID !== this.sessionId || !this.root)
|
|
33550
|
+
return;
|
|
33551
|
+
switch (event?.type) {
|
|
33552
|
+
case "session.step.started":
|
|
33553
|
+
this.events.emit("runtime_event", {
|
|
33554
|
+
kind: "internal_progress",
|
|
33555
|
+
source: "opencode.service",
|
|
33556
|
+
itemType: "step_started"
|
|
33557
|
+
});
|
|
33558
|
+
break;
|
|
33559
|
+
case "session.tool.input.started": {
|
|
33560
|
+
const key = this.toolKey(data.assistantMessageID, data.id);
|
|
33561
|
+
if (key && typeof data.name === "string" && !this.liveTools.has(key) && !this.settledTools.has(key)) {
|
|
33562
|
+
this.liveTools.set(key, { name: data.name, called: false });
|
|
33563
|
+
}
|
|
33564
|
+
break;
|
|
33565
|
+
}
|
|
33566
|
+
case "session.tool.called":
|
|
33567
|
+
this.projectTool(data);
|
|
33568
|
+
break;
|
|
33569
|
+
case "session.tool.success":
|
|
33570
|
+
case "session.tool.failed": {
|
|
33571
|
+
this.finishTool(this.toolKey(data.assistantMessageID, data.id));
|
|
33572
|
+
break;
|
|
33573
|
+
}
|
|
33574
|
+
case "session.compaction.started":
|
|
33575
|
+
this.events.emit("runtime_event", { kind: "compaction_started" });
|
|
33576
|
+
break;
|
|
33577
|
+
case "session.compaction.failed":
|
|
33578
|
+
case "session.compaction.ended":
|
|
33579
|
+
this.events.emit("runtime_event", { kind: "compaction_finished" });
|
|
33580
|
+
break;
|
|
33581
|
+
default:
|
|
33582
|
+
break;
|
|
33583
|
+
}
|
|
33584
|
+
this.schedule();
|
|
33585
|
+
}
|
|
33586
|
+
async send(input2) {
|
|
33587
|
+
if (!this.ready || this.stopping || !this.sessionId || !this.identityMatches())
|
|
33588
|
+
return { ok: false, reason: "closed" };
|
|
33589
|
+
if (input2.mode === "idle") {
|
|
33590
|
+
if (this.root)
|
|
33591
|
+
return { ok: false, reason: "runtime_busy" };
|
|
33592
|
+
return this.beginRoot(input2);
|
|
33593
|
+
}
|
|
33594
|
+
const root = this.root;
|
|
33595
|
+
if (!root)
|
|
33596
|
+
return { ok: false, reason: "not_ready" };
|
|
33597
|
+
return this.admit(input2.text, "steer", this.newMessageId(), root);
|
|
33598
|
+
}
|
|
33599
|
+
async beginRoot(input2) {
|
|
33600
|
+
const page = await this.messagePage(undefined, 1);
|
|
33601
|
+
if (this.stopping || !this.identityMatches())
|
|
33602
|
+
return { ok: false, reason: "closed" };
|
|
33603
|
+
const receipt = input2.terminalOwner?.startsWith("msg_") ? input2.terminalOwner : this.newMessageId();
|
|
33604
|
+
const root = {
|
|
33605
|
+
receipt,
|
|
33606
|
+
baseline: typeof page.data[0]?.id === "string" ? page.data[0].id : null,
|
|
33607
|
+
inputs: new Set,
|
|
33608
|
+
generation: 0,
|
|
33609
|
+
pending: 0
|
|
33610
|
+
};
|
|
33611
|
+
this.root = root;
|
|
33612
|
+
return this.admit(input2.text, "queue", receipt, root);
|
|
33613
|
+
}
|
|
33614
|
+
admit(text2, delivery, id3, root) {
|
|
33615
|
+
root.generation += 1;
|
|
33616
|
+
root.pending += 1;
|
|
33617
|
+
const run = this.v2AdmissionTail.then(async () => {
|
|
33618
|
+
await this.waitForLiveStream();
|
|
33619
|
+
if (this.root !== root || this.stopping || !this.identityMatches())
|
|
33620
|
+
return { ok: false, reason: "closed" };
|
|
33621
|
+
const { response, body } = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(this.sessionId)}/prompt`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: id3, text: text2, delivery, resume: true }) }, "prompt admission");
|
|
33622
|
+
if (!response.ok)
|
|
33623
|
+
throw new OpenCodeHttpError(response.status, "prompt admission");
|
|
33624
|
+
const input2 = record5(record5(body)?.data);
|
|
33625
|
+
if (input2?.id !== id3 || input2.sessionID !== this.sessionId || input2.type !== "user" || input2.delivery !== delivery) {
|
|
33626
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid prompt receipt");
|
|
33627
|
+
}
|
|
33628
|
+
if (this.root !== root || this.stopping || !this.identityMatches())
|
|
33629
|
+
return { ok: false, reason: "closed" };
|
|
33630
|
+
root.inputs.add(id3);
|
|
33631
|
+
return { ok: true, acceptedAs: delivery === "steer" ? "steer" : "prompt", receipt: id3 };
|
|
33632
|
+
}).catch((error62) => {
|
|
33633
|
+
if (this.root === root && !this.stopping)
|
|
33634
|
+
this.protocolFailure("OpenCode CLI v2 prompt admission failed", error62);
|
|
33635
|
+
throw error62;
|
|
33636
|
+
}).finally(() => {
|
|
33637
|
+
root.pending -= 1;
|
|
33638
|
+
this.schedule();
|
|
33639
|
+
});
|
|
33640
|
+
this.v2AdmissionTail = run.then(() => {}, () => {});
|
|
33641
|
+
return run;
|
|
33642
|
+
}
|
|
33643
|
+
async messagePage(cursor, limit = 100) {
|
|
33644
|
+
const query = new URLSearchParams({ limit: String(limit), ...cursor ? { cursor } : { order: "desc" } });
|
|
33645
|
+
const { response, body } = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(this.sessionId)}/message?${query}`, { method: "GET" }, "message recovery");
|
|
33646
|
+
if (!response.ok)
|
|
33647
|
+
throw new OpenCodeHttpError(response.status, "message recovery");
|
|
33648
|
+
const page = record5(body);
|
|
33649
|
+
const cursors = record5(page?.cursor);
|
|
33650
|
+
if (!Array.isArray(page?.data) || !cursors || page.data.some((item) => typeof record5(item)?.id !== "string")) {
|
|
33651
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid message page");
|
|
33652
|
+
}
|
|
33653
|
+
if (cursors.next !== undefined && cursors.next !== null && typeof cursors.next !== "string")
|
|
33654
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid message cursor");
|
|
33655
|
+
return { data: page.data, next: typeof cursors.next === "string" ? cursors.next : undefined };
|
|
33656
|
+
}
|
|
33657
|
+
async messagesAfter(root) {
|
|
33658
|
+
const messages = [];
|
|
33659
|
+
const cursors = new Set;
|
|
33660
|
+
let cursor;
|
|
33661
|
+
for (;; ) {
|
|
33662
|
+
const page = await this.messagePage(cursor);
|
|
33663
|
+
if (this.root !== root || this.stopping)
|
|
33664
|
+
return [];
|
|
33665
|
+
for (const message2 of page.data) {
|
|
33666
|
+
if (message2.id === root.baseline)
|
|
33667
|
+
return messages.reverse();
|
|
33668
|
+
messages.push(message2);
|
|
33669
|
+
}
|
|
33670
|
+
if (!page.next) {
|
|
33671
|
+
if (root.baseline !== null)
|
|
33672
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 message recovery lost its root boundary");
|
|
33673
|
+
return messages.reverse();
|
|
33674
|
+
}
|
|
33675
|
+
if (cursors.has(page.next))
|
|
33676
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 message cursor did not advance");
|
|
33677
|
+
cursors.add(page.next);
|
|
33678
|
+
cursor = page.next;
|
|
33679
|
+
}
|
|
33680
|
+
}
|
|
33681
|
+
schedule() {
|
|
33682
|
+
if (!this.root || this.stopping || this.v2EvaluationTimer || this.v2Evaluating)
|
|
33683
|
+
return;
|
|
33684
|
+
this.v2EvaluationTimer = setTimeout(() => {
|
|
33685
|
+
this.v2EvaluationTimer = undefined;
|
|
33686
|
+
this.evaluate();
|
|
33687
|
+
}, this.options.activePollMs ?? 100);
|
|
33688
|
+
this.v2EvaluationTimer.unref?.();
|
|
33689
|
+
}
|
|
33690
|
+
async isActive() {
|
|
33691
|
+
const { response, body } = await this.fetchJsonWithTimeout("/api/session/active", { method: "GET" }, "active session query");
|
|
33692
|
+
if (!response.ok)
|
|
33693
|
+
throw new OpenCodeHttpError(response.status, "active session query");
|
|
33694
|
+
const active = record5(record5(body)?.data);
|
|
33695
|
+
if (!active)
|
|
33696
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned invalid active session data");
|
|
33697
|
+
return active[this.sessionId] !== undefined;
|
|
33698
|
+
}
|
|
33699
|
+
async evaluate() {
|
|
33700
|
+
const root = this.root;
|
|
33701
|
+
const identity = this.identity;
|
|
33702
|
+
if (!root || !identity || this.stopping || root.pending > 0 || root.inputs.size === 0 || this.v2Evaluating)
|
|
33703
|
+
return;
|
|
33704
|
+
this.v2Evaluating = true;
|
|
33705
|
+
const generation = root.generation;
|
|
33706
|
+
const current = () => this.root === root && root.generation === generation && root.pending === 0 && this.isIdentity(identity);
|
|
33707
|
+
try {
|
|
33708
|
+
if (await this.isActive())
|
|
33709
|
+
return;
|
|
33710
|
+
if (!current())
|
|
33711
|
+
return;
|
|
33712
|
+
const messages = await this.messagesAfter(root);
|
|
33713
|
+
if (!current())
|
|
33714
|
+
return;
|
|
33715
|
+
let lastInput = -1;
|
|
33716
|
+
const delivered = new Set;
|
|
33717
|
+
for (const [index2, message2] of messages.entries()) {
|
|
33718
|
+
if (message2.type === "user" && typeof message2.id === "string" && root.inputs.has(message2.id)) {
|
|
33719
|
+
delivered.add(message2.id);
|
|
33720
|
+
lastInput = index2;
|
|
33721
|
+
}
|
|
33722
|
+
}
|
|
33723
|
+
const idle = messages.slice(lastInput + 1).reverse().find((message2) => message2.type === "idle");
|
|
33724
|
+
if (delivered.size !== root.inputs.size) {
|
|
33725
|
+
const { response, body } = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(this.sessionId)}/inbox`, { method: "GET" }, "pending input recovery");
|
|
33726
|
+
if (!response.ok)
|
|
33727
|
+
throw new OpenCodeHttpError(response.status, "pending input recovery");
|
|
33728
|
+
const pending = record5(body)?.data;
|
|
33729
|
+
if (!Array.isArray(pending))
|
|
33730
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned invalid inbox data");
|
|
33731
|
+
if (!current())
|
|
33732
|
+
return;
|
|
33733
|
+
const retained = new Set(pending.map((item) => record5(item)?.id));
|
|
33734
|
+
for (const id3 of root.inputs) {
|
|
33735
|
+
if (delivered.has(id3) || retained.has(id3))
|
|
33736
|
+
continue;
|
|
33737
|
+
const recovered = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(this.sessionId)}/message/${encodeURIComponent(id3)}`, { method: "GET" }, "accepted input recovery");
|
|
33738
|
+
if (!current())
|
|
33739
|
+
return;
|
|
33740
|
+
if (recovered.response.status === 404)
|
|
33741
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 lost an accepted input from both inbox and messages");
|
|
33742
|
+
if (!recovered.response.ok)
|
|
33743
|
+
throw new OpenCodeHttpError(recovered.response.status, "accepted input recovery");
|
|
33744
|
+
const message2 = record5(record5(recovered.body)?.data);
|
|
33745
|
+
if (message2?.id !== id3 || message2.type !== "user")
|
|
33746
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid recovered input");
|
|
33747
|
+
}
|
|
33748
|
+
return;
|
|
33749
|
+
}
|
|
33750
|
+
for (const message2 of messages) {
|
|
33751
|
+
this.projectTools(message2);
|
|
33752
|
+
this.projectMessage(message2);
|
|
33753
|
+
}
|
|
33754
|
+
if (!idle || await this.isActive() || !current())
|
|
33755
|
+
return;
|
|
33756
|
+
if (!["succeeded", "failed", "interrupted"].includes(String(idle.outcome))) {
|
|
33757
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid idle outcome");
|
|
33758
|
+
}
|
|
33759
|
+
this.root = null;
|
|
33760
|
+
if (idle.outcome === "failed") {
|
|
33761
|
+
const error62 = record5(idle.error);
|
|
33762
|
+
this.events.emit("runtime_event", {
|
|
33763
|
+
kind: "error",
|
|
33764
|
+
code: "opencode.turn_failed",
|
|
33765
|
+
message: typeof error62?.message === "string" ? error62.message : "OpenCode CLI v2 execution failed"
|
|
33766
|
+
});
|
|
33767
|
+
}
|
|
33768
|
+
this.events.emit("runtime_event", {
|
|
33769
|
+
kind: "turn_end",
|
|
33770
|
+
sessionId: this.sessionId,
|
|
33771
|
+
turnOwner: root.receipt
|
|
33772
|
+
});
|
|
33773
|
+
} catch (error62) {
|
|
33774
|
+
if (!current() || this.stopping)
|
|
33775
|
+
return;
|
|
33776
|
+
if (error62 instanceof OpenCodeProtocolError || error62 instanceof OpenCodeHttpError && error62.status < 500) {
|
|
33777
|
+
this.protocolFailure("OpenCode CLI v2 durable message recovery failed", error62);
|
|
33778
|
+
} else
|
|
33779
|
+
this.diagnostic("warning", "OpenCode CLI v2 message recovery temporarily unavailable; keeping the root active");
|
|
33780
|
+
} finally {
|
|
33781
|
+
this.v2Evaluating = false;
|
|
33782
|
+
this.schedule();
|
|
33783
|
+
}
|
|
33784
|
+
}
|
|
33785
|
+
toolKey(messageId, id3) {
|
|
33786
|
+
return typeof messageId === "string" && typeof id3 === "string" ? `${messageId}:${id3}` : undefined;
|
|
33787
|
+
}
|
|
33788
|
+
projectTool(data) {
|
|
33789
|
+
const key = this.toolKey(data.assistantMessageID, data.id);
|
|
33790
|
+
if (!key || this.settledTools.has(key))
|
|
33791
|
+
return;
|
|
33792
|
+
const tool = this.liveTools.get(key) ?? { name: typeof data.name === "string" ? data.name : "OpenCode tool", called: false };
|
|
33793
|
+
if (tool.called)
|
|
33794
|
+
return;
|
|
33795
|
+
tool.called = true;
|
|
33796
|
+
this.liveTools.set(key, tool);
|
|
33797
|
+
this.events.emit("runtime_event", { kind: "tool_call", callId: key, name: tool.name, input: data.input });
|
|
33798
|
+
}
|
|
33799
|
+
finishTool(key) {
|
|
33800
|
+
if (!key || this.settledTools.has(key))
|
|
33801
|
+
return;
|
|
33802
|
+
const tool = this.liveTools.get(key);
|
|
33803
|
+
if (!tool?.called)
|
|
33804
|
+
return;
|
|
33805
|
+
this.liveTools.delete(key);
|
|
33806
|
+
this.settledTools.add(key);
|
|
33807
|
+
this.events.emit("runtime_event", { kind: "tool_output", callId: key, name: tool.name });
|
|
33808
|
+
}
|
|
33809
|
+
projectTools(message2) {
|
|
33810
|
+
if (message2.type !== "assistant" || !Array.isArray(message2.content) || !this.root || this.stopping)
|
|
33811
|
+
return;
|
|
33812
|
+
for (const value of message2.content) {
|
|
33813
|
+
const tool = record5(value);
|
|
33814
|
+
const state = record5(tool?.state);
|
|
33815
|
+
if (tool?.type !== "tool" || !["running", "completed", "error"].includes(String(state?.status)))
|
|
33816
|
+
continue;
|
|
33817
|
+
this.projectTool({ assistantMessageID: message2.id, id: tool.id, name: tool.name, input: state?.input });
|
|
33818
|
+
if (state?.status !== "running")
|
|
33819
|
+
this.finishTool(this.toolKey(message2.id, tool.id));
|
|
33820
|
+
}
|
|
33821
|
+
}
|
|
33822
|
+
projectMessage(message2) {
|
|
33823
|
+
if (message2.type !== "assistant" || typeof message2.id !== "string" || this.projectedMessages.has(message2.id))
|
|
33824
|
+
return;
|
|
33825
|
+
const time3 = record5(message2.time);
|
|
33826
|
+
if (time3?.completed === undefined)
|
|
33827
|
+
return;
|
|
33828
|
+
this.projectedMessages.add(message2.id);
|
|
33829
|
+
if (Array.isArray(message2.content))
|
|
33830
|
+
for (const value of message2.content) {
|
|
33831
|
+
const content = record5(value);
|
|
33832
|
+
if (typeof content?.text !== "string" || !content.text)
|
|
33833
|
+
continue;
|
|
33834
|
+
if (content.type === "text")
|
|
33835
|
+
this.events.emit("runtime_event", { kind: "assistant_message_completed", text: content.text });
|
|
33836
|
+
if (content.type === "reasoning")
|
|
33837
|
+
this.events.emit("runtime_event", { kind: "assistant_reasoning_completed", text: content.text });
|
|
33838
|
+
}
|
|
33839
|
+
const tokens = record5(message2.tokens);
|
|
33840
|
+
if (!tokens || !this.sessionId)
|
|
33841
|
+
return;
|
|
33842
|
+
const cache = record5(tokens.cache);
|
|
33843
|
+
const identity = { runtime: "opencode", backendSessionId: this.sessionId, providerRecordId: message2.id };
|
|
33844
|
+
const usage = this.usage.project({
|
|
33845
|
+
...identity,
|
|
33846
|
+
source: "opencode.v2",
|
|
33847
|
+
input: tokens.input,
|
|
33848
|
+
output: tokens.output,
|
|
33849
|
+
reasoning: tokens.reasoning,
|
|
33850
|
+
cacheRead: cache?.read,
|
|
33851
|
+
cacheWrite: cache?.write,
|
|
33852
|
+
inputIncludesCache: false,
|
|
33853
|
+
outputIncludesReasoning: false
|
|
33854
|
+
});
|
|
33855
|
+
if (usage)
|
|
33856
|
+
this.events.emit("runtime_event", usage);
|
|
33857
|
+
this.usage.release(identity);
|
|
33858
|
+
}
|
|
33859
|
+
async interrupt(_input) {
|
|
33860
|
+
const root = this.root;
|
|
33861
|
+
if (!root || !this.ready || this.stopping || !this.identityMatches())
|
|
33862
|
+
return false;
|
|
33863
|
+
root.generation += 1;
|
|
33864
|
+
root.pending += 1;
|
|
33865
|
+
try {
|
|
33866
|
+
await this.requestNoContent(`/api/session/${encodeURIComponent(this.sessionId)}/interrupt?resume=false`, "POST", undefined, "session interrupt");
|
|
33867
|
+
return true;
|
|
33868
|
+
} catch (error62) {
|
|
33869
|
+
if (!this.stopping)
|
|
33870
|
+
this.stop({ reason: "interrupt_timeout", forceAfterMs: 0 });
|
|
33871
|
+
throw error62;
|
|
33872
|
+
} finally {
|
|
33873
|
+
root.pending -= 1;
|
|
33874
|
+
this.schedule();
|
|
33875
|
+
}
|
|
33876
|
+
}
|
|
33877
|
+
stop(input2 = {}) {
|
|
33878
|
+
this.root = null;
|
|
33879
|
+
if (this.v2EvaluationTimer)
|
|
33880
|
+
clearTimeout(this.v2EvaluationTimer);
|
|
33881
|
+
return super.stop(input2);
|
|
33882
|
+
}
|
|
33883
|
+
}
|
|
33884
|
+
|
|
33461
33885
|
// agent-driver/dist/adapters/opencode/index.js
|
|
33462
33886
|
function createOpenCodeMessageId() {
|
|
33463
33887
|
return `msg_${randomBytes4(16).toString("hex")}`;
|
|
@@ -33465,6 +33889,7 @@ function createOpenCodeMessageId() {
|
|
|
33465
33889
|
|
|
33466
33890
|
class OpenCodeDriver {
|
|
33467
33891
|
outputProbe;
|
|
33892
|
+
versionProbe;
|
|
33468
33893
|
id = "opencode";
|
|
33469
33894
|
instructionDelivery = { kind: "workspace_file", canonical: "AGENTS.md", aliases: ["CLAUDE.md"] };
|
|
33470
33895
|
execution = {
|
|
@@ -33473,17 +33898,29 @@ class OpenCodeDriver {
|
|
|
33473
33898
|
wakeStart: "immediate",
|
|
33474
33899
|
terminalOwnership: "transport_request"
|
|
33475
33900
|
};
|
|
33476
|
-
constructor(outputProbe = probeCommandOutput) {
|
|
33901
|
+
constructor(outputProbe = probeCommandOutput, versionProbe = probeCliRuntime) {
|
|
33477
33902
|
this.outputProbe = outputProbe;
|
|
33903
|
+
this.versionProbe = versionProbe;
|
|
33478
33904
|
}
|
|
33479
33905
|
discoverRecentContext(request) {
|
|
33480
|
-
|
|
33906
|
+
if (request.recentProjectsTopK === 0)
|
|
33907
|
+
return discoverOpenCodeRecentContext(request);
|
|
33908
|
+
const result = this.versionProbe("opencode", {}, request.command);
|
|
33909
|
+
if (result.status !== "healthy")
|
|
33910
|
+
throw new Error("Installed OpenCode CLI could not report its version");
|
|
33911
|
+
return discoverOpenCodeRecentContext(request, { compatibility: resolveOpenCodeCompatibility(result.version) });
|
|
33481
33912
|
}
|
|
33482
33913
|
probe(command) {
|
|
33483
|
-
const result =
|
|
33914
|
+
const result = this.versionProbe("opencode", {}, command);
|
|
33484
33915
|
if (result.status !== "healthy")
|
|
33485
33916
|
return result;
|
|
33486
|
-
|
|
33917
|
+
let compatibility;
|
|
33918
|
+
try {
|
|
33919
|
+
compatibility = resolveOpenCodeCompatibility(result.version);
|
|
33920
|
+
} catch {
|
|
33921
|
+
return { ...result, status: "unhealthy", lastError: "unsupported_opencode_cli_version" };
|
|
33922
|
+
}
|
|
33923
|
+
const spec = resolveSpawnSpec("opencode", [...compatibility.modelArgs], command);
|
|
33487
33924
|
const output2 = this.outputProbe(spec.command, spec.args);
|
|
33488
33925
|
return {
|
|
33489
33926
|
...result,
|
|
@@ -33494,20 +33931,29 @@ class OpenCodeDriver {
|
|
|
33494
33931
|
return createOpenCodeMessageId();
|
|
33495
33932
|
}
|
|
33496
33933
|
async openLane(ctx, options) {
|
|
33497
|
-
|
|
33934
|
+
const command = resolveLaunchFieldsOrDefault(ctx.config.runtimeConfig).command;
|
|
33935
|
+
const result = this.versionProbe("opencode", {}, command);
|
|
33936
|
+
if (result.status !== "healthy")
|
|
33937
|
+
throw new Error("Installed OpenCode CLI could not report its version");
|
|
33938
|
+
const compatibility = resolveOpenCodeCompatibility(result.version);
|
|
33939
|
+
const factory = {
|
|
33940
|
+
spawnService: (launch, port, password) => this.spawnService(launch, port, password, compatibility)
|
|
33941
|
+
};
|
|
33942
|
+
const Lane = compatibility.major === 1 ? OpenCodeServiceLane : OpenCodeV2ServiceLane;
|
|
33943
|
+
return new Lane(factory, ctx, {
|
|
33498
33944
|
onRawStdoutLine: options?.onRawStdoutLine
|
|
33499
33945
|
});
|
|
33500
33946
|
}
|
|
33501
|
-
async spawnService(ctx, port, password) {
|
|
33947
|
+
async spawnService(ctx, port, password, compatibility = OPEN_CODE_V1) {
|
|
33502
33948
|
const { spawnEnv } = await prepareCliTransport(ctx, {
|
|
33503
|
-
OPENCODE_SERVER_PASSWORD: password
|
|
33949
|
+
OPENCODE_SERVER_PASSWORD: password,
|
|
33950
|
+
...compatibility.major === 2 ? { OPENCODE_PASSWORD: password } : {}
|
|
33504
33951
|
});
|
|
33505
33952
|
const fields2 = resolveLaunchFieldsOrDefault(ctx.config.runtimeConfig);
|
|
33506
33953
|
Object.assign(spawnEnv, await legacyOpenCodeApiEnvironment(spawnEnv, fields2.model));
|
|
33507
33954
|
const override = fields2.command;
|
|
33508
33955
|
const args = [
|
|
33509
|
-
|
|
33510
|
-
"--pure",
|
|
33956
|
+
...compatibility.serviceArgs,
|
|
33511
33957
|
"--hostname",
|
|
33512
33958
|
"127.0.0.1",
|
|
33513
33959
|
"--port",
|
|
@@ -33702,15 +34148,14 @@ function createPiSessionDependencies(ctx, loadSdk = loadPiSdkModule) {
|
|
|
33702
34148
|
},
|
|
33703
34149
|
async createAgentSession(opts) {
|
|
33704
34150
|
const sdk = await loadSdk();
|
|
33705
|
-
const
|
|
34151
|
+
const modelRuntime = await sdk.ModelRuntime.create();
|
|
33706
34152
|
const runtimeConfig = ctx.config.runtimeConfig;
|
|
33707
34153
|
const provider = runtimeConfig && "provider" in runtimeConfig ? runtimeConfig.provider : undefined;
|
|
33708
34154
|
if (provider?.kind === "builtin") {
|
|
33709
|
-
|
|
34155
|
+
await modelRuntime.setRuntimeApiKey(provider.providerId, provider.apiKey);
|
|
33710
34156
|
}
|
|
33711
|
-
const modelRegistry = sdk.ModelRegistry.create(authStorage);
|
|
33712
34157
|
const parsed = parseModelString(opts.model);
|
|
33713
|
-
const model = parsed ?
|
|
34158
|
+
const model = parsed ? modelRuntime.getModel(parsed.provider, parsed.id) : undefined;
|
|
33714
34159
|
const cwd = opts.cwd;
|
|
33715
34160
|
const requestedSessionId = opts.sessionId;
|
|
33716
34161
|
let sessionManager;
|
|
@@ -33729,8 +34174,7 @@ function createPiSessionDependencies(ctx, loadSdk = loadPiSdkModule) {
|
|
|
33729
34174
|
cwd,
|
|
33730
34175
|
model,
|
|
33731
34176
|
thinkingLevel: opts.thinkingLevel,
|
|
33732
|
-
|
|
33733
|
-
modelRegistry,
|
|
34177
|
+
modelRuntime,
|
|
33734
34178
|
sessionManager,
|
|
33735
34179
|
customTools: [bashTool]
|
|
33736
34180
|
});
|
|
@@ -33965,9 +34409,8 @@ class PiDriver {
|
|
|
33965
34409
|
try {
|
|
33966
34410
|
const reasoning = await Promise.race([
|
|
33967
34411
|
this.loadSdk().then(async (sdk) => {
|
|
33968
|
-
const
|
|
33969
|
-
|
|
33970
|
-
return parsePiModelCatalog(await registry2.getAvailable());
|
|
34412
|
+
const modelRuntime = await sdk.ModelRuntime.create();
|
|
34413
|
+
return parsePiModelCatalog(await modelRuntime.getAvailable());
|
|
33971
34414
|
}),
|
|
33972
34415
|
new Promise((resolve4) => {
|
|
33973
34416
|
timer = setTimeout(() => resolve4(undefined), PI_MODEL_PROBE_TIMEOUT_MS);
|
|
@@ -37572,10 +38015,31 @@ function reduceManager(state, event) {
|
|
|
37572
38015
|
return withAgent(state, event.agentId, (a) => a ?? freshAgent(event.agentId), []);
|
|
37573
38016
|
case "wake":
|
|
37574
38017
|
return onWake(state, event.agentId, event.message);
|
|
37575
|
-
case "spawned":
|
|
38018
|
+
case "spawned": {
|
|
38019
|
+
const existing = state.agents[event.agentId];
|
|
38020
|
+
if (!existing || existing.status !== "starting")
|
|
38021
|
+
return { state, effects: [] };
|
|
38022
|
+
const agent2 = clone2(existing);
|
|
38023
|
+
enterStable(agent2, "running");
|
|
38024
|
+
syncExecutionProjection(agent2);
|
|
38025
|
+
const mode = leaseIsWorking(agent2.execution.lease) || agent2.pendingAdmissions.length > 0 ? "busy" : "idle";
|
|
38026
|
+
const messages = drainInbox(agent2);
|
|
38027
|
+
return commit(state, agent2, messages.map((message2) => ({ type: "send", agentId: event.agentId, message: message2, mode })));
|
|
38028
|
+
}
|
|
38029
|
+
case "queue_delivery":
|
|
37576
38030
|
return mutate(state, event.agentId, (a) => {
|
|
37577
|
-
|
|
38031
|
+
const queuedById = new Map(a.inbox.filter((message2) => message2.id).map((message2) => [message2.id, message2]));
|
|
38032
|
+
const restoredIds = new Set;
|
|
38033
|
+
const messages = event.messages.filter((message2) => {
|
|
38034
|
+
if (message2.id && restoredIds.has(message2.id))
|
|
38035
|
+
return false;
|
|
38036
|
+
if (message2.id)
|
|
38037
|
+
restoredIds.add(message2.id);
|
|
38038
|
+
return true;
|
|
38039
|
+
}).map((message2) => message2.id ? queuedById.get(message2.id) ?? message2 : message2);
|
|
38040
|
+
a.inbox = [...messages, ...a.inbox.filter((message2) => !message2.id || !restoredIds.has(message2.id))];
|
|
37578
38041
|
syncExecutionProjection(a);
|
|
38042
|
+
a.idleSince = null;
|
|
37579
38043
|
});
|
|
37580
38044
|
case "backend_session":
|
|
37581
38045
|
return mutate(state, event.agentId, (a) => {
|
|
@@ -37916,14 +38380,14 @@ function onTurnCompleted(state, agentId, sessionInstanceId, nowMs, turnId, endRe
|
|
|
37916
38380
|
agent2.stalledSessionId = null;
|
|
37917
38381
|
syncExecutionProjection(agent2);
|
|
37918
38382
|
const clearEffects = clearedStallSessionId === null ? [] : [{ type: "clear_stall_recovery", agentId, sessionId: clearedStallSessionId }];
|
|
37919
|
-
if (agent2.inbox.length > 0 && !agent2.resetting) {
|
|
38383
|
+
if (agent2.status === "running" && agent2.inbox.length > 0 && !agent2.resetting) {
|
|
37920
38384
|
const messages = drainInbox(agent2);
|
|
37921
38385
|
return commit(state, agent2, [
|
|
37922
38386
|
...clearEffects,
|
|
37923
38387
|
...messages.map((queued) => ({ type: "send", agentId, message: queued, mode: "idle" }))
|
|
37924
38388
|
]);
|
|
37925
38389
|
}
|
|
37926
|
-
agent2.idleSince = nowMs;
|
|
38390
|
+
agent2.idleSince = agent2.status === "running" && !agent2.resetting ? nowMs : null;
|
|
37927
38391
|
return commit(state, agent2, clearEffects);
|
|
37928
38392
|
}
|
|
37929
38393
|
function onTurnToolLifecycle(state, event, lifecycle) {
|
|
@@ -39719,8 +40183,34 @@ class AgentProcessManager {
|
|
|
39719
40183
|
}
|
|
39720
40184
|
}
|
|
39721
40185
|
}
|
|
39722
|
-
|
|
39723
|
-
|
|
40186
|
+
const completed = new Set;
|
|
40187
|
+
const deferSends = (agentId) => {
|
|
40188
|
+
const remaining = effects.filter((candidate) => candidate.type === "send" && !completed.has(candidate) && (agentId === undefined || candidate.agentId === agentId));
|
|
40189
|
+
for (const id3 of new Set(remaining.map((candidate) => candidate.agentId))) {
|
|
40190
|
+
const batch = remaining.filter((candidate) => candidate.agentId === id3);
|
|
40191
|
+
batch.forEach((candidate) => completed.add(candidate));
|
|
40192
|
+
this.dispatch({
|
|
40193
|
+
type: "queue_delivery",
|
|
40194
|
+
agentId: id3,
|
|
40195
|
+
messages: batch.map((candidate) => candidate.message)
|
|
40196
|
+
});
|
|
40197
|
+
}
|
|
40198
|
+
};
|
|
40199
|
+
try {
|
|
40200
|
+
for (const effect of effects) {
|
|
40201
|
+
if (completed.has(effect))
|
|
40202
|
+
continue;
|
|
40203
|
+
if (effect.type === "send" && !this.canSend(effect.agentId)) {
|
|
40204
|
+
deferSends(effect.agentId);
|
|
40205
|
+
continue;
|
|
40206
|
+
}
|
|
40207
|
+
this.applyEffect(effect);
|
|
40208
|
+
completed.add(effect);
|
|
40209
|
+
}
|
|
40210
|
+
} catch (error62) {
|
|
40211
|
+
deferSends();
|
|
40212
|
+
throw error62;
|
|
40213
|
+
}
|
|
39724
40214
|
return effects;
|
|
39725
40215
|
}
|
|
39726
40216
|
deriveActivitySnapshot(state) {
|
|
@@ -39752,6 +40242,26 @@ ${this.opts.wakePromptFooter}` : text3;
|
|
|
39752
40242
|
stampNow(text3) {
|
|
39753
40243
|
return this.opts.stampWakePromptTime ? `[${nowLocalISO()}] ${text3}` : text3;
|
|
39754
40244
|
}
|
|
40245
|
+
prepareDelivery(message2) {
|
|
40246
|
+
return {
|
|
40247
|
+
...message2,
|
|
40248
|
+
preparedInput: message2.preparedInput ?? {
|
|
40249
|
+
id: message2.id,
|
|
40250
|
+
kind: "user",
|
|
40251
|
+
text: this.stampNow(this.withFooter(message2.text)),
|
|
40252
|
+
sequence: message2.seq
|
|
40253
|
+
}
|
|
40254
|
+
};
|
|
40255
|
+
}
|
|
40256
|
+
canSend(agentId) {
|
|
40257
|
+
const session2 = this.sessions.get(agentId);
|
|
40258
|
+
const owner = this.activeSpawnState.get(agentId);
|
|
40259
|
+
const agent2 = this.state.agents[agentId];
|
|
40260
|
+
if (!session2 || !owner || owner.session !== session2 || owner.torndown || owner.superseded || agent2?.status !== "running" || agent2.resetting || agent2.execution.sessionInstanceId !== session2.sessionInstanceId)
|
|
40261
|
+
return false;
|
|
40262
|
+
const driverState = session2.snapshot().state;
|
|
40263
|
+
return driverState !== "stopping" && driverState !== "closed";
|
|
40264
|
+
}
|
|
39755
40265
|
beginPendingDelivery(owner, commandId, message2, mode, span, requeueOnFailure = true) {
|
|
39756
40266
|
const sessionInstanceId = owner.sessionInstanceId;
|
|
39757
40267
|
if (!sessionInstanceId || owner.pendingDeliverySpans.has(commandId))
|
|
@@ -39811,18 +40321,15 @@ ${this.opts.wakePromptFooter}` : text3;
|
|
|
39811
40321
|
break;
|
|
39812
40322
|
case "send": {
|
|
39813
40323
|
const session2 = this.sessions.get(effect.agentId);
|
|
39814
|
-
|
|
39815
|
-
|
|
39816
|
-
|
|
39817
|
-
|
|
39818
|
-
sequence: effect.message.seq
|
|
39819
|
-
};
|
|
39820
|
-
if (session2) {
|
|
40324
|
+
if (session2 && this.canSend(effect.agentId)) {
|
|
40325
|
+
const message2 = this.prepareDelivery(effect.message);
|
|
40326
|
+
effect.message = message2;
|
|
40327
|
+
const input2 = message2.preparedInput;
|
|
39821
40328
|
const owner = this.activeSpawnState.get(effect.agentId);
|
|
39822
40329
|
const exactOwner = owner?.session === session2 ? owner : undefined;
|
|
39823
40330
|
const associatedSpan = exactOwner ? effect.mode === "idle" ? this.openTurn(exactOwner) : exactOwner.activeSpan : null;
|
|
39824
40331
|
if (exactOwner)
|
|
39825
|
-
this.beginPendingDelivery(exactOwner, input2.id,
|
|
40332
|
+
this.beginPendingDelivery(exactOwner, input2.id, message2, effect.mode, associatedSpan);
|
|
39826
40333
|
let sent;
|
|
39827
40334
|
try {
|
|
39828
40335
|
sent = session2.send(input2);
|
|
@@ -40031,9 +40538,11 @@ ${this.opts.wakePromptFooter}` : text3;
|
|
|
40031
40538
|
this.log.info("agent session ended", { agentId, sessionId, reason });
|
|
40032
40539
|
}
|
|
40033
40540
|
doSpawn(agentId, messages, resumeSessionId) {
|
|
40034
|
-
const [
|
|
40035
|
-
if (!
|
|
40541
|
+
const [initial, ...pending] = messages;
|
|
40542
|
+
if (!initial)
|
|
40036
40543
|
throw new Error(`AgentProcessManager: spawn for ${agentId} has no command`);
|
|
40544
|
+
this.dispatch({ type: "queue_delivery", agentId, messages: pending });
|
|
40545
|
+
const first = this.prepareDelivery(initial);
|
|
40037
40546
|
const prompt = this.withFooter(first.text);
|
|
40038
40547
|
const driver = this.opts.driverFor(agentId, this.runtimeConfigs.get(agentId));
|
|
40039
40548
|
this.liveBackendIds.set(agentId, driver.id);
|
|
@@ -40237,12 +40746,7 @@ ${this.opts.wakePromptFooter}` : text3;
|
|
|
40237
40746
|
this.beginPendingDelivery(state, commandId, first, "idle", startedSpan, false);
|
|
40238
40747
|
let startResult;
|
|
40239
40748
|
try {
|
|
40240
|
-
startResult = session2.start(
|
|
40241
|
-
id: commandId,
|
|
40242
|
-
kind: "user",
|
|
40243
|
-
text: this.stampNow(prompt),
|
|
40244
|
-
sequence: first.seq
|
|
40245
|
-
});
|
|
40749
|
+
startResult = session2.start(first.preparedInput);
|
|
40246
40750
|
this.markPendingDeliveryObserved(state, commandId);
|
|
40247
40751
|
} catch (error62) {
|
|
40248
40752
|
this.settlePendingDelivery(state, commandId);
|
|
@@ -40250,7 +40754,7 @@ ${this.opts.wakePromptFooter}` : text3;
|
|
|
40250
40754
|
throw error62;
|
|
40251
40755
|
}
|
|
40252
40756
|
startResult.then((receipt) => {
|
|
40253
|
-
if (this.sessions.get(agentId) !== session2 || state.torndown)
|
|
40757
|
+
if (this.sessions.get(agentId) !== session2 || state.torndown || state.superseded || this.activeSpawnState.get(agentId) !== state)
|
|
40254
40758
|
return;
|
|
40255
40759
|
if (receipt?.status === "rejected") {
|
|
40256
40760
|
this.settlePendingDelivery(state, commandId);
|
|
@@ -40259,44 +40763,16 @@ ${this.opts.wakePromptFooter}` : text3;
|
|
|
40259
40763
|
session2.stop({ reason: "shutdown", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
40260
40764
|
return;
|
|
40261
40765
|
}
|
|
40262
|
-
|
|
40263
|
-
|
|
40264
|
-
|
|
40265
|
-
|
|
40266
|
-
|
|
40267
|
-
|
|
40268
|
-
|
|
40269
|
-
|
|
40270
|
-
|
|
40271
|
-
|
|
40272
|
-
id: message2.id,
|
|
40273
|
-
kind: "user",
|
|
40274
|
-
text: this.stampNow(this.withFooter(message2.text)),
|
|
40275
|
-
sequence: message2.seq
|
|
40276
|
-
});
|
|
40277
|
-
this.markPendingDeliveryObserved(state, message2.id);
|
|
40278
|
-
queuedReceipt = await queuedResult;
|
|
40279
|
-
} catch (error62) {
|
|
40280
|
-
this.settlePendingDelivery(state, message2.id);
|
|
40281
|
-
if (!state.torndown && this.sessions.get(agentId) === session2 && this.activeSpawnState.get(agentId) === state) {
|
|
40282
|
-
this.emitErrorAudit(agentId, "runtime", "send_failed", String(error62));
|
|
40283
|
-
session2.stop({ reason: "shutdown", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
40284
|
-
}
|
|
40285
|
-
return;
|
|
40286
|
-
}
|
|
40287
|
-
if (state.torndown || this.sessions.get(agentId) !== session2 || this.activeSpawnState.get(agentId) !== state) {
|
|
40288
|
-
return;
|
|
40289
|
-
}
|
|
40290
|
-
if (queuedReceipt.status === "rejected") {
|
|
40291
|
-
if (!state.pendingDeliverySpans.has(message2.id))
|
|
40292
|
-
return;
|
|
40293
|
-
this.settlePendingDelivery(state, message2.id);
|
|
40294
|
-
this.emitErrorAudit(agentId, "runtime", queuedReceipt.error?.code ?? queuedReceipt.reason, queuedReceipt.error?.message ?? `Delivery rejected (${queuedReceipt.reason})`);
|
|
40295
|
-
session2.stop({ reason: "shutdown", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
40296
|
-
return;
|
|
40297
|
-
}
|
|
40298
|
-
}
|
|
40299
|
-
})().catch((error62) => this.emitErrorAudit(agentId, "runtime", "send_failed", String(error62)));
|
|
40766
|
+
const driverState = session2.snapshot().state;
|
|
40767
|
+
if (this.state.agents[agentId]?.status !== "starting" || driverState === "stopping" || driverState === "closed")
|
|
40768
|
+
return;
|
|
40769
|
+
try {
|
|
40770
|
+
this.dispatch({ type: "spawned", agentId, nowMs: this.now() }, state);
|
|
40771
|
+
} catch (error62) {
|
|
40772
|
+
this.emitErrorAudit(agentId, "runtime", "send_failed", String(error62));
|
|
40773
|
+
session2.stop({ reason: "shutdown", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
40774
|
+
return;
|
|
40775
|
+
}
|
|
40300
40776
|
if (state.hasEstablished || state.hasReportedSpawnFailure)
|
|
40301
40777
|
return;
|
|
40302
40778
|
state.handshakeTimer = setTimeout(() => {
|