@once-agent/sdk 0.1.4 → 0.1.6
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/LICENSE +20 -20
- package/README.md +62 -3
- package/dist/benchmark.d.ts +40 -0
- package/dist/benchmark.d.ts.map +1 -0
- package/dist/benchmark.js +169 -0
- package/dist/benchmark.js.map +1 -0
- package/dist/cli.js +52 -12
- package/dist/cli.js.map +1 -1
- package/dist/connect/binding.d.ts +17 -0
- package/dist/connect/binding.d.ts.map +1 -0
- package/dist/connect/binding.js +91 -0
- package/dist/connect/binding.js.map +1 -0
- package/dist/connect/classifier.d.ts +18 -0
- package/dist/connect/classifier.d.ts.map +1 -0
- package/dist/connect/classifier.js +49 -0
- package/dist/connect/classifier.js.map +1 -0
- package/dist/connect/execute.d.ts +30 -0
- package/dist/connect/execute.d.ts.map +1 -0
- package/dist/connect/execute.js +47 -0
- package/dist/connect/execute.js.map +1 -0
- package/dist/connect/kernel.d.ts +33 -0
- package/dist/connect/kernel.d.ts.map +1 -0
- package/dist/connect/kernel.js +46 -0
- package/dist/connect/kernel.js.map +1 -0
- package/dist/connect/openai-agents.d.ts +31 -0
- package/dist/connect/openai-agents.d.ts.map +1 -0
- package/dist/connect/openai-agents.js +42 -0
- package/dist/connect/openai-agents.js.map +1 -0
- package/dist/dataset-cli.d.ts +3 -0
- package/dist/dataset-cli.d.ts.map +1 -0
- package/dist/dataset-cli.js +49 -0
- package/dist/dataset-cli.js.map +1 -0
- package/dist/dataset-progress.d.ts +16 -0
- package/dist/dataset-progress.d.ts.map +1 -0
- package/dist/dataset-progress.js +130 -0
- package/dist/dataset-progress.js.map +1 -0
- package/dist/dataset.d.ts +35 -0
- package/dist/dataset.d.ts.map +1 -0
- package/dist/dataset.js +133 -0
- package/dist/dataset.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +259 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime/decision.d.ts +39 -0
- package/dist/runtime/decision.d.ts.map +1 -0
- package/dist/runtime/decision.js +102 -0
- package/dist/runtime/decision.js.map +1 -0
- package/dist/runtime/fetch-interceptor.d.ts +74 -0
- package/dist/runtime/fetch-interceptor.d.ts.map +1 -0
- package/dist/runtime/fetch-interceptor.js +156 -0
- package/dist/runtime/fetch-interceptor.js.map +1 -0
- package/dist/runtime/identity.d.ts +23 -0
- package/dist/runtime/identity.d.ts.map +1 -0
- package/dist/runtime/identity.js +191 -0
- package/dist/runtime/identity.js.map +1 -0
- package/dist/runtime/pipeline.d.ts +25 -0
- package/dist/runtime/pipeline.d.ts.map +1 -0
- package/dist/runtime/pipeline.js +121 -0
- package/dist/runtime/pipeline.js.map +1 -0
- package/dist/setup.d.ts +2 -0
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +126 -33
- package/dist/setup.js.map +1 -1
- package/dist/trace.d.ts +13 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +60 -0
- package/dist/trace.js.map +1 -0
- package/dist-cjs/connect/binding.js +99 -0
- package/dist-cjs/connect/binding.js.map +1 -0
- package/dist-cjs/connect/classifier.js +53 -0
- package/dist-cjs/connect/classifier.js.map +1 -0
- package/dist-cjs/connect/execute.js +52 -0
- package/dist-cjs/connect/execute.js.map +1 -0
- package/dist-cjs/connect/kernel.js +51 -0
- package/dist-cjs/connect/kernel.js.map +1 -0
- package/dist-cjs/connect/openai-agents.js +47 -0
- package/dist-cjs/connect/openai-agents.js.map +1 -0
- package/dist-cjs/index.js +282 -3
- package/dist-cjs/index.js.map +1 -1
- package/dist-cjs/runtime/decision.js +105 -0
- package/dist-cjs/runtime/decision.js.map +1 -0
- package/dist-cjs/runtime/fetch-interceptor.js +162 -0
- package/dist-cjs/runtime/fetch-interceptor.js.map +1 -0
- package/dist-cjs/runtime/identity.js +194 -0
- package/dist-cjs/runtime/identity.js.map +1 -0
- package/dist-cjs/runtime/pipeline.js +124 -0
- package/dist-cjs/runtime/pipeline.js.map +1 -0
- package/package.json +91 -69
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectBindingError = void 0;
|
|
4
|
+
exports.canonicalizeConnectPayload = canonicalizeConnectPayload;
|
|
5
|
+
exports.fingerprintConnectPayload = fingerprintConnectPayload;
|
|
6
|
+
exports.bindConnectOperation = bindConnectOperation;
|
|
7
|
+
exports.assertConnectBindingMatch = assertConnectBindingMatch;
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
class ConnectBindingError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(message, code) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "ConnectBindingError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ConnectBindingError = ConnectBindingError;
|
|
18
|
+
function canonicalize(value, path = "$") {
|
|
19
|
+
if (value === null) {
|
|
20
|
+
return "null";
|
|
21
|
+
}
|
|
22
|
+
const type = typeof value;
|
|
23
|
+
if (type === "string") {
|
|
24
|
+
return JSON.stringify(value);
|
|
25
|
+
}
|
|
26
|
+
if (type === "boolean") {
|
|
27
|
+
return value ? "true" : "false";
|
|
28
|
+
}
|
|
29
|
+
if (type === "number") {
|
|
30
|
+
const numberValue = value;
|
|
31
|
+
if (!Number.isFinite(numberValue)) {
|
|
32
|
+
throw new ConnectBindingError(`Unsupported non-finite number at ${path}.`, "UNSUPPORTED_PAYLOAD_VALUE");
|
|
33
|
+
}
|
|
34
|
+
if (Object.is(numberValue, -0)) {
|
|
35
|
+
return "0";
|
|
36
|
+
}
|
|
37
|
+
return JSON.stringify(numberValue);
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
return "[" +
|
|
41
|
+
value
|
|
42
|
+
.map((item, index) => canonicalize(item, `${path}[${index}]`))
|
|
43
|
+
.join(",") +
|
|
44
|
+
"]";
|
|
45
|
+
}
|
|
46
|
+
if (type === "object") {
|
|
47
|
+
const objectValue = value;
|
|
48
|
+
const prototype = Object.getPrototypeOf(objectValue);
|
|
49
|
+
if (prototype !== Object.prototype &&
|
|
50
|
+
prototype !== null) {
|
|
51
|
+
throw new ConnectBindingError(`Unsupported object type at ${path}.`, "UNSUPPORTED_PAYLOAD_VALUE");
|
|
52
|
+
}
|
|
53
|
+
const keys = Object.keys(objectValue).sort();
|
|
54
|
+
return "{" +
|
|
55
|
+
keys
|
|
56
|
+
.map((key) => `${JSON.stringify(key)}:${canonicalize(objectValue[key], `${path}.${key}`)}`)
|
|
57
|
+
.join(",") +
|
|
58
|
+
"}";
|
|
59
|
+
}
|
|
60
|
+
throw new ConnectBindingError(`Unsupported payload value at ${path}.`, "UNSUPPORTED_PAYLOAD_VALUE");
|
|
61
|
+
}
|
|
62
|
+
function canonicalizeConnectPayload(payload) {
|
|
63
|
+
if (payload === null ||
|
|
64
|
+
typeof payload !== "object" ||
|
|
65
|
+
Array.isArray(payload)) {
|
|
66
|
+
throw new ConnectBindingError("Once Connect payload must be a plain object.", "INVALID_PAYLOAD");
|
|
67
|
+
}
|
|
68
|
+
return canonicalize(payload);
|
|
69
|
+
}
|
|
70
|
+
function fingerprintConnectPayload(payload) {
|
|
71
|
+
const canonical = canonicalizeConnectPayload(payload);
|
|
72
|
+
const digest = (0, node_crypto_1.createHash)("sha256")
|
|
73
|
+
.update("once-connect-payload-v1\0", "utf8")
|
|
74
|
+
.update(canonical, "utf8")
|
|
75
|
+
.digest("hex");
|
|
76
|
+
return `once-connect-payload-v1:${digest}`;
|
|
77
|
+
}
|
|
78
|
+
function bindConnectOperation({ operationId, payload, }) {
|
|
79
|
+
if (typeof operationId !== "string" ||
|
|
80
|
+
operationId.trim() === "") {
|
|
81
|
+
throw new ConnectBindingError("Once Connect requires a stable operationId.", "INVALID_OPERATION_ID");
|
|
82
|
+
}
|
|
83
|
+
return Object.freeze({
|
|
84
|
+
operationId,
|
|
85
|
+
payloadFingerprint: fingerprintConnectPayload(payload),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function assertConnectBindingMatch(previousBinding, nextBinding) {
|
|
89
|
+
if (previousBinding.operationId !==
|
|
90
|
+
nextBinding.operationId) {
|
|
91
|
+
throw new ConnectBindingError("Operation identities do not match.", "OPERATION_ID_MISMATCH");
|
|
92
|
+
}
|
|
93
|
+
if (previousBinding.payloadFingerprint !==
|
|
94
|
+
nextBinding.payloadFingerprint) {
|
|
95
|
+
throw new ConnectBindingError("The same operationId was reused with a different consequential payload.", "PAYLOAD_DRIFT");
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../src/connect/binding.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONNECT_DECISION = void 0;
|
|
4
|
+
exports.classifyConnectOperation = classifyConnectOperation;
|
|
5
|
+
exports.CONNECT_DECISION = Object.freeze({
|
|
6
|
+
PROTECT: "PROTECT",
|
|
7
|
+
BYPASS: "BYPASS",
|
|
8
|
+
REJECT: "REJECT",
|
|
9
|
+
});
|
|
10
|
+
function requireBoolean(value, name) {
|
|
11
|
+
if (typeof value !== "boolean") {
|
|
12
|
+
throw new TypeError(`Once Connect requires boolean "${name}".`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function classifyConnectOperation(operation) {
|
|
16
|
+
if (!operation ||
|
|
17
|
+
typeof operation !== "object" ||
|
|
18
|
+
Array.isArray(operation)) {
|
|
19
|
+
return Object.freeze({
|
|
20
|
+
decision: exports.CONNECT_DECISION.REJECT,
|
|
21
|
+
reason: "INVALID_OPERATION",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const candidate = operation;
|
|
25
|
+
const { changesExternalState, retryPossible, ambiguousOutcomePossible, duplicateUndesirable, } = candidate;
|
|
26
|
+
try {
|
|
27
|
+
requireBoolean(changesExternalState, "changesExternalState");
|
|
28
|
+
requireBoolean(retryPossible, "retryPossible");
|
|
29
|
+
requireBoolean(ambiguousOutcomePossible, "ambiguousOutcomePossible");
|
|
30
|
+
requireBoolean(duplicateUndesirable, "duplicateUndesirable");
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
decision: exports.CONNECT_DECISION.REJECT,
|
|
35
|
+
reason: "INCOMPLETE_SAFETY_DECLARATION",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const requiresProtection = changesExternalState &&
|
|
39
|
+
retryPossible &&
|
|
40
|
+
ambiguousOutcomePossible &&
|
|
41
|
+
duplicateUndesirable;
|
|
42
|
+
if (requiresProtection) {
|
|
43
|
+
return Object.freeze({
|
|
44
|
+
decision: exports.CONNECT_DECISION.PROTECT,
|
|
45
|
+
reason: "CONSEQUENTIAL_RETRY_RISK",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return Object.freeze({
|
|
49
|
+
decision: exports.CONNECT_DECISION.BYPASS,
|
|
50
|
+
reason: "PROTECTION_CONDITIONS_NOT_ALL_PRESENT",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifier.js","sourceRoot":"","sources":["../../src/connect/classifier.ts"],"names":[],"mappings":";;;AAoCA,4DAqEC;AAzGY,QAAA,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;CACR,CAAC,CAAC;AAqBZ,SAAS,cAAc,CACrB,KAAc,EACd,IAAY;IAEZ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CACjB,kCAAkC,IAAI,IAAI,CAC3C,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAgB,wBAAwB,CACtC,SAAkB;IAElB,IACE,CAAC,SAAS;QACV,OAAO,SAAS,KAAK,QAAQ;QAC7B,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EACxB,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,QAAQ,EAAE,wBAAgB,CAAC,MAAM;YACjC,MAAM,EAAE,mBAAmB;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,SAAS,GACb,SAAoC,CAAC;IAEvC,MAAM,EACJ,oBAAoB,EACpB,aAAa,EACb,wBAAwB,EACxB,oBAAoB,GACrB,GAAG,SAAS,CAAC;IAEd,IAAI,CAAC;QACH,cAAc,CACZ,oBAAoB,EACpB,sBAAsB,CACvB,CAAC;QAEF,cAAc,CACZ,aAAa,EACb,eAAe,CAChB,CAAC;QAEF,cAAc,CACZ,wBAAwB,EACxB,0BAA0B,CAC3B,CAAC;QAEF,cAAc,CACZ,oBAAoB,EACpB,sBAAsB,CACvB,CAAC;IACJ,CAAC;IACD,MAAM,CAAC;QACL,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,QAAQ,EAAE,wBAAgB,CAAC,MAAM;YACjC,MAAM,EAAE,+BAA+B;SACxC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,kBAAkB,GACtB,oBAAoB;QACpB,aAAa;QACb,wBAAwB;QACxB,oBAAoB,CAAC;IAEvB,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,QAAQ,EAAE,wBAAgB,CAAC,OAAO;YAClC,MAAM,EAAE,0BAA0B;SACnC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,QAAQ,EAAE,wBAAgB,CAAC,MAAM;QACjC,MAAM,EAAE,uCAAuC;KAChD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectExecutionError = void 0;
|
|
4
|
+
exports.executeConnectOperation = executeConnectOperation;
|
|
5
|
+
const classifier_js_1 = require("./classifier.js");
|
|
6
|
+
const binding_js_1 = require("./binding.js");
|
|
7
|
+
class ConnectExecutionError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(message, code) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "ConnectExecutionError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ConnectExecutionError = ConnectExecutionError;
|
|
16
|
+
/**
|
|
17
|
+
* Framework-neutral Connect orchestration boundary.
|
|
18
|
+
*
|
|
19
|
+
* Connect decides whether the proposed tool call requires
|
|
20
|
+
* Once protection. It does not implement execution safety.
|
|
21
|
+
*
|
|
22
|
+
* Protected execution is delegated to the existing Once
|
|
23
|
+
* runtime/kernel supplied by the caller.
|
|
24
|
+
*/
|
|
25
|
+
async function executeConnectOperation({ safety, operationId, payload, bypass, protect, }) {
|
|
26
|
+
const classification = (0, classifier_js_1.classifyConnectOperation)(safety);
|
|
27
|
+
if (classification.decision ===
|
|
28
|
+
classifier_js_1.CONNECT_DECISION.REJECT) {
|
|
29
|
+
throw new ConnectExecutionError("Once Connect rejected an incomplete or invalid safety declaration.", "CONNECT_REJECTED");
|
|
30
|
+
}
|
|
31
|
+
if (classification.decision ===
|
|
32
|
+
classifier_js_1.CONNECT_DECISION.BYPASS) {
|
|
33
|
+
if (typeof bypass !== "function") {
|
|
34
|
+
throw new ConnectExecutionError("Once Connect bypass execution is unavailable.", "BYPASS_HANDLER_MISSING");
|
|
35
|
+
}
|
|
36
|
+
return await bypass();
|
|
37
|
+
}
|
|
38
|
+
const binding = (0, binding_js_1.bindConnectOperation)({
|
|
39
|
+
operationId,
|
|
40
|
+
payload,
|
|
41
|
+
});
|
|
42
|
+
if (typeof protect !== "function") {
|
|
43
|
+
throw new ConnectExecutionError("Once Connect protected execution is unavailable.", "PROTECT_HANDLER_MISSING");
|
|
44
|
+
}
|
|
45
|
+
return await protect({
|
|
46
|
+
operationId: binding.operationId,
|
|
47
|
+
payload,
|
|
48
|
+
payloadFingerprint: binding.payloadFingerprint,
|
|
49
|
+
classification,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/connect/execute.ts"],"names":[],"mappings":";;;AAyDA,0DA0DC;AAnHD,mDAGyB;AAOzB,6CAEsB;AAuBtB,MAAa,qBAAsB,SAAQ,KAAK;IACrC,IAAI,CAAS;IAEtB,YACE,OAAe,EACf,IAAY;QAEZ,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAXD,sDAWC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,uBAAuB,CAAc,EACzD,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,OAAO,GACkB;IACzB,MAAM,cAAc,GAClB,IAAA,wCAAwB,EAAC,MAAM,CAAC,CAAC;IAEnC,IACE,cAAc,CAAC,QAAQ;QACvB,gCAAgB,CAAC,MAAM,EACvB,CAAC;QACD,MAAM,IAAI,qBAAqB,CAC7B,oEAAoE,EACpE,kBAAkB,CACnB,CAAC;IACJ,CAAC;IAED,IACE,cAAc,CAAC,QAAQ;QACvB,gCAAgB,CAAC,MAAM,EACvB,CAAC;QACD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,MAAM,IAAI,qBAAqB,CAC7B,+CAA+C,EAC/C,wBAAwB,CACzB,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,MAAM,EAAE,CAAC;IACxB,CAAC;IAED,MAAM,OAAO,GACX,IAAA,iCAAoB,EAAC;QACnB,WAAW;QACX,OAAO;KACR,CAAC,CAAC;IAEL,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,IAAI,qBAAqB,CAC7B,kDAAkD,EAClD,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,OAAO,CAAC;QACnB,WAAW,EACT,OAAO,CAAC,WAAW;QAErB,OAAO;QAEP,kBAAkB,EAChB,OAAO,CAAC,kBAAkB;QAE5B,cAAc;KACf,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectExecutionError = exports.ConnectKernelError = void 0;
|
|
4
|
+
exports.executeConnectWithOnce = executeConnectWithOnce;
|
|
5
|
+
const execute_js_1 = require("./execute.js");
|
|
6
|
+
Object.defineProperty(exports, "ConnectExecutionError", { enumerable: true, get: function () { return execute_js_1.ConnectExecutionError; } });
|
|
7
|
+
class ConnectKernelError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(message, code) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "ConnectKernelError";
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ConnectKernelError = ConnectKernelError;
|
|
16
|
+
/**
|
|
17
|
+
* Route a proposed tool operation through Connect and, when protection
|
|
18
|
+
* is required, through the existing authoritative Once.execute() kernel.
|
|
19
|
+
*
|
|
20
|
+
* This adapter deliberately contains no execution-state machine,
|
|
21
|
+
* replay logic, reconciliation logic, or truth semantics.
|
|
22
|
+
*/
|
|
23
|
+
async function executeConnectWithOnce({ once, provider, safety, operationId, payload, action, bypass, }) {
|
|
24
|
+
if (!once ||
|
|
25
|
+
typeof once.execute !== "function") {
|
|
26
|
+
throw new ConnectKernelError("Once Connect requires an existing Once client.", "ONCE_CLIENT_REQUIRED");
|
|
27
|
+
}
|
|
28
|
+
return (0, execute_js_1.executeConnectOperation)({
|
|
29
|
+
safety,
|
|
30
|
+
operationId,
|
|
31
|
+
payload,
|
|
32
|
+
bypass,
|
|
33
|
+
protect: async (context) => {
|
|
34
|
+
if (typeof provider !== "string" ||
|
|
35
|
+
provider.trim() === "") {
|
|
36
|
+
throw new ConnectKernelError("Protected Connect execution requires a Once provider.", "PROVIDER_REQUIRED");
|
|
37
|
+
}
|
|
38
|
+
if (action === null ||
|
|
39
|
+
typeof action !== "object" ||
|
|
40
|
+
Array.isArray(action)) {
|
|
41
|
+
throw new ConnectKernelError("Protected Connect execution requires an action object.", "ACTION_REQUIRED");
|
|
42
|
+
}
|
|
43
|
+
return once.execute({
|
|
44
|
+
operationId: context.operationId,
|
|
45
|
+
provider,
|
|
46
|
+
action,
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=kernel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel.js","sourceRoot":"","sources":["../../src/connect/kernel.ts"],"names":[],"mappings":";;;AAmDA,wDA0DC;AA7GD,6CAGsB;AA6GpB,sGA9GA,kCAAqB,OA8GA;AAjFvB,MAAa,kBAAmB,SAAQ,KAAK;IAClC,IAAI,CAAS;IAEtB,YACE,OAAe,EACf,IAAY;QAEZ,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAXD,gDAWC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,sBAAsB,CAAc,EACxD,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,MAAM,GACgB;IACtB,IACE,CAAC,IAAI;QACL,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU,EAClC,CAAC;QACD,MAAM,IAAI,kBAAkB,CAC1B,gDAAgD,EAChD,sBAAsB,CACvB,CAAC;IACJ,CAAC;IAED,OAAO,IAAA,oCAAuB,EAAc;QAC1C,MAAM;QACN,WAAW;QACX,OAAO;QAEP,MAAM;QAEN,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACzB,IACE,OAAO,QAAQ,KAAK,QAAQ;gBAC5B,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EACtB,CAAC;gBACD,MAAM,IAAI,kBAAkB,CAC1B,uDAAuD,EACvD,mBAAmB,CACpB,CAAC;YACJ,CAAC;YAED,IACE,MAAM,KAAK,IAAI;gBACf,OAAO,MAAM,KAAK,QAAQ;gBAC1B,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EACrB,CAAC;gBACD,MAAM,IAAI,kBAAkB,CAC1B,wDAAwD,EACxD,iBAAiB,CAClB,CAAC;YACJ,CAAC;YAED,OAAO,IAAI,CAAC,OAAO,CAAC;gBAClB,WAAW,EACT,OAAO,CAAC,WAAW;gBAErB,QAAQ;gBAER,MAAM;aACP,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAIAgentsConnectError = void 0;
|
|
4
|
+
exports.executeOpenAIAgentsConnectTool = executeOpenAIAgentsConnectTool;
|
|
5
|
+
const kernel_js_1 = require("./kernel.js");
|
|
6
|
+
class OpenAIAgentsConnectError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
constructor(message, code) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "OpenAIAgentsConnectError";
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.OpenAIAgentsConnectError = OpenAIAgentsConnectError;
|
|
15
|
+
/**
|
|
16
|
+
* Minimal OpenAI Agents -> Once Connect execution adapter.
|
|
17
|
+
*
|
|
18
|
+
* This adapter owns no execution-safety state machine.
|
|
19
|
+
* It validates the framework boundary and delegates to
|
|
20
|
+
* the existing Connect -> Once kernel.
|
|
21
|
+
*
|
|
22
|
+
* OpenAI tool-call IDs are intentionally not used as
|
|
23
|
+
* logical operation identity. The caller must provide a
|
|
24
|
+
* stable operationId representing the same real-world
|
|
25
|
+
* logical operation across retries.
|
|
26
|
+
*/
|
|
27
|
+
async function executeOpenAIAgentsConnectTool({ once, provider, safety, operationId, input, action, bypass, }) {
|
|
28
|
+
if (input === null ||
|
|
29
|
+
typeof input !== "object" ||
|
|
30
|
+
Array.isArray(input)) {
|
|
31
|
+
throw new OpenAIAgentsConnectError("Once Connect requires parsed OpenAI Agents tool input.", "INVALID_OPENAI_TOOL_INPUT");
|
|
32
|
+
}
|
|
33
|
+
return await (0, kernel_js_1.executeConnectWithOnce)({
|
|
34
|
+
once,
|
|
35
|
+
provider,
|
|
36
|
+
safety,
|
|
37
|
+
operationId,
|
|
38
|
+
/*
|
|
39
|
+
* Parsed consequential tool input becomes the payload
|
|
40
|
+
* bound to the stable logical operation identity.
|
|
41
|
+
*/
|
|
42
|
+
payload: input,
|
|
43
|
+
action,
|
|
44
|
+
bypass,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=openai-agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-agents.js","sourceRoot":"","sources":["../../src/connect/openai-agents.ts"],"names":[],"mappings":";;;AAqDA,wEAqCC;AA1FD,2CAEqB;AA0BrB,MAAa,wBAAyB,SAAQ,KAAK;IACxC,IAAI,CAAS;IAEtB,YACE,OAAe,EACf,IAAY;QAEZ,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAXD,4DAWC;AAED;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,8BAA8B,CAClD,EACE,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,WAAW,EACX,KAAK,EACL,MAAM,EACN,MAAM,GACuB;IAE/B,IACE,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACpB,CAAC;QACD,MAAM,IAAI,wBAAwB,CAChC,wDAAwD,EACxD,2BAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,IAAA,kCAAsB,EAAC;QAClC,IAAI;QACJ,QAAQ;QACR,MAAM;QACN,WAAW;QAEX;;;WAGG;QACH,OAAO,EAAE,KAAK;QAEd,MAAM;QACN,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
|
package/dist-cjs/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Once = exports.OnceNetworkError = exports.OnceTimeoutError = exports.OnceError = void 0;
|
|
3
|
+
exports.executeOpenAIAgentsConnectTool = exports.OpenAIAgentsConnectError = exports.executeConnectWithOnce = exports.ConnectKernelError = exports.executeConnectOperation = exports.ConnectExecutionError = exports.assertConnectBindingMatch = exports.bindConnectOperation = exports.fingerprintConnectPayload = exports.canonicalizeConnectPayload = exports.ConnectBindingError = exports.classifyConnectOperation = exports.CONNECT_DECISION = exports.resolveHttpOperationIdentity = exports.decideHttpExecution = exports.prepareHttpExecution = exports.OnceRuntimeBlockedError = exports.installOnceFetchInterceptor = exports.createOnceFetchInterceptor = exports.Once = exports.OnceNetworkError = exports.OnceTimeoutError = exports.OnceRuntimeHttpShapeError = exports.OnceError = void 0;
|
|
4
|
+
exports.createOnceRuntimeFetch = createOnceRuntimeFetch;
|
|
5
|
+
exports.installOnceRuntimeFetch = installOnceRuntimeFetch;
|
|
4
6
|
const node_buffer_1 = require("node:buffer");
|
|
5
7
|
const node_crypto_1 = require("node:crypto");
|
|
8
|
+
const fetch_interceptor_js_1 = require("./runtime/fetch-interceptor.js");
|
|
6
9
|
const DEFAULT_BASE_URL = "https://once-q18-cloud.pennywatch.workers.dev";
|
|
7
10
|
class OnceError extends Error {
|
|
8
11
|
status;
|
|
@@ -21,6 +24,16 @@ class OnceError extends Error {
|
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
exports.OnceError = OnceError;
|
|
27
|
+
class OnceRuntimeHttpShapeError extends OnceError {
|
|
28
|
+
constructor(message, code = "unsupported_runtime_http_shape") {
|
|
29
|
+
super(message, {
|
|
30
|
+
code
|
|
31
|
+
});
|
|
32
|
+
this.name =
|
|
33
|
+
"OnceRuntimeHttpShapeError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.OnceRuntimeHttpShapeError = OnceRuntimeHttpShapeError;
|
|
24
37
|
class OnceTimeoutError extends OnceError {
|
|
25
38
|
constructor(message = "Once request timed out", cause) {
|
|
26
39
|
super(message, {
|
|
@@ -46,6 +59,7 @@ class Once {
|
|
|
46
59
|
baseUrl;
|
|
47
60
|
timeoutMs;
|
|
48
61
|
networkRetries;
|
|
62
|
+
fetchImpl;
|
|
49
63
|
constructor(options = {}) {
|
|
50
64
|
const apiKey = options.apiKey ??
|
|
51
65
|
process.env.ONCE_API_KEY;
|
|
@@ -62,6 +76,9 @@ class Once {
|
|
|
62
76
|
options.timeoutMs ?? 10_000;
|
|
63
77
|
this.networkRetries =
|
|
64
78
|
options.networkRetries ?? 2;
|
|
79
|
+
this.fetchImpl =
|
|
80
|
+
options.fetchImpl ??
|
|
81
|
+
globalThis.fetch;
|
|
65
82
|
}
|
|
66
83
|
/**
|
|
67
84
|
* Generate a deterministic Once operation ID.
|
|
@@ -170,8 +187,9 @@ class Once {
|
|
|
170
187
|
const controller = new AbortController();
|
|
171
188
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
172
189
|
try {
|
|
173
|
-
const response = await
|
|
190
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
174
191
|
...init,
|
|
192
|
+
redirect: "error",
|
|
175
193
|
signal: controller.signal,
|
|
176
194
|
headers: {
|
|
177
195
|
authorization: `Bearer ${this.apiKey}`,
|
|
@@ -179,8 +197,8 @@ class Once {
|
|
|
179
197
|
...init.headers
|
|
180
198
|
}
|
|
181
199
|
});
|
|
182
|
-
clearTimeout(timeout);
|
|
183
200
|
const raw = await response.text();
|
|
201
|
+
clearTimeout(timeout);
|
|
184
202
|
let body = null;
|
|
185
203
|
if (raw) {
|
|
186
204
|
try {
|
|
@@ -240,8 +258,269 @@ class Once {
|
|
|
240
258
|
}
|
|
241
259
|
}
|
|
242
260
|
exports.Once = Once;
|
|
261
|
+
function runtimeJsonContentType(request) {
|
|
262
|
+
const contentType = request.headers
|
|
263
|
+
.get("content-type")
|
|
264
|
+
?.toLowerCase() ??
|
|
265
|
+
"";
|
|
266
|
+
return contentType.includes("application/json");
|
|
267
|
+
}
|
|
268
|
+
function assertRuntimeHeaderShape(request) {
|
|
269
|
+
const allowed = new Set([
|
|
270
|
+
"content-type",
|
|
271
|
+
"idempotency-key",
|
|
272
|
+
"x-idempotency-key"
|
|
273
|
+
]);
|
|
274
|
+
for (const [name] of request.headers) {
|
|
275
|
+
if (!allowed.has(name.toLowerCase())) {
|
|
276
|
+
throw new OnceRuntimeHttpShapeError(`Once Runtime HTTP v0.1 cannot safely preserve target header "${name}".`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function parseRuntimeReplay(value) {
|
|
281
|
+
if (value === null ||
|
|
282
|
+
typeof value !== "object" ||
|
|
283
|
+
Array.isArray(value)) {
|
|
284
|
+
throw new OnceError("Once confirmed the operation but did not return a replayable HTTP response.", {
|
|
285
|
+
code: "runtime_http_response_missing",
|
|
286
|
+
body: value
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
const candidate = value;
|
|
290
|
+
const status = Number(candidate.status);
|
|
291
|
+
/*
|
|
292
|
+
* Fetch Response constructors cannot represent
|
|
293
|
+
* informational 1xx responses.
|
|
294
|
+
*/
|
|
295
|
+
if (!Number.isInteger(status) ||
|
|
296
|
+
status < 200 ||
|
|
297
|
+
status > 599) {
|
|
298
|
+
throw new OnceError("Once returned an HTTP replay with an unsupported status.", {
|
|
299
|
+
code: "runtime_http_response_invalid_status",
|
|
300
|
+
body: value
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
if (typeof candidate.body_text !==
|
|
304
|
+
"string") {
|
|
305
|
+
throw new OnceError("Once returned an HTTP replay without a valid text body.", {
|
|
306
|
+
code: "runtime_http_response_invalid_body",
|
|
307
|
+
body: value
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (candidate.headers === null ||
|
|
311
|
+
typeof candidate.headers !==
|
|
312
|
+
"object" ||
|
|
313
|
+
Array.isArray(candidate.headers)) {
|
|
314
|
+
throw new OnceError("Once returned an HTTP replay without valid headers.", {
|
|
315
|
+
code: "runtime_http_response_invalid_headers",
|
|
316
|
+
body: value
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
const headers = {};
|
|
320
|
+
for (const [name, headerValue] of Object.entries(candidate.headers)) {
|
|
321
|
+
if (typeof headerValue !==
|
|
322
|
+
"string") {
|
|
323
|
+
throw new OnceError("Once returned a non-string HTTP replay header.", {
|
|
324
|
+
code: "runtime_http_response_invalid_headers",
|
|
325
|
+
body: value
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
headers[name] =
|
|
329
|
+
headerValue;
|
|
330
|
+
}
|
|
331
|
+
const nullBody = status === 204 ||
|
|
332
|
+
status === 205 ||
|
|
333
|
+
status === 304;
|
|
334
|
+
if (nullBody &&
|
|
335
|
+
candidate.body_text.length > 0) {
|
|
336
|
+
throw new OnceError("Once returned a body for an HTTP status that cannot carry one.", {
|
|
337
|
+
code: "runtime_http_response_invalid_body",
|
|
338
|
+
body: value
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
status,
|
|
343
|
+
body_text: candidate.body_text,
|
|
344
|
+
headers,
|
|
345
|
+
...(typeof candidate.recorded_at ===
|
|
346
|
+
"string"
|
|
347
|
+
? {
|
|
348
|
+
recorded_at: candidate.recorded_at
|
|
349
|
+
}
|
|
350
|
+
: {})
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function createRuntimeCloudProtector(once) {
|
|
354
|
+
return async ({ request, decision, provider }) => {
|
|
355
|
+
if (decision.decision !==
|
|
356
|
+
"PROTECT") {
|
|
357
|
+
throw new OnceError("Runtime protector received a non-protected operation.", {
|
|
358
|
+
code: "runtime_invalid_protect_state"
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
if (!decision.operationId) {
|
|
362
|
+
throw new OnceError("Runtime protected operation is missing its resolved operation ID.", {
|
|
363
|
+
code: "runtime_operation_id_missing"
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (typeof provider !==
|
|
367
|
+
"string" ||
|
|
368
|
+
provider.trim().length ===
|
|
369
|
+
0) {
|
|
370
|
+
throw new OnceError("Runtime protected operation is missing its resolved provider.", {
|
|
371
|
+
code: "runtime_provider_missing"
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
const method = request.method
|
|
375
|
+
.trim()
|
|
376
|
+
.toUpperCase();
|
|
377
|
+
/*
|
|
378
|
+
* Classification recognizes POST/PUT/PATCH/DELETE as
|
|
379
|
+
* consequential. Execution v0.1 intentionally proves
|
|
380
|
+
* only POST + JSON.
|
|
381
|
+
*/
|
|
382
|
+
if (method !== "POST") {
|
|
383
|
+
throw new OnceRuntimeHttpShapeError(`Once Runtime HTTP v0.1 only has a proven protected execution contract for POST, not ${method || "(empty)"}.`);
|
|
384
|
+
}
|
|
385
|
+
if (!runtimeJsonContentType(request)) {
|
|
386
|
+
throw new OnceRuntimeHttpShapeError("Once Runtime HTTP v0.1 only protects application/json POST bodies.");
|
|
387
|
+
}
|
|
388
|
+
assertRuntimeHeaderShape(request);
|
|
389
|
+
const bodyText = await request
|
|
390
|
+
.clone()
|
|
391
|
+
.text();
|
|
392
|
+
if (bodyText.trim().length ===
|
|
393
|
+
0) {
|
|
394
|
+
throw new OnceRuntimeHttpShapeError("Once Runtime HTTP v0.1 requires a non-empty JSON body.");
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
JSON.parse(bodyText);
|
|
398
|
+
}
|
|
399
|
+
catch {
|
|
400
|
+
throw new OnceRuntimeHttpShapeError("Once Runtime HTTP v0.1 requires a valid JSON body.");
|
|
401
|
+
}
|
|
402
|
+
const result = await once.execute({
|
|
403
|
+
operationId: decision.operationId,
|
|
404
|
+
provider: provider.trim(),
|
|
405
|
+
action: {
|
|
406
|
+
type: "http_write_v1",
|
|
407
|
+
method: "POST",
|
|
408
|
+
url: request.url,
|
|
409
|
+
body_json: bodyText
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
const replay = parseRuntimeReplay(result.http_response);
|
|
413
|
+
const nullBody = replay.status === 204 ||
|
|
414
|
+
replay.status === 205 ||
|
|
415
|
+
replay.status === 304;
|
|
416
|
+
return new Response(nullBody
|
|
417
|
+
? null
|
|
418
|
+
: replay.body_text, {
|
|
419
|
+
status: replay.status,
|
|
420
|
+
headers: replay.headers
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Create a fetch-compatible Once Runtime.
|
|
426
|
+
*
|
|
427
|
+
* v0.1 proven protected execution shape:
|
|
428
|
+
* POST + application/json + stable identity.
|
|
429
|
+
*/
|
|
430
|
+
function createOnceRuntimeFetch(options = {}) {
|
|
431
|
+
const originalFetch = options.fetchImpl ??
|
|
432
|
+
globalThis.fetch;
|
|
433
|
+
if (typeof originalFetch !==
|
|
434
|
+
"function") {
|
|
435
|
+
throw new OnceError("Once Runtime requires a native fetch implementation.", {
|
|
436
|
+
code: "runtime_fetch_missing"
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/*
|
|
440
|
+
* Once Cloud requests use the captured native fetch.
|
|
441
|
+
* They cannot recursively enter this interceptor.
|
|
442
|
+
*/
|
|
443
|
+
const once = new Once({
|
|
444
|
+
apiKey: options.apiKey,
|
|
445
|
+
baseUrl: options.baseUrl,
|
|
446
|
+
timeoutMs: options.timeoutMs,
|
|
447
|
+
networkRetries: options.networkRetries,
|
|
448
|
+
fetchImpl: originalFetch
|
|
449
|
+
});
|
|
450
|
+
return (0, fetch_interceptor_js_1.createOnceFetchInterceptor)({
|
|
451
|
+
provider: options.provider,
|
|
452
|
+
shouldProtect: options.shouldProtect,
|
|
453
|
+
resolveProvider: options.resolveProvider,
|
|
454
|
+
resolveOperationId: options.resolveOperationId,
|
|
455
|
+
fetchImpl: originalFetch,
|
|
456
|
+
protect: createRuntimeCloudProtector(once)
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Explicit reversible global fetch installation.
|
|
461
|
+
*/
|
|
462
|
+
function installOnceRuntimeFetch(options = {}) {
|
|
463
|
+
const previous = globalThis.fetch;
|
|
464
|
+
const intercepted = createOnceRuntimeFetch({
|
|
465
|
+
...options,
|
|
466
|
+
fetchImpl: options.fetchImpl ??
|
|
467
|
+
previous
|
|
468
|
+
});
|
|
469
|
+
globalThis.fetch =
|
|
470
|
+
intercepted;
|
|
471
|
+
let restored = false;
|
|
472
|
+
return {
|
|
473
|
+
fetch: intercepted,
|
|
474
|
+
restore: () => {
|
|
475
|
+
if (restored) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (globalThis.fetch ===
|
|
479
|
+
intercepted) {
|
|
480
|
+
globalThis.fetch =
|
|
481
|
+
previous;
|
|
482
|
+
}
|
|
483
|
+
restored =
|
|
484
|
+
true;
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
243
488
|
function sleep(ms) {
|
|
244
489
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
245
490
|
}
|
|
491
|
+
var fetch_interceptor_js_2 = require("./runtime/fetch-interceptor.js");
|
|
492
|
+
Object.defineProperty(exports, "createOnceFetchInterceptor", { enumerable: true, get: function () { return fetch_interceptor_js_2.createOnceFetchInterceptor; } });
|
|
493
|
+
Object.defineProperty(exports, "installOnceFetchInterceptor", { enumerable: true, get: function () { return fetch_interceptor_js_2.installOnceFetchInterceptor; } });
|
|
494
|
+
Object.defineProperty(exports, "OnceRuntimeBlockedError", { enumerable: true, get: function () { return fetch_interceptor_js_2.OnceRuntimeBlockedError; } });
|
|
495
|
+
var pipeline_js_1 = require("./runtime/pipeline.js");
|
|
496
|
+
Object.defineProperty(exports, "prepareHttpExecution", { enumerable: true, get: function () { return pipeline_js_1.prepareHttpExecution; } });
|
|
497
|
+
var decision_js_1 = require("./runtime/decision.js");
|
|
498
|
+
Object.defineProperty(exports, "decideHttpExecution", { enumerable: true, get: function () { return decision_js_1.decideHttpExecution; } });
|
|
499
|
+
var identity_js_1 = require("./runtime/identity.js");
|
|
500
|
+
Object.defineProperty(exports, "resolveHttpOperationIdentity", { enumerable: true, get: function () { return identity_js_1.resolveHttpOperationIdentity; } });
|
|
246
501
|
exports.default = Once;
|
|
502
|
+
/*
|
|
503
|
+
* Once Connect
|
|
504
|
+
*
|
|
505
|
+
* Framework-neutral execution-safety boundary for agent/tool integrations.
|
|
506
|
+
* Protected execution delegates to the existing Once kernel.
|
|
507
|
+
*/
|
|
508
|
+
var classifier_js_1 = require("./connect/classifier.js");
|
|
509
|
+
Object.defineProperty(exports, "CONNECT_DECISION", { enumerable: true, get: function () { return classifier_js_1.CONNECT_DECISION; } });
|
|
510
|
+
Object.defineProperty(exports, "classifyConnectOperation", { enumerable: true, get: function () { return classifier_js_1.classifyConnectOperation; } });
|
|
511
|
+
var binding_js_1 = require("./connect/binding.js");
|
|
512
|
+
Object.defineProperty(exports, "ConnectBindingError", { enumerable: true, get: function () { return binding_js_1.ConnectBindingError; } });
|
|
513
|
+
Object.defineProperty(exports, "canonicalizeConnectPayload", { enumerable: true, get: function () { return binding_js_1.canonicalizeConnectPayload; } });
|
|
514
|
+
Object.defineProperty(exports, "fingerprintConnectPayload", { enumerable: true, get: function () { return binding_js_1.fingerprintConnectPayload; } });
|
|
515
|
+
Object.defineProperty(exports, "bindConnectOperation", { enumerable: true, get: function () { return binding_js_1.bindConnectOperation; } });
|
|
516
|
+
Object.defineProperty(exports, "assertConnectBindingMatch", { enumerable: true, get: function () { return binding_js_1.assertConnectBindingMatch; } });
|
|
517
|
+
var execute_js_1 = require("./connect/execute.js");
|
|
518
|
+
Object.defineProperty(exports, "ConnectExecutionError", { enumerable: true, get: function () { return execute_js_1.ConnectExecutionError; } });
|
|
519
|
+
Object.defineProperty(exports, "executeConnectOperation", { enumerable: true, get: function () { return execute_js_1.executeConnectOperation; } });
|
|
520
|
+
var kernel_js_1 = require("./connect/kernel.js");
|
|
521
|
+
Object.defineProperty(exports, "ConnectKernelError", { enumerable: true, get: function () { return kernel_js_1.ConnectKernelError; } });
|
|
522
|
+
Object.defineProperty(exports, "executeConnectWithOnce", { enumerable: true, get: function () { return kernel_js_1.executeConnectWithOnce; } });
|
|
523
|
+
var openai_agents_js_1 = require("./connect/openai-agents.js");
|
|
524
|
+
Object.defineProperty(exports, "OpenAIAgentsConnectError", { enumerable: true, get: function () { return openai_agents_js_1.OpenAIAgentsConnectError; } });
|
|
525
|
+
Object.defineProperty(exports, "executeOpenAIAgentsConnectTool", { enumerable: true, get: function () { return openai_agents_js_1.executeOpenAIAgentsConnectTool; } });
|
|
247
526
|
//# sourceMappingURL=index.js.map
|