@agent-assembly/sdk 0.0.1-beta.3 → 0.0.1-beta.5
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 +36 -23
- package/dist/cjs/core/gateway-resolver.js +73 -3
- package/dist/cjs/core/init-assembly.js +155 -33
- package/dist/cjs/core/redact.js +63 -0
- package/dist/cjs/gateway/client.js +63 -1
- package/dist/cjs/gateway/index.js +2 -1
- package/dist/cjs/hooks/ai-sdk.js +46 -10
- package/dist/cjs/hooks/langchain.js +12 -3
- package/dist/cjs/hooks/mastra.js +10 -6
- package/dist/cjs/hooks/openai-agents.js +1 -3
- package/dist/cjs/index.js +9 -1
- package/dist/cjs/native/client.js +94 -25
- package/dist/cjs/op-control.js +159 -17
- package/dist/cjs/runtime.js +73 -7
- package/dist/cjs/wrappers/with-assembly.js +89 -32
- package/dist/esm/core/gateway-resolver.js +72 -3
- package/dist/esm/core/gateway-resolver.js.map +1 -1
- package/dist/esm/core/init-assembly.js +154 -32
- package/dist/esm/core/init-assembly.js.map +1 -1
- package/dist/esm/core/redact.js +59 -0
- package/dist/esm/core/redact.js.map +1 -0
- package/dist/esm/gateway/client.js +62 -1
- package/dist/esm/gateway/client.js.map +1 -1
- package/dist/esm/gateway/index.js +1 -1
- package/dist/esm/gateway/index.js.map +1 -1
- package/dist/esm/hooks/ai-sdk.js +46 -10
- package/dist/esm/hooks/ai-sdk.js.map +1 -1
- package/dist/esm/hooks/langchain.js +12 -3
- package/dist/esm/hooks/langchain.js.map +1 -1
- package/dist/esm/hooks/mastra.js +10 -6
- package/dist/esm/hooks/mastra.js.map +1 -1
- package/dist/esm/hooks/openai-agents.js +1 -3
- package/dist/esm/hooks/openai-agents.js.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/native/client.js +91 -24
- package/dist/esm/native/client.js.map +1 -1
- package/dist/esm/op-control.js +124 -17
- package/dist/esm/op-control.js.map +1 -1
- package/dist/esm/runtime.js +72 -7
- package/dist/esm/runtime.js.map +1 -1
- package/dist/esm/wrappers/with-assembly.js +89 -32
- package/dist/esm/wrappers/with-assembly.js.map +1 -1
- package/dist/types/core/gateway-resolver.d.ts +18 -1
- package/dist/types/core/gateway-resolver.d.ts.map +1 -1
- package/dist/types/core/init-assembly.d.ts +2 -1
- package/dist/types/core/init-assembly.d.ts.map +1 -1
- package/dist/types/core/redact.d.ts +28 -0
- package/dist/types/core/redact.d.ts.map +1 -0
- package/dist/types/gateway/client.d.ts +17 -0
- package/dist/types/gateway/client.d.ts.map +1 -1
- package/dist/types/gateway/index.d.ts +1 -1
- package/dist/types/gateway/index.d.ts.map +1 -1
- package/dist/types/hooks/ai-sdk.d.ts +13 -0
- package/dist/types/hooks/ai-sdk.d.ts.map +1 -1
- package/dist/types/hooks/langchain.d.ts +11 -0
- package/dist/types/hooks/langchain.d.ts.map +1 -1
- package/dist/types/hooks/mastra.d.ts.map +1 -1
- package/dist/types/hooks/openai-agents.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/native/client.d.ts +44 -0
- package/dist/types/native/client.d.ts.map +1 -1
- package/dist/types/op-control.d.ts +71 -7
- package/dist/types/op-control.d.ts.map +1 -1
- package/dist/types/runtime.d.ts +27 -5
- package/dist/types/runtime.d.ts.map +1 -1
- package/dist/types/types/assembly-config.d.ts +6 -0
- package/dist/types/types/assembly-config.d.ts.map +1 -1
- package/dist/types/wrappers/index.d.ts +1 -1
- package/dist/types/wrappers/index.d.ts.map +1 -1
- package/dist/types/wrappers/with-assembly.d.ts +25 -0
- package/dist/types/wrappers/with-assembly.d.ts.map +1 -1
- package/native/aa-ffi-node/index.d.ts +82 -1
- package/package.json +18 -5
package/dist/esm/hooks/mastra.js
CHANGED
|
@@ -37,15 +37,18 @@ export async function patchMastra(options) {
|
|
|
37
37
|
mastraPatchState.originalGenerate = originalGenerate;
|
|
38
38
|
mastraPatchState.patchedAgentClass = module.Agent;
|
|
39
39
|
module.Agent.prototype.generate = function patchedGenerate(...args) {
|
|
40
|
-
|
|
40
|
+
// The try guards only the *synchronous* setup (entering the async-context
|
|
41
|
+
// store and invoking the original); the returned promise is handed to the
|
|
42
|
+
// caller, which awaits it, so its rejection is the caller's to handle.
|
|
43
|
+
// Returning it directly (rather than via a local inside the try) avoids an
|
|
44
|
+
// unhandled-rejection footgun without changing timing or call count.
|
|
41
45
|
try {
|
|
42
|
-
|
|
46
|
+
return runWithAgentId(agentId, () => originalGenerate.apply(this, args));
|
|
43
47
|
}
|
|
44
48
|
catch (e) {
|
|
45
49
|
console.warn("[assembly] Mastra lineage patch error on generate; falling back:", e);
|
|
46
50
|
return originalGenerate.apply(this, args);
|
|
47
51
|
}
|
|
48
|
-
return result;
|
|
49
52
|
};
|
|
50
53
|
// Wrap Workflow.prototype.execute if present
|
|
51
54
|
if (module.Workflow?.prototype?.execute) {
|
|
@@ -53,15 +56,16 @@ export async function patchMastra(options) {
|
|
|
53
56
|
mastraPatchState.originalExecute = originalExecute;
|
|
54
57
|
mastraPatchState.patchedWorkflowClass = module.Workflow;
|
|
55
58
|
module.Workflow.prototype.execute = function patchedExecute(...args) {
|
|
56
|
-
|
|
59
|
+
// See patchedGenerate above: the try guards only the synchronous setup;
|
|
60
|
+
// the returned promise is awaited by the caller, so returning it directly
|
|
61
|
+
// (not via a local) handles its rejection without altering behaviour.
|
|
57
62
|
try {
|
|
58
|
-
|
|
63
|
+
return runWithAgentId(agentId, () => originalExecute.apply(this, args));
|
|
59
64
|
}
|
|
60
65
|
catch (e) {
|
|
61
66
|
console.warn("[assembly] Mastra lineage patch error on execute; falling back:", e);
|
|
62
67
|
return originalExecute.apply(this, args);
|
|
63
68
|
}
|
|
64
|
-
return result;
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
71
|
mastraPatchState.isPatched = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mastra.js","sourceRoot":"","sources":["../../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AC,CAAC;gBACnF,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAED,gBAAgB,CAAC,SAAS,GAAG,IAAI,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,gBAAgB,CAAC,iBAAiB,IAAI,gBAAgB,CAAC,gBAAgB,EAAE,CAAC;QAC5E,gBAAgB,CAAC,iBAAiB,CAAC,SAAS,CAAC,QAAQ,GAAG,gBAAgB,CAAC,gBAAgB,CAAC;IAC5F,CAAC;IACD,IAAI,gBAAgB,CAAC,oBAAoB,IAAI,gBAAgB,CAAC,eAAe,EAAE,CAAC;QAC9E,gBAAgB,CAAC,oBAAoB,CAAC,SAAS,CAAC,OAAO,GAAG,gBAAgB,CAAC,eAAe,CAAC;IAC7F,CAAC;IAED,gBAAgB,CAAC,SAAS,GAAG,KAAK,CAAC;IACnC,gBAAgB,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAC9C,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC;IAC7C,gBAAgB,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAC/C,gBAAgB,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -9,9 +9,7 @@ export function captureOriginalRunTool(agentClass) {
|
|
|
9
9
|
if (!candidate) {
|
|
10
10
|
return undefined;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
openAIAgentsPatchState.originalRunTool = candidate;
|
|
14
|
-
}
|
|
12
|
+
openAIAgentsPatchState.originalRunTool ??= candidate;
|
|
15
13
|
return openAIAgentsPatchState.originalRunTool;
|
|
16
14
|
}
|
|
17
15
|
export function parseToolCallArguments(toolCall) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-agents.js","sourceRoot":"","sources":["../../../src/hooks/openai-agents.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAclE,MAAM,CAAC,MAAM,sBAAsB,GAA2B;IAC5D,SAAS,EAAE,KAAK;IAChB,eAAe,EAAE,SAAS;IAC1B,iBAAiB,EAAE,SAAS;CAC7B,CAAC;AAEF,MAAM,UAAU,sBAAsB,CACpC,UAAkC;IAElC,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC;IAChD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"openai-agents.js","sourceRoot":"","sources":["../../../src/hooks/openai-agents.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAclE,MAAM,CAAC,MAAM,sBAAsB,GAA2B;IAC5D,SAAS,EAAE,KAAK;IAChB,eAAe,EAAE,SAAS;IAC1B,iBAAiB,EAAE,SAAS;CAC7B,CAAC;AAEF,MAAM,UAAU,sBAAsB,CACpC,UAAkC;IAElC,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC;IAChD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,sBAAsB,CAAC,eAAe,KAAK,SAAS,CAAC;IAErD,OAAO,sBAAsB,CAAC,eAAe,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,QAA8B;IACnE,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;IACrC,CAAC;AACH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C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC,sBAAsB,CAAC,iBAAiB,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC,sBAAsB,CAAC,eAAe,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,sBAAsB,CAAC,iBAAiB,CAAC,SAAS,CAAC,QAAQ;QACzD,sBAAsB,CAAC,eAAe,CAAC;IACzC,sBAAsB,CAAC,SAAS,GAAG,KAAK,CAAC;IACzC,sBAAsB,CAAC,iBAAiB,GAAG,SAAS,CAAC;IACrD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export { initAssembly } from "./core/init-assembly.js";
|
|
2
2
|
export { withAssembly } from "./wrappers/index.js";
|
|
3
|
+
// Live op-control consumer (AAASM-3491). Subscribes to the gateway's
|
|
4
|
+
// OpControlStream and exposes per-op cooperative-pause / fast-fail-terminate;
|
|
5
|
+
// pass the subscriber as `withAssembly(..., { opControl })` so an operator
|
|
6
|
+
// terminate/pause reaches a running tool through the SDK tool path.
|
|
7
|
+
export { OpControlSubscriber } from "./op-control.js";
|
|
8
|
+
export { OpTerminatedError } from "./errors/op-terminated-error.js";
|
|
3
9
|
export { ENFORCEMENT_MODES } from "./types/index.js";
|
|
4
10
|
export { decodeAuditEvent, decodeCallStackNode, encodeAuditEvent, encodeCallStackNode } from "./audit/index.js";
|
|
5
11
|
export { currentAgentId, runWithAgentId } from "./lineage/index.js";
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qEAAqE;AACrE,8EAA8E;AAC9E,2EAA2E;AAC3E,oEAAoE;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAKtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAWpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpE,uEAAuE;AACvE,wEAAwE;AACxE,mEAAmE;AACnE,uEAAuE;AACvE,sDAAsD;AACtD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAU5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,wEAAwE;AACxE,qEAAqE;AACrE,sEAAsE;AACtE,6BAA6B;AAC7B,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the installed `@agent-assembly/sdk` package version, or `undefined`.
|
|
5
|
+
*
|
|
6
|
+
* Forwarded into the native `connect` so the user-facing npm package version —
|
|
7
|
+
* not the shared `aa-sdk-client` crate version — is what gets signed into the
|
|
8
|
+
* runtime handshake, giving accurate downgrade detection (AAASM-3683).
|
|
9
|
+
* `undefined` lets the native shim fall back to the crate version (no
|
|
10
|
+
* regression vs AAASM-3666). Uses `createRequire(<cwd>/package.json)`, the same
|
|
11
|
+
* ESM/CJS-safe pattern as the native-binding and runtime-binary resolvers.
|
|
12
|
+
*/
|
|
13
|
+
export function resolveSdkVersion() {
|
|
14
|
+
try {
|
|
15
|
+
const requireFromHere = createRequire(path.resolve(process.cwd(), "package.json"));
|
|
16
|
+
const pkg = requireFromHere("@agent-assembly/sdk/package.json");
|
|
17
|
+
return typeof pkg.version === "string" && pkg.version.length > 0 ? pkg.version : undefined;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
3
23
|
const NATIVE_BINDING_SINGLETON_KEY = Symbol.for("@agent-assembly/sdk/native-binding");
|
|
4
24
|
const ERROR_CONNECT = "AA_ERR_CONNECT";
|
|
5
25
|
const ERROR_SEND_EVENT = "AA_ERR_SEND_EVENT";
|
|
6
26
|
const ERROR_QUERY_POLICY = "AA_ERR_QUERY_POLICY";
|
|
27
|
+
const ERROR_REGISTER = "AA_ERR_REGISTER";
|
|
7
28
|
const ERROR_DISCONNECT = "AA_ERR_DISCONNECT";
|
|
8
29
|
export class NativeConnectError extends Error {
|
|
9
30
|
code = ERROR_CONNECT;
|
|
@@ -14,9 +35,31 @@ export class NativeSendEventError extends Error {
|
|
|
14
35
|
export class NativeQueryPolicyError extends Error {
|
|
15
36
|
code = ERROR_QUERY_POLICY;
|
|
16
37
|
}
|
|
38
|
+
export class NativeRegisterError extends Error {
|
|
39
|
+
code = ERROR_REGISTER;
|
|
40
|
+
}
|
|
17
41
|
export class NativeDisconnectError extends Error {
|
|
18
42
|
code = ERROR_DISCONNECT;
|
|
19
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Translate the native `{decision, reason}` verdict into the SDK's
|
|
46
|
+
* `PolicyResult`. Only `"deny"` blocks; `"pending"` routes to the approval
|
|
47
|
+
* path; `"allow"` / `"redact"` / any unrecognized value proceed. This mirrors
|
|
48
|
+
* the shared enforcement contract across the Python / Go / Node SDKs.
|
|
49
|
+
*
|
|
50
|
+
* The native primitive already fails open (returns `"allow"`) when the runtime
|
|
51
|
+
* is unreachable or too slow, so a missing or degraded runtime never blocks.
|
|
52
|
+
*/
|
|
53
|
+
function mapDecisionToPolicyResult(verdict) {
|
|
54
|
+
switch (verdict.decision) {
|
|
55
|
+
case "deny":
|
|
56
|
+
return { denied: true, pending: false, reason: verdict.reason };
|
|
57
|
+
case "pending":
|
|
58
|
+
return { denied: false, pending: true, reason: verdict.reason };
|
|
59
|
+
default:
|
|
60
|
+
return { denied: false, pending: false };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
20
63
|
function mapNativeError(error) {
|
|
21
64
|
if (!(error instanceof Error)) {
|
|
22
65
|
return new Error(String(error));
|
|
@@ -32,6 +75,9 @@ function mapNativeError(error) {
|
|
|
32
75
|
if (code === ERROR_QUERY_POLICY) {
|
|
33
76
|
return new NativeQueryPolicyError(detail);
|
|
34
77
|
}
|
|
78
|
+
if (code === ERROR_REGISTER) {
|
|
79
|
+
return new NativeRegisterError(detail);
|
|
80
|
+
}
|
|
35
81
|
if (code === ERROR_DISCONNECT) {
|
|
36
82
|
return new NativeDisconnectError(detail);
|
|
37
83
|
}
|
|
@@ -40,9 +86,7 @@ function mapNativeError(error) {
|
|
|
40
86
|
function loadNativeBinding() {
|
|
41
87
|
const shouldUseCache = process.env.VITEST !== "true";
|
|
42
88
|
const globalObject = globalThis;
|
|
43
|
-
const cachedBinding = shouldUseCache
|
|
44
|
-
? globalObject[NATIVE_BINDING_SINGLETON_KEY]
|
|
45
|
-
: undefined;
|
|
89
|
+
const cachedBinding = shouldUseCache ? globalObject[NATIVE_BINDING_SINGLETON_KEY] : undefined;
|
|
46
90
|
if (cachedBinding) {
|
|
47
91
|
return cachedBinding;
|
|
48
92
|
}
|
|
@@ -74,7 +118,11 @@ export function createNativeClient(options) {
|
|
|
74
118
|
mode,
|
|
75
119
|
close: async () => undefined,
|
|
76
120
|
sendEvent: () => undefined,
|
|
77
|
-
queryPolicy: async () => ({ denied: false, pending: false })
|
|
121
|
+
queryPolicy: async () => ({ denied: false, pending: false }),
|
|
122
|
+
// No native session to register against off the in-process path; the
|
|
123
|
+
// gRPC sidecar registers the agent in its own process. Resolve neutrally
|
|
124
|
+
// so init never blocks on a transport that does not own a handle.
|
|
125
|
+
register: async () => ""
|
|
78
126
|
};
|
|
79
127
|
}
|
|
80
128
|
const binding = loadNativeBinding();
|
|
@@ -82,20 +130,21 @@ export function createNativeClient(options) {
|
|
|
82
130
|
let handlePromise;
|
|
83
131
|
let activeHandle;
|
|
84
132
|
let pendingSendError;
|
|
133
|
+
const sdkVersion = resolveSdkVersion();
|
|
85
134
|
const getHandle = async () => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
135
|
+
handlePromise ??= binding
|
|
136
|
+
// Forward the npm package version so it is signed into the handshake
|
|
137
|
+
// (AAASM-3683); agent id is wired at register time, not connect.
|
|
138
|
+
.connect(socketPath, undefined, sdkVersion)
|
|
139
|
+
.then((handle) => {
|
|
140
|
+
activeHandle = handle;
|
|
141
|
+
return handle;
|
|
142
|
+
})
|
|
143
|
+
.catch((error) => {
|
|
144
|
+
handlePromise = undefined;
|
|
145
|
+
activeHandle = undefined;
|
|
146
|
+
throw mapNativeError(error);
|
|
147
|
+
});
|
|
99
148
|
return handlePromise;
|
|
100
149
|
};
|
|
101
150
|
return {
|
|
@@ -134,18 +183,36 @@ export function createNativeClient(options) {
|
|
|
134
183
|
pendingSendError = mapNativeError(error);
|
|
135
184
|
});
|
|
136
185
|
},
|
|
137
|
-
queryPolicy: async () => {
|
|
186
|
+
queryPolicy: async (action) => {
|
|
138
187
|
if (pendingSendError) {
|
|
139
188
|
const error = pendingSendError;
|
|
140
189
|
pendingSendError = undefined;
|
|
141
190
|
throw error;
|
|
142
191
|
}
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
192
|
+
// Connect (surfacing any connect error as a genuine local fault), then
|
|
193
|
+
// ask the runtime for an authoritative verdict via the native primitive.
|
|
194
|
+
// The native `queryPolicy` is async — it offloads its blocking wait to a
|
|
195
|
+
// worker thread, so awaiting it never blocks the Node event loop — and it
|
|
196
|
+
// already fails open (returns `"allow"`) when the runtime is unreachable
|
|
197
|
+
// or too slow, so a missing or degraded runtime never blocks the agent.
|
|
198
|
+
const handle = await getHandle();
|
|
199
|
+
const verdict = await binding.queryPolicy(handle, action);
|
|
200
|
+
return mapDecisionToPolicyResult(verdict);
|
|
201
|
+
},
|
|
202
|
+
register: async (options) => {
|
|
203
|
+
// Register on the same session the queryPolicy path uses, so the token
|
|
204
|
+
// the gateway issues is stored on this handle and attached to every
|
|
205
|
+
// subsequent query. This is the only direct SDK→gateway gRPC call
|
|
206
|
+
// (ADR 0004); CheckAction still flows through aa-runtime.
|
|
207
|
+
if (binding.register === undefined) {
|
|
208
|
+
// A binding without `register` predates AAASM-3400; the agent simply
|
|
209
|
+
// runs unregistered rather than failing init.
|
|
210
|
+
return "";
|
|
211
|
+
}
|
|
212
|
+
const handle = await getHandle();
|
|
213
|
+
return binding.register(handle, options).catch((error) => {
|
|
214
|
+
throw mapNativeError(error);
|
|
215
|
+
});
|
|
149
216
|
}
|
|
150
217
|
};
|
|
151
218
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/native/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/native/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WA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M,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC1D,OAAO,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QACD,QAAQ,EAAE,KAAK,EAAE,OAAwB,EAAE,EAAE;YAC3C,uEAAuE;YACvE,oEAAoE;YACpE,kEAAkE;YAClE,0DAA0D;YAC1D,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBACnC,qEAAqE;gBACrE,8CAA8C;gBAC9C,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;YACjC,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAChE,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/esm/op-control.js
CHANGED
|
@@ -19,37 +19,141 @@
|
|
|
19
19
|
* - Auto-wiring into the existing `GatewayClient` / adapter hooks
|
|
20
20
|
* (separate sub-task when the adapter surface is stable).
|
|
21
21
|
*/
|
|
22
|
-
import { credentials as grpcCredentials, } from "@grpc/grpc-js";
|
|
23
22
|
import { OpTerminatedError } from "./errors/op-terminated-error.js";
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Numeric `OpControlSignal` values, inlined to keep this module grpc-free at load.
|
|
25
|
+
*
|
|
26
|
+
* `OpControlSignal` lives in `./proto/generated/policy.js`, which imports
|
|
27
|
+
* `@grpc/grpc-js` at module scope; importing the enum as a *value* would defeat
|
|
28
|
+
* the lazy-load. These are the stable protobuf wire numbers (UNSPECIFIED=0,
|
|
29
|
+
* PAUSE=1, RESUME=2, TERMINATE=3) — `msg.signal` is compared against them
|
|
30
|
+
* numerically in {@link OpControlSubscriber.dispatch}. The `OpControlSignal`
|
|
31
|
+
* type is still imported (type-only) for signatures.
|
|
32
|
+
*/
|
|
33
|
+
const SIGNAL_PAUSE = 1;
|
|
34
|
+
const SIGNAL_RESUME = 2;
|
|
35
|
+
const SIGNAL_TERMINATE = 3;
|
|
36
|
+
/**
|
|
37
|
+
* Hosts treated as loopback for the secure-by-default transport decision.
|
|
38
|
+
* A loopback gateway is the local dev-mode CP, where plaintext gRPC is the
|
|
39
|
+
* documented default; anything else is presumed remote and must be encrypted.
|
|
40
|
+
*/
|
|
41
|
+
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
42
|
+
/**
|
|
43
|
+
* Extract the bare host from a gRPC target (`host:port`, a bare host, or a
|
|
44
|
+
* URL-style `scheme://host:port`). Returns the lowercased host with any
|
|
45
|
+
* surrounding IPv6 brackets preserved so it can be matched against
|
|
46
|
+
* {@link LOOPBACK_HOSTS}.
|
|
47
|
+
*/
|
|
48
|
+
export function gatewayHostOf(gatewayUrl) {
|
|
49
|
+
let target = gatewayUrl.trim();
|
|
50
|
+
const schemeIdx = target.indexOf("://");
|
|
51
|
+
if (schemeIdx !== -1)
|
|
52
|
+
target = target.slice(schemeIdx + 3);
|
|
53
|
+
// Drop a path/query suffix if a URL form was passed.
|
|
54
|
+
const slashIdx = target.indexOf("/");
|
|
55
|
+
if (slashIdx !== -1)
|
|
56
|
+
target = target.slice(0, slashIdx);
|
|
57
|
+
if (target.startsWith("[")) {
|
|
58
|
+
// Bracketed IPv6: keep the bracketed form, strip only the trailing :port.
|
|
59
|
+
const close = target.indexOf("]");
|
|
60
|
+
return close === -1 ? target.toLowerCase() : target.slice(0, close + 1).toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
const colonIdx = target.indexOf(":");
|
|
63
|
+
if (colonIdx !== -1)
|
|
64
|
+
target = target.slice(0, colonIdx);
|
|
65
|
+
return target.toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
function isLoopbackTarget(gatewayUrl) {
|
|
68
|
+
return LOOPBACK_HOSTS.has(gatewayHostOf(gatewayUrl));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Pick channel credentials for the op-control stream, secure by default.
|
|
72
|
+
*
|
|
73
|
+
* Precedence: an explicit `credentials` override wins; otherwise a loopback
|
|
74
|
+
* target gets plaintext (local dev gateway), a remote target gets TLS, and a
|
|
75
|
+
* remote target is only allowed plaintext when the caller sets `allowInsecure`.
|
|
76
|
+
*
|
|
77
|
+
* `grpcCredentials` is injected (rather than imported at module scope) so this
|
|
78
|
+
* module does not eagerly load `@grpc/grpc-js` — see the module header. The
|
|
79
|
+
* real-connect path passes the lazily-imported `credentials` namespace.
|
|
80
|
+
*
|
|
81
|
+
* @throws never — returns the chosen {@link ChannelCredentials}.
|
|
82
|
+
*/
|
|
83
|
+
export function resolveOpControlCredentials(gatewayUrl, opts, grpcCredentials) {
|
|
84
|
+
if (opts.credentials)
|
|
85
|
+
return opts.credentials;
|
|
86
|
+
if (isLoopbackTarget(gatewayUrl))
|
|
87
|
+
return grpcCredentials.createInsecure();
|
|
88
|
+
if (opts.allowInsecure)
|
|
89
|
+
return grpcCredentials.createInsecure();
|
|
90
|
+
return grpcCredentials.createSsl();
|
|
91
|
+
}
|
|
25
92
|
export class OpControlSubscriber {
|
|
26
|
-
|
|
93
|
+
/**
|
|
94
|
+
* `null` until the channel is opened. On the test-seam (`clientFactory`) path
|
|
95
|
+
* it is set synchronously in {@link connect}; on the real-connect path it is
|
|
96
|
+
* set asynchronously once `@grpc/grpc-js` + `PolicyServiceClient` have been
|
|
97
|
+
* lazily imported (see {@link openRealChannel}).
|
|
98
|
+
*/
|
|
99
|
+
client = null;
|
|
27
100
|
agent;
|
|
28
101
|
ops = new Map();
|
|
29
102
|
call = null;
|
|
30
103
|
alive = true;
|
|
31
|
-
|
|
32
|
-
|
|
104
|
+
/** Set once {@link close} is called before the async channel finishes opening. */
|
|
105
|
+
closed = false;
|
|
106
|
+
constructor(agent) {
|
|
33
107
|
this.agent = agent;
|
|
34
108
|
}
|
|
35
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Open the gRPC channel + subscription stream and start the reader.
|
|
111
|
+
*
|
|
112
|
+
* Returns synchronously. On the real-connect path the channel is opened
|
|
113
|
+
* asynchronously — `@grpc/grpc-js` and `PolicyServiceClient` are loaded lazily
|
|
114
|
+
* (`await import`) so that importing this module never eagerly pulls grpc (see
|
|
115
|
+
* the module header). The test seam (`clientFactory`) opens synchronously and
|
|
116
|
+
* never touches grpc.
|
|
117
|
+
*/
|
|
36
118
|
static connect(gatewayUrl, opts) {
|
|
37
119
|
const agent = {
|
|
38
120
|
orgId: opts.orgId,
|
|
39
121
|
teamId: opts.teamId,
|
|
40
|
-
agentId: opts.agentId
|
|
122
|
+
agentId: opts.agentId
|
|
41
123
|
};
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
124
|
+
const subscriber = new OpControlSubscriber(agent);
|
|
125
|
+
if (opts.clientFactory) {
|
|
126
|
+
subscriber.client = opts.clientFactory();
|
|
127
|
+
subscriber.start();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Real channel: defer grpc loading to the dynamic-import path. Errors
|
|
131
|
+
// surface as a dead stream so callers see `streamAlive() === false`.
|
|
132
|
+
void subscriber.openRealChannel(gatewayUrl, opts).catch(() => {
|
|
133
|
+
subscriber.markStreamDead();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
47
136
|
return subscriber;
|
|
48
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Lazily import grpc + the policy client, build the real client, and start the
|
|
140
|
+
* reader. Kept off the module's import graph so `import '@agent-assembly/sdk'`
|
|
141
|
+
* stays grpc-free until a subscriber actually opens a live channel.
|
|
142
|
+
*/
|
|
143
|
+
async openRealChannel(gatewayUrl, opts) {
|
|
144
|
+
const { credentials } = await import("@grpc/grpc-js");
|
|
145
|
+
const { PolicyServiceClient } = await import("./proto/generated/policy.js");
|
|
146
|
+
if (this.closed)
|
|
147
|
+
return; // close() raced ahead of the async open.
|
|
148
|
+
this.client = new PolicyServiceClient(gatewayUrl, resolveOpControlCredentials(gatewayUrl, opts, credentials));
|
|
149
|
+
this.start();
|
|
150
|
+
}
|
|
49
151
|
/** Open the stream and wire reader handlers. Public so tests can call
|
|
50
152
|
* directly after constructing with a hand-rolled client.
|
|
51
153
|
*/
|
|
52
154
|
start() {
|
|
155
|
+
if (!this.client)
|
|
156
|
+
return;
|
|
53
157
|
this.call = this.client.opControlStream({ agentId: this.agent });
|
|
54
158
|
this.call.on("data", (msg) => this.dispatch(msg));
|
|
55
159
|
this.call.on("error", () => this.markStreamDead());
|
|
@@ -58,14 +162,14 @@ export class OpControlSubscriber {
|
|
|
58
162
|
dispatch(msg) {
|
|
59
163
|
const state = this.slot(msg.opId);
|
|
60
164
|
switch (msg.signal) {
|
|
61
|
-
case
|
|
165
|
+
case SIGNAL_PAUSE:
|
|
62
166
|
state.paused = true;
|
|
63
167
|
break;
|
|
64
|
-
case
|
|
168
|
+
case SIGNAL_RESUME:
|
|
65
169
|
state.paused = false;
|
|
66
170
|
this.flushResolvers(state);
|
|
67
171
|
break;
|
|
68
|
-
case
|
|
172
|
+
case SIGNAL_TERMINATE:
|
|
69
173
|
state.terminated = true;
|
|
70
174
|
this.flushResolvers(state);
|
|
71
175
|
break;
|
|
@@ -137,10 +241,13 @@ export class OpControlSubscriber {
|
|
|
137
241
|
streamAlive() {
|
|
138
242
|
return this.alive;
|
|
139
243
|
}
|
|
140
|
-
/** Cancel the stream and clean up.
|
|
244
|
+
/** Cancel the stream and clean up. Safe to call before the async real-channel
|
|
245
|
+
* open has completed — it flags `closed` so the pending open bails out.
|
|
246
|
+
*/
|
|
141
247
|
close() {
|
|
248
|
+
this.closed = true;
|
|
142
249
|
this.call?.cancel();
|
|
143
|
-
this.client
|
|
250
|
+
this.client?.close?.();
|
|
144
251
|
this.markStreamDead();
|
|
145
252
|
}
|
|
146
253
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"op-control.js","sourceRoot":"","sources":["../../src/op-control.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;
|
|
1
|
+
{"version":3,"file":"op-control.js","sourceRoot":"","sources":["../../src/op-control.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAaH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAQpE;;;;;;;;;GASG;AACH,MAAM,YAAY,GAAoB,CAAC,CAAC;AACxC,MAAM,aAAa,GAAoB,CAAC,CAAC;AACzC,MAAM,gBAAgB,GAAoB,CAAC,CAAC;AA2C5C;;;;GAIG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB;IAC9C,IAAI,MAAM,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;IAC/B,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,SAAS,KAAK,CAAC,CAAC;QAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IAC3D,qDAAqD;IACrD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,QAAQ,KAAK,CAAC,CAAC;QAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACxD,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,0EAA0E;QAC1E,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CA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AK,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,iBAAiB,CAAC,MAAM,IAAI,gCAAgC,EAAE,IAAI,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;IAEM,QAAQ,CAAC,IAAY;QAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,KAAK,CAAC;IAC7C,CAAC;IAEM,YAAY,CAAC,IAAY;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,IAAI,KAAK,CAAC;IACjD,CAAC;IAEM,WAAW;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QACpB,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACvB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;CACF"}
|
package/dist/esm/runtime.js
CHANGED
|
@@ -12,11 +12,18 @@ import { existsSync, openSync } from "node:fs";
|
|
|
12
12
|
import { createRequire } from "node:module";
|
|
13
13
|
import { createConnection } from "node:net";
|
|
14
14
|
import { arch, homedir, platform } from "node:os";
|
|
15
|
-
import { delimiter as PATH_DELIM, dirname, join } from "node:path";
|
|
15
|
+
import { delimiter as PATH_DELIM, dirname, isAbsolute, join, resolve as resolvePath } from "node:path";
|
|
16
16
|
import { cwd, env } from "node:process";
|
|
17
17
|
export const BINARY_NAME = "aasm";
|
|
18
18
|
export const DEFAULT_PORT = 7878;
|
|
19
19
|
export const DEFAULT_RUNTIME_HOST = "127.0.0.1";
|
|
20
|
+
/**
|
|
21
|
+
* Opt-in gate for spawning the `aasm` sidecar. Auto-start runs a binary
|
|
22
|
+
* discovered from `$PATH` / the filesystem, so it is a privileged side effect
|
|
23
|
+
* that must be explicitly enabled rather than triggered silently by every
|
|
24
|
+
* `initAssembly()` call. Set to `1`/`true`/`yes` to permit auto-start.
|
|
25
|
+
*/
|
|
26
|
+
export const ENV_AUTO_START = "AA_AUTO_START";
|
|
20
27
|
export const USER_LOCAL_BIN = join(homedir(), ".local", "bin");
|
|
21
28
|
export const DOCKER_BASE_BIN = "/usr/local/bin";
|
|
22
29
|
export const RUNTIME_LOG_FILENAME = ".aasm-runtime.log";
|
|
@@ -93,6 +100,51 @@ export function isRunning(port = DEFAULT_PORT, host = DEFAULT_RUNTIME_HOST) {
|
|
|
93
100
|
socket.once("error", () => settle(false));
|
|
94
101
|
});
|
|
95
102
|
}
|
|
103
|
+
/** Truthy values that enable {@link ENV_AUTO_START}. */
|
|
104
|
+
function autoStartEnabled() {
|
|
105
|
+
const raw = env[ENV_AUTO_START]?.trim().toLowerCase();
|
|
106
|
+
return raw === "1" || raw === "true" || raw === "yes";
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Install roots an auto-started `aasm` binary is permitted to live in, in
|
|
110
|
+
* addition to the npm-bundled `node_modules/@agent-assembly/runtime-*` path
|
|
111
|
+
* (which is trusted because it ships with the SDK install). This blocks a
|
|
112
|
+
* `$PATH`-injected `./aasm` or a binary planted in an arbitrary writable
|
|
113
|
+
* directory from being spawned.
|
|
114
|
+
*/
|
|
115
|
+
function allowedInstallDirs() {
|
|
116
|
+
const home = homedir();
|
|
117
|
+
return [
|
|
118
|
+
"/usr/local/bin",
|
|
119
|
+
"/usr/bin",
|
|
120
|
+
"/opt/homebrew/bin",
|
|
121
|
+
USER_LOCAL_BIN,
|
|
122
|
+
join(home, ".cargo", "bin"),
|
|
123
|
+
"/usr/local/cargo/bin",
|
|
124
|
+
DOCKER_BASE_BIN,
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Throw `Error` unless `binaryPath` is safe to spawn: it must be absolute and
|
|
129
|
+
* either resolve inside an allow-listed install dir (see
|
|
130
|
+
* {@link allowedInstallDirs}) or be the npm-bundled runtime binary. This is the
|
|
131
|
+
* integrity gate for the auto-start subprocess — without it the SDK would
|
|
132
|
+
* execute whatever `aasm` happened to be first on `$PATH`.
|
|
133
|
+
*/
|
|
134
|
+
export function assertSafeBinaryPath(binaryPath) {
|
|
135
|
+
if (!isAbsolute(binaryPath)) {
|
|
136
|
+
throw new Error(`Refusing to auto-start a non-absolute 'aasm' path: ${binaryPath}`);
|
|
137
|
+
}
|
|
138
|
+
const resolved = resolvePath(binaryPath);
|
|
139
|
+
const bundled = bundledRuntimeBinaryPath();
|
|
140
|
+
if (bundled !== null && resolvePath(bundled) === resolved)
|
|
141
|
+
return;
|
|
142
|
+
const ok = allowedInstallDirs().some((dir) => resolved.startsWith(resolvePath(dir) + "/"));
|
|
143
|
+
if (!ok) {
|
|
144
|
+
throw new Error(`Refusing to auto-start 'aasm' from an untrusted location: ${resolved}. ` +
|
|
145
|
+
`Install it under one of: ${allowedInstallDirs().join(", ")}.`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
96
148
|
/**
|
|
97
149
|
* Spawn `aasm serve --port <port>` as a detached background subprocess.
|
|
98
150
|
*
|
|
@@ -119,20 +171,33 @@ export function startRuntime(binaryPath, port = DEFAULT_PORT, logDir = cwd()) {
|
|
|
119
171
|
* 2. Resolve the binary via {@link findAasmBinary}.
|
|
120
172
|
* 3. Spawn the sidecar via {@link startRuntime}.
|
|
121
173
|
*
|
|
122
|
-
* `
|
|
123
|
-
*
|
|
124
|
-
* `@agent-assembly/sdk` `initAssembly`
|
|
174
|
+
* `_agentId` is accepted to keep the ticket-specified signature stable but is
|
|
175
|
+
* intentionally not consumed at this lifecycle layer; actual register-and-connect
|
|
176
|
+
* is performed by the existing gateway-aware `@agent-assembly/sdk` `initAssembly`
|
|
177
|
+
* once the sidecar is reachable.
|
|
178
|
+
*
|
|
179
|
+
* Auto-start is **opt-in**: when the sidecar is not already running, this
|
|
180
|
+
* throws unless `AA_AUTO_START` is enabled. When it does spawn, the resolved
|
|
181
|
+
* binary path is logged and integrity-checked via {@link assertSafeBinaryPath}.
|
|
125
182
|
*
|
|
126
|
-
* Throws `Error` with {@link INSTALL_HINT} when no binary is found
|
|
183
|
+
* Throws `Error` with {@link INSTALL_HINT} when no binary is found, and a
|
|
184
|
+
* descriptive `Error` when auto-start is not opted in or the resolved binary
|
|
185
|
+
* fails the integrity check.
|
|
127
186
|
*/
|
|
128
|
-
export async function initAssembly(
|
|
129
|
-
void agentId; // not consumed at the lifecycle layer; see jsdoc
|
|
187
|
+
export async function initAssembly(_agentId, port = DEFAULT_PORT) {
|
|
130
188
|
if (await isRunning(port))
|
|
131
189
|
return;
|
|
190
|
+
if (!autoStartEnabled()) {
|
|
191
|
+
throw new Error(`No aasm sidecar running on port ${port} and auto-start is disabled. ` +
|
|
192
|
+
`Start it with 'aasm serve --port ${port}', or set ${ENV_AUTO_START}=1 ` +
|
|
193
|
+
"to allow the SDK to auto-start it.");
|
|
194
|
+
}
|
|
132
195
|
const binary = findAasmBinary();
|
|
133
196
|
if (binary === null) {
|
|
134
197
|
throw new Error(INSTALL_HINT);
|
|
135
198
|
}
|
|
199
|
+
assertSafeBinaryPath(binary);
|
|
200
|
+
console.info(`[agent-assembly] auto-starting aasm sidecar from ${binary}`);
|
|
136
201
|
startRuntime(binary, port);
|
|
137
202
|
}
|
|
138
203
|
//# sourceMappingURL=runtime.js.map
|