@sixb/core 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.js +17 -18
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/worker.js +4 -4
- package/dist/actions/worker.js.map +1 -1
- package/dist/agents/context-compaction.d.ts +40 -0
- package/dist/agents/context-compaction.d.ts.map +1 -0
- package/dist/agents/ids.d.ts +2 -0
- package/dist/agents/ids.d.ts.map +1 -1
- package/dist/agents/index.d.ts +6 -5
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +42 -37
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/streams.d.ts +17 -1
- package/dist/agents/streams.d.ts.map +1 -1
- package/dist/agents/streams.js +4 -2
- package/dist/agents/streams.js.map +1 -1
- package/dist/agents/types.d.ts +9 -0
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/validation.d.ts +1 -1
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/auth/index.js +7 -3
- package/dist/auth/index.js.map +1 -1
- package/dist/authorization/index.js +6 -2
- package/dist/authorization/index.js.map +1 -1
- package/dist/bootstrap/index.js +30 -31
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/{chunk-xmggaxg4.js → chunk-1wk20wn3.js} +188 -21
- package/dist/{chunk-xmggaxg4.js.map → chunk-1wk20wn3.js.map} +7 -5
- package/dist/{chunk-1ywq4hzk.js → chunk-1yz3x65y.js} +7 -7
- package/dist/{chunk-gqdd7508.js → chunk-4rh2m6zg.js} +1 -1
- package/dist/{chunk-fmx1sz2h.js → chunk-72q2y8hn.js} +3 -3
- package/dist/{chunk-fmx1sz2h.js.map → chunk-72q2y8hn.js.map} +3 -3
- package/dist/{chunk-f1cyvnrk.js → chunk-7gw7mepb.js} +259 -9
- package/dist/chunk-7gw7mepb.js.map +14 -0
- package/dist/{chunk-wb4051cx.js → chunk-819wnjz8.js} +11 -5
- package/dist/chunk-819wnjz8.js.map +12 -0
- package/dist/{chunk-pxtrxm3p.js → chunk-a09jx26t.js} +1 -1
- package/dist/{chunk-ettb0cy4.js → chunk-afjpa2hs.js} +59 -29
- package/dist/{chunk-ettb0cy4.js.map → chunk-afjpa2hs.js.map} +5 -5
- package/dist/{chunk-177ed2mp.js → chunk-c43qr6s0.js} +229 -97
- package/dist/{chunk-177ed2mp.js.map → chunk-c43qr6s0.js.map} +9 -9
- package/dist/{chunk-261ag4t4.js → chunk-cbkm2vam.js} +3 -3
- package/dist/{chunk-zpw39qhj.js → chunk-dm72y8wt.js} +25 -2
- package/dist/chunk-dm72y8wt.js.map +10 -0
- package/dist/{chunk-kqxgf6kv.js → chunk-drjqm1aa.js} +16 -1
- package/dist/{chunk-kqxgf6kv.js.map → chunk-drjqm1aa.js.map} +3 -3
- package/dist/chunk-dysw7nsm.js.map +1 -1
- package/dist/{chunk-4aw0jwk0.js → chunk-f6erf2vv.js} +1 -1
- package/dist/{chunk-4z3n1dzt.js → chunk-f83ka50g.js} +131 -25
- package/dist/chunk-f83ka50g.js.map +23 -0
- package/dist/{chunk-km4rkj4t.js → chunk-g13869yf.js} +3 -3
- package/dist/{chunk-c8bw2b6c.js → chunk-hbeh8j9w.js} +2 -2
- package/dist/{chunk-n5x5y80a.js → chunk-nzw7sm3b.js} +2 -2
- package/dist/{chunk-3rsf30p4.js → chunk-pn8n8sba.js} +16 -15
- package/dist/{chunk-3rsf30p4.js.map → chunk-pn8n8sba.js.map} +3 -3
- package/dist/{chunk-63te770v.js → chunk-qewtks41.js} +8 -8
- package/dist/{chunk-63te770v.js.map → chunk-qewtks41.js.map} +2 -2
- package/dist/{chunk-4p9rh7jj.js → chunk-rs1wbvy6.js} +1 -1
- package/dist/{chunk-88ppkr54.js → chunk-rte5sm3z.js} +26 -2
- package/dist/chunk-rte5sm3z.js.map +12 -0
- package/dist/{chunk-bv41fmjn.js → chunk-s31d0qmq.js} +57 -20
- package/dist/{chunk-bv41fmjn.js.map → chunk-s31d0qmq.js.map} +8 -7
- package/dist/{chunk-c6cfqydk.js → chunk-sxwk41qa.js} +1 -1
- package/dist/chunk-t0jjkep3.js.map +1 -1
- package/dist/{chunk-d6y2wsfg.js → chunk-tek1qwgm.js} +6 -6
- package/dist/{chunk-d6y2wsfg.js.map → chunk-tek1qwgm.js.map} +1 -1
- package/dist/{chunk-d2adj15j.js → chunk-tkdscva6.js} +1 -1
- package/dist/{chunk-ttba8x6z.js → chunk-tycbzedm.js} +2 -2
- package/dist/{chunk-z8j83gzd.js → chunk-x2yw73hy.js} +1 -1
- package/dist/{chunk-qer6am8w.js → chunk-xdf9yswn.js} +1 -1
- package/dist/execution/agent.js +26 -27
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/primitive.js +26 -27
- package/dist/execution/primitive.js.map +2 -2
- package/dist/execution/request.js +27 -28
- package/dist/execution/request.js.map +2 -2
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -53
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/types.d.ts +2 -1
- package/dist/lake-storage/types.d.ts.map +1 -1
- package/dist/materializer/index.js +15 -16
- package/dist/materializer/index.js.map +1 -1
- package/dist/models/index.d.ts +40 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/objects/execution.d.ts +6 -1
- package/dist/objects/execution.d.ts.map +1 -1
- package/dist/objects/index.js +19 -20
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/link/endpoints.d.ts.map +1 -1
- package/dist/objects/query/executor.d.ts +1 -0
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/explain.d.ts +1 -0
- package/dist/objects/query/explain.d.ts.map +1 -1
- package/dist/objects/query/index.d.ts +3 -1
- package/dist/objects/query/index.d.ts.map +1 -1
- package/dist/objects/query/index.js +30 -5
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/query/ir.d.ts +14 -1
- package/dist/objects/query/ir.d.ts.map +1 -1
- package/dist/objects/query/links.d.ts +25 -0
- package/dist/objects/query/links.d.ts.map +1 -0
- package/dist/objects/query/normalize.d.ts.map +1 -1
- package/dist/objects/query/planner.d.ts.map +1 -1
- package/dist/objects/query/validate.d.ts +1 -0
- package/dist/objects/query/validate.d.ts.map +1 -1
- package/dist/pipelines/index.js +15 -16
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/builders.d.ts +33 -4
- package/dist/projections/builders.d.ts.map +1 -1
- package/dist/projections/index.d.ts +1 -1
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/internal.js +15 -16
- package/dist/projections/internal.js.map +1 -1
- package/dist/projections/run-dispatch.d.ts +1 -0
- package/dist/projections/run-dispatch.d.ts.map +1 -1
- package/dist/projections/types.d.ts +12 -9
- package/dist/projections/types.d.ts.map +1 -1
- package/dist/projections/validation.d.ts +6 -5
- package/dist/projections/validation.d.ts.map +1 -1
- package/dist/query.d.ts +2 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +2 -2
- package/dist/runtime/create.d.ts +3 -0
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/definitions.d.ts +3 -0
- package/dist/runtime/definitions.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +2 -0
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/resolve-definitions.d.ts +2 -0
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/storage/agents/in-memory.d.ts +4 -0
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +9 -5
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +5 -0
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +1 -1
- package/dist/storage/ai-usage/in-memory.d.ts +2 -1
- package/dist/storage/ai-usage/in-memory.d.ts.map +1 -1
- package/dist/storage/ai-usage/index.d.ts +1 -1
- package/dist/storage/ai-usage/index.d.ts.map +1 -1
- package/dist/storage/ai-usage/types.d.ts +6 -0
- package/dist/storage/ai-usage/types.d.ts.map +1 -1
- package/dist/storage/index.d.ts +3 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +19 -14
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/objects/in-memory.d.ts +6 -3
- package/dist/storage/objects/in-memory.d.ts.map +1 -1
- package/dist/storage/objects/index.d.ts +3 -1
- package/dist/storage/objects/index.d.ts.map +1 -1
- package/dist/storage/objects/keys.d.ts +16 -0
- package/dist/storage/objects/keys.d.ts.map +1 -0
- package/dist/storage/objects/types.d.ts +33 -6
- package/dist/storage/objects/types.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +1 -1
- package/dist/storage/workflow-runs/provider.js +9 -5
- package/dist/storage/workflow-runs/provider.js.map +1 -1
- package/dist/syncs/index.js +15 -16
- package/dist/syncs/index.js.map +1 -1
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
- package/dist/testing/effective-storage-contract.d.ts +1 -1
- package/dist/testing/effective-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.js +455 -40
- package/dist/testing/index.js.map +7 -7
- package/dist/testing/lake-storage-contract.d.ts.map +1 -1
- package/dist/testing/object-query-contract.d.ts +1 -1
- package/dist/testing/object-query-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +13 -14
- package/dist/webhooks/internal.js.map +2 -2
- package/dist/workflows/index.js +27 -28
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
- package/src/agents/builders.ts +3 -3
- package/src/agents/context-compaction.ts +261 -0
- package/src/agents/ids.ts +5 -0
- package/src/agents/index.ts +18 -9
- package/src/agents/streams.ts +56 -0
- package/src/agents/types.ts +10 -0
- package/src/agents/validation.ts +35 -5
- package/src/http/api-routes.ts +7 -7
- package/src/index.ts +14 -0
- package/src/lake-storage/types.ts +2 -1
- package/src/materializer/telemetry/append.ts +33 -16
- package/src/models/index.ts +71 -0
- package/src/objects/execution.ts +20 -0
- package/src/objects/link/endpoints.ts +2 -1
- package/src/objects/query/executor.ts +42 -11
- package/src/objects/query/explain.ts +11 -0
- package/src/objects/query/index.ts +6 -0
- package/src/objects/query/ir.ts +16 -0
- package/src/objects/query/links.ts +308 -0
- package/src/objects/query/normalize.ts +40 -1
- package/src/objects/query/planner.ts +5 -0
- package/src/objects/query/validate.ts +58 -2
- package/src/projections/builders.ts +220 -15
- package/src/projections/index.ts +1 -0
- package/src/projections/ownership.ts +5 -5
- package/src/projections/registry.ts +9 -3
- package/src/projections/revision.ts +31 -5
- package/src/projections/run-dispatch.ts +10 -1
- package/src/projections/types.ts +13 -9
- package/src/projections/validation.ts +61 -19
- package/src/query.ts +2 -0
- package/src/runtime/create.ts +4 -0
- package/src/runtime/definitions.ts +3 -0
- package/src/runtime/host.ts +2 -0
- package/src/runtime/resolve-definitions.ts +28 -0
- package/src/storage/agents/in-memory.ts +15 -0
- package/src/storage/agents/types.ts +5 -0
- package/src/storage/ai-usage/in-memory.ts +23 -0
- package/src/storage/ai-usage/index.ts +1 -0
- package/src/storage/ai-usage/types.ts +10 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/objects/in-memory.ts +103 -16
- package/src/storage/objects/index.ts +9 -0
- package/src/storage/objects/keys.ts +36 -0
- package/src/storage/objects/types.ts +34 -6
- package/src/storage/ontology/provider-header-validation.ts +2 -2
- package/src/testing/agent-storage-contract.ts +12 -0
- package/src/testing/ai-usage-storage-contract.ts +35 -0
- package/src/testing/effective-storage-contract.ts +194 -4
- package/src/testing/lake-storage-contract.ts +56 -0
- package/src/testing/object-query-contract.ts +208 -1
- package/dist/agents/prompt.d.ts +0 -21
- package/dist/agents/prompt.d.ts.map +0 -1
- package/dist/chunk-4z3n1dzt.js.map +0 -23
- package/dist/chunk-6wetht33.js +0 -89
- package/dist/chunk-6wetht33.js.map +0 -10
- package/dist/chunk-88ppkr54.js.map +0 -12
- package/dist/chunk-f1cyvnrk.js.map +0 -13
- package/dist/chunk-wb4051cx.js.map +0 -12
- package/dist/chunk-zpw39qhj.js.map +0 -10
- package/src/agents/prompt.ts +0 -85
- /package/dist/{chunk-1ywq4hzk.js.map → chunk-1yz3x65y.js.map} +0 -0
- /package/dist/{chunk-gqdd7508.js.map → chunk-4rh2m6zg.js.map} +0 -0
- /package/dist/{chunk-pxtrxm3p.js.map → chunk-a09jx26t.js.map} +0 -0
- /package/dist/{chunk-261ag4t4.js.map → chunk-cbkm2vam.js.map} +0 -0
- /package/dist/{chunk-4aw0jwk0.js.map → chunk-f6erf2vv.js.map} +0 -0
- /package/dist/{chunk-km4rkj4t.js.map → chunk-g13869yf.js.map} +0 -0
- /package/dist/{chunk-c8bw2b6c.js.map → chunk-hbeh8j9w.js.map} +0 -0
- /package/dist/{chunk-n5x5y80a.js.map → chunk-nzw7sm3b.js.map} +0 -0
- /package/dist/{chunk-4p9rh7jj.js.map → chunk-rs1wbvy6.js.map} +0 -0
- /package/dist/{chunk-c6cfqydk.js.map → chunk-sxwk41qa.js.map} +0 -0
- /package/dist/{chunk-d2adj15j.js.map → chunk-tkdscva6.js.map} +0 -0
- /package/dist/{chunk-ttba8x6z.js.map → chunk-tycbzedm.js.map} +0 -0
- /package/dist/{chunk-z8j83gzd.js.map → chunk-x2yw73hy.js.map} +0 -0
- /package/dist/{chunk-qer6am8w.js.map → chunk-xdf9yswn.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lake-storage-contract.d.ts","sourceRoot":"","sources":["../../src/testing/lake-storage-contract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEpE,MAAM,MAAM,oCAAoC,GAAG,QAAQ,GAAG,oBAAoB,CAAA;AAElF,MAAM,WAAW,+BAA+B,CAAC,QAAQ,SAAS,WAAW,GAAG,WAAW;IACzF,+EAA+E;IAC/E,QAAQ,CAAC,aAAa,EAAE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC1D,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/D;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,oCAAoC,CAAA;IAC/D;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CACnC;AA2CD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,SAAS,WAAW,EACtE,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,+BAA+B,CAAC,QAAQ,CAAC,GACjD,IAAI,
|
|
1
|
+
{"version":3,"file":"lake-storage-contract.d.ts","sourceRoot":"","sources":["../../src/testing/lake-storage-contract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEpE,MAAM,MAAM,oCAAoC,GAAG,QAAQ,GAAG,oBAAoB,CAAA;AAElF,MAAM,WAAW,+BAA+B,CAAC,QAAQ,SAAS,WAAW,GAAG,WAAW;IACzF,+EAA+E;IAC/E,QAAQ,CAAC,aAAa,EAAE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC1D,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/D;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,oCAAoC,CAAA;IAC/D;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CACnC;AA2CD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,SAAS,WAAW,EACtE,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,+BAA+B,CAAC,QAAQ,CAAC,GACjD,IAAI,CAmrBN"}
|
|
@@ -13,7 +13,7 @@ export declare const objectQueryContractOntology: OntologyRegistry;
|
|
|
13
13
|
*
|
|
14
14
|
* The contract defines the portable V1 query surface: capability declarations,
|
|
15
15
|
* validation/normalization handoff, provider pushdown, bounded fallback,
|
|
16
|
-
* traversal, set operations, pagination, search profile defaults, and stable
|
|
16
|
+
* canonical reference sets, traversal, set operations, pagination, search profile defaults, and stable
|
|
17
17
|
* structured rejections for features outside a provider's capability map.
|
|
18
18
|
*/
|
|
19
19
|
export declare function runObjectQueryProviderContractSuite<TStorage extends Storage>(label: string, options: ObjectQueryProviderContractSuiteOptions<TStorage>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-query-contract.d.ts","sourceRoot":"","sources":["../../src/testing/object-query-contract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"object-query-contract.d.ts","sourceRoot":"","sources":["../../src/testing/object-query-contract.ts"],"names":[],"mappings":"AAcA,OAAO,EAA0B,gBAAgB,EAAoB,MAAM,aAAa,CAAA;AAExF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,wBAAwB,CAAA;AAE/B,MAAM,WAAW,uCAAuC,CAAC,QAAQ,SAAS,OAAO;IAC/E,kFAAkF;IAClF,QAAQ,CAAC,aAAa,EAAE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC1D,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAChE;AA8GD,eAAO,MAAM,2BAA2B,kBAEtC,CAAA;AAEF;;;;;;;GAOG;AACH,wBAAgB,mCAAmC,CAAC,QAAQ,SAAS,OAAO,EAC1E,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uCAAuC,CAAC,QAAQ,CAAC,GACzD,IAAI,CAslCN;AAED,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2EjG"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
createPrimitiveExecutionRecord
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-f6erf2vv.js";
|
|
5
5
|
import {
|
|
6
6
|
canRetryWebhookRun,
|
|
7
7
|
isStorageSerializationFailure
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import"../chunk-
|
|
8
|
+
} from "../chunk-1wk20wn3.js";
|
|
9
|
+
import"../chunk-72q2y8hn.js";
|
|
10
10
|
import"../chunk-xc7hq65b.js";
|
|
11
11
|
import"../chunk-cy0n5dms.js";
|
|
12
12
|
import"../chunk-dysw7nsm.js";
|
|
@@ -14,13 +14,13 @@ import"../chunk-62c7t4jc.js";
|
|
|
14
14
|
import {
|
|
15
15
|
WebhookRunError
|
|
16
16
|
} from "../chunk-ezake7g1.js";
|
|
17
|
-
import"../chunk-
|
|
17
|
+
import"../chunk-a09jx26t.js";
|
|
18
18
|
import"../chunk-htq0qh7z.js";
|
|
19
19
|
import"../chunk-xkthy56g.js";
|
|
20
|
-
import"../chunk-
|
|
21
|
-
import"../chunk-
|
|
20
|
+
import"../chunk-xdf9yswn.js";
|
|
21
|
+
import"../chunk-nzw7sm3b.js";
|
|
22
22
|
import"../chunk-t9xghkva.js";
|
|
23
|
-
import"../chunk-
|
|
23
|
+
import"../chunk-drjqm1aa.js";
|
|
24
24
|
import"../chunk-5gd7tpv6.js";
|
|
25
25
|
import {
|
|
26
26
|
ExecutionStorageError
|
|
@@ -28,19 +28,18 @@ import {
|
|
|
28
28
|
import"../chunk-9dzba0f2.js";
|
|
29
29
|
import"../chunk-vybf6pkp.js";
|
|
30
30
|
import"../chunk-ry24jbr1.js";
|
|
31
|
-
import"../chunk-6wetht33.js";
|
|
32
31
|
import"../chunk-3j7573mj.js";
|
|
33
32
|
import"../chunk-4gz41why.js";
|
|
34
33
|
import"../chunk-zcnhxkvd.js";
|
|
34
|
+
import"../chunk-t0jjkep3.js";
|
|
35
|
+
import"../chunk-tkdscva6.js";
|
|
36
|
+
import"../chunk-rhrbz7d4.js";
|
|
37
|
+
import"../chunk-xwnf87e1.js";
|
|
38
|
+
import"../chunk-f83ka50g.js";
|
|
35
39
|
import"../chunk-rnshztfq.js";
|
|
36
40
|
import"../chunk-04b07a9q.js";
|
|
37
41
|
import"../chunk-dktq02ne.js";
|
|
38
42
|
import"../chunk-zqysyfjt.js";
|
|
39
|
-
import"../chunk-t0jjkep3.js";
|
|
40
|
-
import"../chunk-d2adj15j.js";
|
|
41
|
-
import"../chunk-rhrbz7d4.js";
|
|
42
|
-
import"../chunk-xwnf87e1.js";
|
|
43
|
-
import"../chunk-4z3n1dzt.js";
|
|
44
43
|
import"../chunk-0172wgm9.js";
|
|
45
44
|
import"../chunk-t8t39h7v.js";
|
|
46
45
|
import"../chunk-y64skrwp.js";
|
|
@@ -149,4 +148,4 @@ export {
|
|
|
149
148
|
admitWebhookRun
|
|
150
149
|
};
|
|
151
150
|
|
|
152
|
-
//# debugId=
|
|
151
|
+
//# debugId=1789834E3012281164756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { randomUUID } from \"node:crypto\"\nimport { createPrimitiveExecutionRecord } from \"../execution/durable\"\nimport type { ExecutionRecord, Storage, WebhookRunRecord } from \"../storage\"\nimport {\n canRetryWebhookRun,\n ExecutionStorageError,\n isStorageSerializationFailure,\n WebhookRunError,\n} from \"../storage\"\n\nconst MAX_ADMISSION_ATTEMPTS = 3\n\nexport interface AdmitWebhookRunInput {\n readonly projectId: string\n readonly storage: Storage\n readonly runId: string\n readonly connectorId: string\n readonly webhookId: string\n readonly method: string\n readonly route: string\n readonly requestBodyBytes: number\n readonly requestBodySha256: string\n readonly idempotencyKey?: string\n}\n\nexport type AdmitWebhookRunResult =\n | {\n readonly status: \"admitted\"\n readonly run: WebhookRunRecord\n readonly execution: ExecutionRecord\n readonly retried: boolean\n }\n | {\n readonly status: \"duplicate\" | \"in_progress\"\n readonly run: WebhookRunRecord\n }\n\n/** Persist or reclaim one verified Webhook delivery before its protected handler executes. */\nexport async function admitWebhookRun(input: AdmitWebhookRunInput): Promise<AdmitWebhookRunResult> {\n assertAdmissionInput(input)\n let attempt = 0\n\n // Concurrent deliveries may both observe no run before one transaction commits. Retry only\n // serialization and uniqueness races so the loser can reload the winning run; every other error\n // fails immediately, and repeated contention remains bounded by MAX_ADMISSION_ATTEMPTS.\n while (true) {\n attempt += 1\n try {\n return await input.storage.transaction((tx) => admitWebhookRunTransaction(tx, input), {\n isolation: \"serializable\",\n })\n } catch (error) {\n if (attempt >= MAX_ADMISSION_ATTEMPTS || !isConcurrentAdmissionConflict(error)) {\n throw error\n }\n }\n }\n}\n\nasync function admitWebhookRunTransaction(\n storage: Storage,\n input: AdmitWebhookRunInput\n): Promise<AdmitWebhookRunResult> {\n const runs = requireWebhookRunStorage(storage)\n const existing = input.idempotencyKey\n ? await runs.getByDelivery({\n projectId: input.projectId,\n connectorId: input.connectorId,\n webhookId: input.webhookId,\n idempotencyKey: input.idempotencyKey,\n })\n : null\n\n if (existing) {\n assertSameDelivery(existing, input)\n if (existing.status === \"running\") return { status: \"in_progress\", run: existing }\n if (!canRetryWebhookRun(existing)) return { status: \"duplicate\", run: existing }\n\n const execution = await requireWebhookExecution(storage, existing)\n const run = await runs.restart({\n projectId: input.projectId,\n id: existing.id,\n })\n return { status: \"admitted\", run, execution, retried: true }\n }\n\n const executionInput = createPrimitiveExecutionRecord({\n id: `exec_${randomUUID()}`,\n primitive: { kind: \"webhook\", id: input.route, runId: input.runId },\n origin: {\n type: \"automatic\",\n projectId: input.projectId,\n source: { type: \"webhook\", deliveryId: input.runId },\n correlationId: input.runId,\n },\n })\n const execution = await storage.executions.create(executionInput)\n const run = await runs.start({\n id: input.runId,\n projectId: input.projectId,\n executionId: execution.id,\n connectorId: input.connectorId,\n webhookId: input.webhookId,\n method: input.method,\n route: input.route,\n requestBodyBytes: input.requestBodyBytes,\n requestBodySha256: input.requestBodySha256,\n idempotencyKey: input.idempotencyKey,\n })\n return { status: \"admitted\", run, execution, retried: false }\n}\n\nfunction assertSameDelivery(existing: WebhookRunRecord, input: AdmitWebhookRunInput): void {\n if (\n existing.connectorId !== input.connectorId ||\n existing.webhookId !== input.webhookId ||\n existing.method !== input.method ||\n existing.route !== input.route ||\n existing.requestBodyBytes !== input.requestBodyBytes ||\n existing.requestBodySha256 !== input.requestBodySha256\n ) {\n throw new WebhookRunError(\n `[Sixb] Webhook delivery '${input.idempotencyKey}' conflicts with run '${existing.id}'.`,\n \"delivery_conflict\"\n )\n }\n}\n\nasync function requireWebhookExecution(\n storage: Storage,\n run: WebhookRunRecord\n): Promise<ExecutionRecord> {\n const execution = await storage.executions.getById({\n projectId: run.projectId,\n id: run.executionId,\n })\n if (!execution) {\n throw new WebhookRunError(\n `[Sixb] Execution '${run.executionId}' for Webhook run '${run.id}' was not found.`,\n \"invalid_execution\"\n )\n }\n return execution\n}\n\nfunction requireWebhookRunStorage(storage: Storage): NonNullable<Storage[\"webhookRuns\"]> {\n if (!storage.webhookRuns) {\n throw new WebhookRunError(\"[Sixb] Webhook run storage is not configured.\")\n }\n return storage.webhookRuns\n}\n\nfunction assertAdmissionInput(input: AdmitWebhookRunInput): void {\n if (input.idempotencyKey !== undefined && !input.idempotencyKey.trim()) {\n throw new WebhookRunError(\"[Sixb] Webhook idempotency key must not be empty.\")\n }\n if (!Number.isSafeInteger(input.requestBodyBytes) || input.requestBodyBytes < 0) {\n throw new WebhookRunError(\"[Sixb] Webhook request body bytes must be a non-negative integer.\")\n }\n if (!/^[a-f0-9]{64}$/.test(input.requestBodySha256)) {\n throw new WebhookRunError(\"[Sixb] Webhook request body SHA-256 must be lowercase hexadecimal.\")\n }\n}\n\nfunction isConcurrentAdmissionConflict(error: unknown): boolean {\n return (\n isStorageSerializationFailure(error) ||\n (error instanceof ExecutionStorageError && error.code === \"duplicate_execution\") ||\n (error instanceof WebhookRunError &&\n (error.code === \"duplicate_run\" || error.code === \"invalid_transition\"))\n )\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "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",
|
|
8
|
+
"debugId": "1789834E3012281164756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/workflows/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
defineWorkflowStep,
|
|
8
8
|
interventionField,
|
|
9
9
|
unwrapWorkflowNodeFailure
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-hbeh8j9w.js";
|
|
11
11
|
import"../chunk-5sz8ta9r.js";
|
|
12
12
|
import"../chunk-979ww6b3.js";
|
|
13
13
|
import"../chunk-74drx9gd.js";
|
|
@@ -40,62 +40,61 @@ import {
|
|
|
40
40
|
validateWorkflowStepInput,
|
|
41
41
|
validateWorkflowStepOutput,
|
|
42
42
|
validateWorkflowsAtStartup
|
|
43
|
-
} from "../chunk-
|
|
44
|
-
import"../chunk-
|
|
45
|
-
import"../chunk-
|
|
46
|
-
import"../chunk-
|
|
47
|
-
import"../chunk-
|
|
43
|
+
} from "../chunk-c43qr6s0.js";
|
|
44
|
+
import"../chunk-g13869yf.js";
|
|
45
|
+
import"../chunk-cbkm2vam.js";
|
|
46
|
+
import"../chunk-pn8n8sba.js";
|
|
47
|
+
import"../chunk-4rh2m6zg.js";
|
|
48
48
|
import"../chunk-xhy826cz.js";
|
|
49
|
-
import"../chunk-
|
|
50
|
-
import"../chunk-
|
|
51
|
-
import"../chunk-
|
|
49
|
+
import"../chunk-7gw7mepb.js";
|
|
50
|
+
import"../chunk-rte5sm3z.js";
|
|
51
|
+
import"../chunk-qewtks41.js";
|
|
52
52
|
import"../chunk-8b55ygje.js";
|
|
53
53
|
import"../chunk-51fjndv0.js";
|
|
54
54
|
import"../chunk-8m5ejdpn.js";
|
|
55
55
|
import"../chunk-nf4r78r4.js";
|
|
56
|
-
import"../chunk-
|
|
57
|
-
import"../chunk-
|
|
58
|
-
import"../chunk-
|
|
56
|
+
import"../chunk-tycbzedm.js";
|
|
57
|
+
import"../chunk-tek1qwgm.js";
|
|
58
|
+
import"../chunk-afjpa2hs.js";
|
|
59
59
|
import"../chunk-96swp2wd.js";
|
|
60
|
-
import"../chunk-
|
|
61
|
-
import"../chunk-
|
|
62
|
-
import"../chunk-
|
|
60
|
+
import"../chunk-f6erf2vv.js";
|
|
61
|
+
import"../chunk-1wk20wn3.js";
|
|
62
|
+
import"../chunk-72q2y8hn.js";
|
|
63
63
|
import"../chunk-xc7hq65b.js";
|
|
64
64
|
import"../chunk-cy0n5dms.js";
|
|
65
65
|
import"../chunk-dysw7nsm.js";
|
|
66
66
|
import"../chunk-62c7t4jc.js";
|
|
67
67
|
import"../chunk-ezake7g1.js";
|
|
68
|
-
import"../chunk-
|
|
68
|
+
import"../chunk-a09jx26t.js";
|
|
69
69
|
import"../chunk-htq0qh7z.js";
|
|
70
70
|
import"../chunk-xkthy56g.js";
|
|
71
|
-
import"../chunk-
|
|
72
|
-
import"../chunk-
|
|
71
|
+
import"../chunk-xdf9yswn.js";
|
|
72
|
+
import"../chunk-nzw7sm3b.js";
|
|
73
73
|
import"../chunk-t9xghkva.js";
|
|
74
|
-
import"../chunk-
|
|
74
|
+
import"../chunk-drjqm1aa.js";
|
|
75
75
|
import"../chunk-5gd7tpv6.js";
|
|
76
76
|
import"../chunk-h9kxd41f.js";
|
|
77
77
|
import"../chunk-9dzba0f2.js";
|
|
78
78
|
import"../chunk-vybf6pkp.js";
|
|
79
79
|
import"../chunk-ry24jbr1.js";
|
|
80
|
-
import"../chunk-6wetht33.js";
|
|
81
80
|
import"../chunk-3j7573mj.js";
|
|
82
81
|
import"../chunk-4gz41why.js";
|
|
83
82
|
import"../chunk-zcnhxkvd.js";
|
|
84
83
|
import"../chunk-1evzqhks.js";
|
|
85
84
|
import"../chunk-dsrkgtnh.js";
|
|
86
85
|
import"../chunk-bhxaq2nn.js";
|
|
87
|
-
import"../chunk-rnshztfq.js";
|
|
88
|
-
import"../chunk-04b07a9q.js";
|
|
89
|
-
import"../chunk-dktq02ne.js";
|
|
90
|
-
import"../chunk-zqysyfjt.js";
|
|
91
86
|
import"../chunk-yt8wphsx.js";
|
|
92
87
|
import"../chunk-rdeagz6b.js";
|
|
93
|
-
import"../chunk-
|
|
88
|
+
import"../chunk-dm72y8wt.js";
|
|
94
89
|
import"../chunk-t0jjkep3.js";
|
|
95
|
-
import"../chunk-
|
|
90
|
+
import"../chunk-tkdscva6.js";
|
|
96
91
|
import"../chunk-rhrbz7d4.js";
|
|
97
92
|
import"../chunk-xwnf87e1.js";
|
|
98
|
-
import"../chunk-
|
|
93
|
+
import"../chunk-f83ka50g.js";
|
|
94
|
+
import"../chunk-rnshztfq.js";
|
|
95
|
+
import"../chunk-04b07a9q.js";
|
|
96
|
+
import"../chunk-dktq02ne.js";
|
|
97
|
+
import"../chunk-zqysyfjt.js";
|
|
99
98
|
import"../chunk-0172wgm9.js";
|
|
100
99
|
import"../chunk-t8t39h7v.js";
|
|
101
100
|
import"../chunk-y64skrwp.js";
|
|
@@ -136,4 +135,4 @@ export {
|
|
|
136
135
|
WorkflowDefinitionError
|
|
137
136
|
};
|
|
138
137
|
|
|
139
|
-
//# debugId=
|
|
138
|
+
//# debugId=49C4A15FE91A2DE064756E2164756E21
|
package/package.json
CHANGED
package/src/agents/builders.ts
CHANGED
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
assertValidAgentToolDescription,
|
|
17
17
|
assertValidAgentToolInput,
|
|
18
18
|
assertValidAgentToolName,
|
|
19
|
-
assertValidLoopConfig,
|
|
20
19
|
assertValidProviderOptions,
|
|
21
20
|
assertValidReasoningLevel,
|
|
22
21
|
groupIdsFromDefinitions,
|
|
22
|
+
resolveAgentLoopConfig,
|
|
23
23
|
} from "./validation"
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -76,7 +76,7 @@ export function defineAgent<const TId extends string>(
|
|
|
76
76
|
}
|
|
77
77
|
assertValidReasoningLevel(config.reasoning)
|
|
78
78
|
assertValidProviderOptions(config.providerOptions)
|
|
79
|
-
|
|
79
|
+
const loop = resolveAgentLoopConfig(config.loop)
|
|
80
80
|
const groupIds = groupIdsFromDefinitions(id, config.groups)
|
|
81
81
|
const tools = toolsFromDefinitions(id, config.tools)
|
|
82
82
|
|
|
@@ -91,6 +91,6 @@ export function defineAgent<const TId extends string>(
|
|
|
91
91
|
groupIds,
|
|
92
92
|
tools,
|
|
93
93
|
...(config.description !== undefined ? { description: config.description } : {}),
|
|
94
|
-
...(
|
|
94
|
+
...(loop !== undefined ? { loop } : {}),
|
|
95
95
|
})
|
|
96
96
|
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { stableJsonStringify } from "../json"
|
|
2
|
+
import type { AgentMessageRecord } from "../storage/agents/types"
|
|
3
|
+
import type { AgentMessage, AgentMessagePart } from "./message"
|
|
4
|
+
|
|
5
|
+
export const AGENT_CONTEXT_ESTIMATOR_VERSION = 1 as const
|
|
6
|
+
|
|
7
|
+
const CHARS_PER_TOKEN = 4
|
|
8
|
+
const REQUEST_OVERHEAD_TOKENS = 8
|
|
9
|
+
const MESSAGE_OVERHEAD_TOKENS = 8
|
|
10
|
+
const TOOL_OVERHEAD_TOKENS = 16
|
|
11
|
+
const STEP_OVERHEAD_TOKENS = 2
|
|
12
|
+
const IMAGE_ALLOWANCE_TOKENS = 1_200
|
|
13
|
+
const FILE_TEXT_INLINE_MAX_BYTES = 50 * 1024
|
|
14
|
+
const FILE_TEXT_INLINE_TOTAL_MAX_BYTES = 200 * 1024
|
|
15
|
+
const TOOL_RESULT_SUMMARY_MAX_CHARS = 2_000
|
|
16
|
+
|
|
17
|
+
export interface AgentContextEstimateTool {
|
|
18
|
+
readonly name: string
|
|
19
|
+
readonly description: string
|
|
20
|
+
/** Deterministic JSON-schema serialization sent for this tool. */
|
|
21
|
+
readonly inputSchema: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface EstimateAgentContextRequestTokensInput {
|
|
25
|
+
readonly systemPrompt: string
|
|
26
|
+
readonly tools: readonly AgentContextEstimateTool[]
|
|
27
|
+
readonly messages: readonly AgentMessage[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface AgentContextTokenEstimate {
|
|
31
|
+
readonly tokens: number
|
|
32
|
+
readonly estimatorVersion: typeof AGENT_CONTEXT_ESTIMATOR_VERSION
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface AgentContextCompactionBoundary {
|
|
36
|
+
readonly messagesToSummarize: readonly AgentMessageRecord[]
|
|
37
|
+
readonly retainedMessages: readonly AgentMessageRecord[]
|
|
38
|
+
readonly summarizedThroughSeq: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Compaction begins only once the estimated request crosses the reserved input budget. */
|
|
42
|
+
export function shouldCompactAgentContext(input: {
|
|
43
|
+
readonly estimatedInputTokens: number
|
|
44
|
+
readonly inputBudgetTokens: number
|
|
45
|
+
}): boolean {
|
|
46
|
+
return input.estimatedInputTokens > input.inputBudgetTokens
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Estimate the provider request shape with one stable, conservative character heuristic. */
|
|
50
|
+
export function estimateAgentContextRequestTokens(
|
|
51
|
+
input: EstimateAgentContextRequestTokensInput
|
|
52
|
+
): AgentContextTokenEstimate {
|
|
53
|
+
const toolTokens = input.tools.reduce(
|
|
54
|
+
(total, tool) =>
|
|
55
|
+
total +
|
|
56
|
+
TOOL_OVERHEAD_TOKENS +
|
|
57
|
+
textTokens(tool.name) +
|
|
58
|
+
textTokens(tool.description) +
|
|
59
|
+
textTokens(tool.inputSchema),
|
|
60
|
+
0
|
|
61
|
+
)
|
|
62
|
+
return {
|
|
63
|
+
tokens:
|
|
64
|
+
REQUEST_OVERHEAD_TOKENS +
|
|
65
|
+
textTokens(input.systemPrompt) +
|
|
66
|
+
toolTokens +
|
|
67
|
+
estimateAgentContextMessagesTokens(input.messages).tokens,
|
|
68
|
+
estimatorVersion: AGENT_CONTEXT_ESTIMATOR_VERSION,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Estimate message-only growth after a provider-usage anchor. */
|
|
73
|
+
export function estimateAgentContextMessagesTokens(
|
|
74
|
+
messages: readonly AgentMessage[]
|
|
75
|
+
): AgentContextTokenEstimate {
|
|
76
|
+
const attachments = { textBytesRemaining: FILE_TEXT_INLINE_TOTAL_MAX_BYTES }
|
|
77
|
+
let tokens = 0
|
|
78
|
+
for (const message of messages) {
|
|
79
|
+
tokens += estimateMessageTokens(message, attachments)
|
|
80
|
+
}
|
|
81
|
+
return { tokens, estimatorVersion: AGENT_CONTEXT_ESTIMATOR_VERSION }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Select the safe user boundary whose retained tail is closest to the configured recent budget. */
|
|
85
|
+
export function selectAgentContextCompactionBoundary(input: {
|
|
86
|
+
readonly messages: readonly AgentMessageRecord[]
|
|
87
|
+
readonly keepRecentTokens: number
|
|
88
|
+
}): AgentContextCompactionBoundary | null {
|
|
89
|
+
if (input.messages.length < 2) return null
|
|
90
|
+
|
|
91
|
+
let retainedTokens = 0
|
|
92
|
+
let boundaryIndex: number | null = null
|
|
93
|
+
let closestDistance = Number.POSITIVE_INFINITY
|
|
94
|
+
for (let index = input.messages.length - 1; index > 0; index -= 1) {
|
|
95
|
+
retainedTokens += estimateAgentContextMessagesTokens([input.messages[index]!]).tokens
|
|
96
|
+
if (input.messages[index]?.role !== "user") continue
|
|
97
|
+
|
|
98
|
+
const distance = Math.abs(input.keepRecentTokens - retainedTokens)
|
|
99
|
+
if (distance <= closestDistance) {
|
|
100
|
+
boundaryIndex = index
|
|
101
|
+
closestDistance = distance
|
|
102
|
+
}
|
|
103
|
+
if (retainedTokens >= input.keepRecentTokens) break
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (boundaryIndex === null) return null
|
|
107
|
+
|
|
108
|
+
const summarizedThroughSeq = input.messages[boundaryIndex - 1]?.seq
|
|
109
|
+
if (summarizedThroughSeq === undefined) return null
|
|
110
|
+
return {
|
|
111
|
+
messagesToSummarize: input.messages.slice(0, boundaryIndex),
|
|
112
|
+
retainedMessages: input.messages.slice(boundaryIndex),
|
|
113
|
+
summarizedThroughSeq,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Serialize durable conversation content as escaped quoted data for the summary model. */
|
|
118
|
+
export function serializeAgentMessagesForSummary(messages: readonly AgentMessageRecord[]): string {
|
|
119
|
+
const lines = ["<sixb_conversation_history>"]
|
|
120
|
+
for (const message of messages) {
|
|
121
|
+
lines.push(
|
|
122
|
+
` <message id="${escapeXml(message.id)}" seq="${message.seq}" role="${message.role}">`
|
|
123
|
+
)
|
|
124
|
+
message.parts.forEach((part, partIndex) => {
|
|
125
|
+
lines.push(...serializeSummaryPart(message, part, partIndex))
|
|
126
|
+
})
|
|
127
|
+
lines.push(" </message>")
|
|
128
|
+
}
|
|
129
|
+
lines.push("</sixb_conversation_history>")
|
|
130
|
+
return lines.join("\n")
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function estimateMessageTokens(
|
|
134
|
+
message: AgentMessage,
|
|
135
|
+
attachments: { textBytesRemaining: number }
|
|
136
|
+
): number {
|
|
137
|
+
let tokens = MESSAGE_OVERHEAD_TOKENS
|
|
138
|
+
for (const part of message.parts) {
|
|
139
|
+
switch (part.type) {
|
|
140
|
+
case "text":
|
|
141
|
+
case "reasoning":
|
|
142
|
+
tokens += textTokens(part.text)
|
|
143
|
+
break
|
|
144
|
+
case "step-start":
|
|
145
|
+
tokens += STEP_OVERHEAD_TOKENS
|
|
146
|
+
break
|
|
147
|
+
case "context":
|
|
148
|
+
tokens += textTokens(stableJsonStringify(part.context))
|
|
149
|
+
break
|
|
150
|
+
case "tool-call":
|
|
151
|
+
tokens +=
|
|
152
|
+
TOOL_OVERHEAD_TOKENS +
|
|
153
|
+
textTokens(part.toolName) +
|
|
154
|
+
textTokens(stableJsonStringify(part.input)) +
|
|
155
|
+
(part.state === "output-available"
|
|
156
|
+
? textTokens(stableJsonStringify(part.output))
|
|
157
|
+
: textTokens(part.errorText))
|
|
158
|
+
break
|
|
159
|
+
case "file": {
|
|
160
|
+
const file = part.fileRef
|
|
161
|
+
tokens += textTokens(
|
|
162
|
+
[file.blobId, file.digest, file.fileName, file.mediaType, file.logicalPath]
|
|
163
|
+
.filter((value): value is string => value !== undefined)
|
|
164
|
+
.join(" ")
|
|
165
|
+
)
|
|
166
|
+
if (message.role !== "assistant") {
|
|
167
|
+
if (looksLikeImage(file.mediaType, file.fileName)) {
|
|
168
|
+
tokens += IMAGE_ALLOWANCE_TOKENS
|
|
169
|
+
} else {
|
|
170
|
+
const inlineBytes = Math.min(
|
|
171
|
+
file.sizeBytes,
|
|
172
|
+
FILE_TEXT_INLINE_MAX_BYTES,
|
|
173
|
+
attachments.textBytesRemaining
|
|
174
|
+
)
|
|
175
|
+
attachments.textBytesRemaining -= inlineBytes
|
|
176
|
+
tokens += Math.ceil(inlineBytes / CHARS_PER_TOKEN)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
break
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return tokens
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function serializeSummaryPart(
|
|
187
|
+
message: AgentMessageRecord,
|
|
188
|
+
part: AgentMessagePart,
|
|
189
|
+
partIndex: number
|
|
190
|
+
): string[] {
|
|
191
|
+
const indent = " "
|
|
192
|
+
switch (part.type) {
|
|
193
|
+
case "text":
|
|
194
|
+
return [`${indent}<text>${escapeXml(part.text)}</text>`]
|
|
195
|
+
case "reasoning":
|
|
196
|
+
case "step-start":
|
|
197
|
+
return []
|
|
198
|
+
case "context":
|
|
199
|
+
return part.context.kind === "object"
|
|
200
|
+
? [
|
|
201
|
+
`${indent}<object_context origin="${part.origin}" object_type_id="${escapeXml(part.context.ref.objectTypeId)}" primary_id="${escapeXml(part.context.ref.primaryId)}" />`,
|
|
202
|
+
]
|
|
203
|
+
: [
|
|
204
|
+
`${indent}<app_context origin="${part.origin}" id="${escapeXml(part.context.id)}" label="${escapeXml(part.context.label)}">`,
|
|
205
|
+
`${indent} <description>${escapeXml(part.context.description)}</description>`,
|
|
206
|
+
`${indent} <value format="json">${escapeXml(stableJsonStringify(part.context.value))}</value>`,
|
|
207
|
+
`${indent}</app_context>`,
|
|
208
|
+
]
|
|
209
|
+
case "file": {
|
|
210
|
+
const file = part.fileRef
|
|
211
|
+
const attributes = [
|
|
212
|
+
`message_id="${escapeXml(message.id)}"`,
|
|
213
|
+
`part_index="${partIndex}"`,
|
|
214
|
+
`blob_id="${escapeXml(file.blobId)}"`,
|
|
215
|
+
`digest="${escapeXml(file.digest)}"`,
|
|
216
|
+
`size_bytes="${file.sizeBytes}"`,
|
|
217
|
+
...(file.fileName === undefined ? [] : [`file_name="${escapeXml(file.fileName)}"`]),
|
|
218
|
+
...(file.mediaType === undefined ? [] : [`media_type="${escapeXml(file.mediaType)}"`]),
|
|
219
|
+
...(file.logicalPath === undefined
|
|
220
|
+
? []
|
|
221
|
+
: [`logical_path="${escapeXml(file.logicalPath)}"`]),
|
|
222
|
+
]
|
|
223
|
+
return [`${indent}<file ${attributes.join(" ")} />`]
|
|
224
|
+
}
|
|
225
|
+
case "tool-call": {
|
|
226
|
+
const output =
|
|
227
|
+
part.state === "output-available"
|
|
228
|
+
? truncateToolResult(stableJsonStringify(part.output))
|
|
229
|
+
: truncateToolResult(part.errorText)
|
|
230
|
+
return [
|
|
231
|
+
`${indent}<tool_call id="${escapeXml(part.toolCallId)}" name="${escapeXml(part.toolName)}" state="${part.state}">`,
|
|
232
|
+
`${indent} <input format="json">${escapeXml(stableJsonStringify(part.input))}</input>`,
|
|
233
|
+
`${indent} <result>${escapeXml(output)}</result>`,
|
|
234
|
+
`${indent}</tool_call>`,
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function truncateToolResult(value: string): string {
|
|
241
|
+
if (value.length <= TOOL_RESULT_SUMMARY_MAX_CHARS) return value
|
|
242
|
+
return `${value.slice(0, TOOL_RESULT_SUMMARY_MAX_CHARS)}\n[truncated ${value.length - TOOL_RESULT_SUMMARY_MAX_CHARS} characters]`
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function looksLikeImage(mediaType: string | undefined, fileName: string | undefined): boolean {
|
|
246
|
+
if (mediaType?.toLowerCase().startsWith("image/")) return true
|
|
247
|
+
return /\.(?:avif|gif|jpe?g|png|webp)$/i.test(fileName ?? "")
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function textTokens(value: string): number {
|
|
251
|
+
return Math.ceil(new TextEncoder().encode(value).byteLength / CHARS_PER_TOKEN)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function escapeXml(value: string): string {
|
|
255
|
+
return value
|
|
256
|
+
.replaceAll("&", "&")
|
|
257
|
+
.replaceAll("<", "<")
|
|
258
|
+
.replaceAll(">", ">")
|
|
259
|
+
.replaceAll('"', """)
|
|
260
|
+
.replaceAll("'", "'")
|
|
261
|
+
}
|
package/src/agents/ids.ts
CHANGED
|
@@ -18,6 +18,11 @@ export function createAgentMessageId(): string {
|
|
|
18
18
|
return `agt_msg_${randomUUID()}`
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** One deterministic context-checkpoint identity per conversational run. */
|
|
22
|
+
export function agentContextCheckpointId(runId: string): string {
|
|
23
|
+
return `agt_ctx_${runId}`
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
/** A queue delivery's fencing token for writes to an `agent_runs` record. */
|
|
22
27
|
export function createAgentRunExecutionToken(): string {
|
|
23
28
|
return `agt_exec_${randomUUID()}`
|
package/src/agents/index.ts
CHANGED
|
@@ -53,6 +53,20 @@ export {
|
|
|
53
53
|
MAX_AGENT_CONTEXT_ENTRIES,
|
|
54
54
|
normalizeAgentContextEntries,
|
|
55
55
|
} from "./context"
|
|
56
|
+
export type {
|
|
57
|
+
AgentContextCompactionBoundary,
|
|
58
|
+
AgentContextEstimateTool,
|
|
59
|
+
AgentContextTokenEstimate,
|
|
60
|
+
EstimateAgentContextRequestTokensInput,
|
|
61
|
+
} from "./context-compaction"
|
|
62
|
+
export {
|
|
63
|
+
AGENT_CONTEXT_ESTIMATOR_VERSION,
|
|
64
|
+
estimateAgentContextMessagesTokens,
|
|
65
|
+
estimateAgentContextRequestTokens,
|
|
66
|
+
selectAgentContextCompactionBoundary,
|
|
67
|
+
serializeAgentMessagesForSummary,
|
|
68
|
+
shouldCompactAgentContext,
|
|
69
|
+
} from "./context-compaction"
|
|
56
70
|
export { serializeAgentContextForModel } from "./context-model"
|
|
57
71
|
export { resolveAgentContextParts } from "./context-resolution"
|
|
58
72
|
export type {
|
|
@@ -75,6 +89,7 @@ export {
|
|
|
75
89
|
AgentToolResultValidationError,
|
|
76
90
|
} from "./errors"
|
|
77
91
|
export {
|
|
92
|
+
agentContextCheckpointId,
|
|
78
93
|
createAgentMessageId,
|
|
79
94
|
createAgentRunExecutionToken,
|
|
80
95
|
createAgentRunId,
|
|
@@ -93,15 +108,6 @@ export {
|
|
|
93
108
|
type AgentToolCallPart,
|
|
94
109
|
type AgentToolCallState,
|
|
95
110
|
} from "./message"
|
|
96
|
-
export {
|
|
97
|
-
type BuildAgentSystemPromptInput,
|
|
98
|
-
type BuildWorkflowOutputFinalizerPromptInput,
|
|
99
|
-
buildAgentSystemPrompt,
|
|
100
|
-
buildWorkflowOutputFinalizerPrompt,
|
|
101
|
-
DEFAULT_AGENT_SYSTEM_CONTEXT,
|
|
102
|
-
DEFAULT_AGENT_WORKFLOW_SYSTEM_CONTEXT,
|
|
103
|
-
DEFAULT_WORKFLOW_OUTPUT_FINALIZER_SYSTEM_CONTEXT,
|
|
104
|
-
} from "./prompt"
|
|
105
111
|
export {
|
|
106
112
|
type RequestAgentRunInput,
|
|
107
113
|
type RequestAgentRunResult,
|
|
@@ -109,6 +115,7 @@ export {
|
|
|
109
115
|
retryAgentRun,
|
|
110
116
|
} from "./request"
|
|
111
117
|
export type {
|
|
118
|
+
AgentCompactionFailureCode,
|
|
112
119
|
AgentRunControlStreamId,
|
|
113
120
|
AgentRunFailure,
|
|
114
121
|
AgentRunFinishedEvent,
|
|
@@ -116,6 +123,7 @@ export type {
|
|
|
116
123
|
AgentRunStreamId,
|
|
117
124
|
} from "./streams"
|
|
118
125
|
export {
|
|
126
|
+
AGENT_COMPACTION_FAILURE_CODES,
|
|
119
127
|
AGENT_RUN_CANCEL_RECORD,
|
|
120
128
|
AGENT_RUN_STREAM_SCHEMA_VERSION,
|
|
121
129
|
agentRunControlStreamDefinition,
|
|
@@ -137,6 +145,7 @@ export type {
|
|
|
137
145
|
export { projectAgentThreadModelContext } from "./thread-context-projection"
|
|
138
146
|
export { isAgentToolResult } from "./tool-result"
|
|
139
147
|
export type {
|
|
148
|
+
AgentContextConfig,
|
|
140
149
|
AgentDefinition,
|
|
141
150
|
AgentLoopConfig,
|
|
142
151
|
AgentReasoningLevel,
|