memeloop 0.0.1 → 0.1.0
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 +63 -0
- package/dist/browser.cjs +1413 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +3066 -0
- package/dist/browser.d.ts +3066 -0
- package/dist/browser.js +43 -0
- package/dist/chunk-426CJUZP.js +630 -0
- package/dist/chunk-426CJUZP.js.map +1 -0
- package/dist/chunk-44YHBKDL.js +382 -0
- package/dist/chunk-44YHBKDL.js.map +1 -0
- package/dist/chunk-7ZDTB4VZ.js +63 -0
- package/dist/chunk-7ZDTB4VZ.js.map +1 -0
- package/dist/chunk-AZFYDWIN.js +98 -0
- package/dist/chunk-AZFYDWIN.js.map +1 -0
- package/dist/chunk-BGPU4RR7.js +367 -0
- package/dist/chunk-BGPU4RR7.js.map +1 -0
- package/dist/chunk-CCEFAOSH.js +496 -0
- package/dist/chunk-CCEFAOSH.js.map +1 -0
- package/dist/chunk-FWSY5HOA.js +63 -0
- package/dist/chunk-FWSY5HOA.js.map +1 -0
- package/dist/chunk-GYIOMQMY.js +8726 -0
- package/dist/chunk-GYIOMQMY.js.map +1 -0
- package/dist/chunk-HVB2BR3H.js +42 -0
- package/dist/chunk-HVB2BR3H.js.map +1 -0
- package/dist/chunk-K6P63KD4.js +68 -0
- package/dist/chunk-K6P63KD4.js.map +1 -0
- package/dist/chunk-MRKY4HGF.js +205 -0
- package/dist/chunk-MRKY4HGF.js.map +1 -0
- package/dist/chunk-QFHAAIIM.js +2657 -0
- package/dist/chunk-QFHAAIIM.js.map +1 -0
- package/dist/chunk-VZKQX5PP.js +1 -0
- package/dist/chunk-VZKQX5PP.js.map +1 -0
- package/dist/chunk-WAI6BODI.js +175 -0
- package/dist/chunk-WAI6BODI.js.map +1 -0
- package/dist/chunk-XHRBV6I3.js +3637 -0
- package/dist/chunk-XHRBV6I3.js.map +1 -0
- package/dist/chunk-YMNXDNDW.js +798 -0
- package/dist/chunk-YMNXDNDW.js.map +1 -0
- package/dist/conversation.cjs +208 -0
- package/dist/conversation.cjs.map +1 -0
- package/dist/conversation.d.cts +100 -0
- package/dist/conversation.d.ts +100 -0
- package/dist/conversation.js +21 -0
- package/dist/conversation.js.map +1 -0
- package/dist/device-network-portable.cjs +702 -0
- package/dist/device-network-portable.cjs.map +1 -0
- package/dist/device-network-portable.d.cts +110 -0
- package/dist/device-network-portable.d.ts +110 -0
- package/dist/device-network-portable.js +53 -0
- package/dist/device-network-portable.js.map +1 -0
- package/dist/device-network.cjs +906 -0
- package/dist/device-network.cjs.map +1 -0
- package/dist/device-network.d.cts +6 -0
- package/dist/device-network.d.ts +6 -0
- package/dist/device-network.js +59 -0
- package/dist/device-network.js.map +1 -0
- package/dist/fetchProvider-BpcGVSOG.d.cts +91 -0
- package/dist/fetchProvider-Cm0sO4Tl.d.ts +91 -0
- package/dist/index.cjs +27957 -5459
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -1320
- package/dist/index.d.ts +94 -1320
- package/dist/index.js +10576 -2386
- package/dist/index.js.map +1 -1
- package/dist/interface-IrKBFtL1.d.cts +493 -0
- package/dist/interface-IrKBFtL1.d.ts +493 -0
- package/dist/llm-providers.cjs +43 -8
- package/dist/llm-providers.cjs.map +1 -1
- package/dist/llm-providers.d.cts +2 -1
- package/dist/llm-providers.d.ts +2 -1
- package/dist/llm-providers.js +4 -2
- package/dist/llm-providers.js.map +1 -1
- package/dist/loop-api.cjs +5177 -2050
- package/dist/loop-api.cjs.map +1 -1
- package/dist/loop-api.d.cts +11 -5
- package/dist/loop-api.d.ts +11 -5
- package/dist/loop-api.js +84 -49
- package/dist/mobile.cjs +2625 -0
- package/dist/mobile.cjs.map +1 -0
- package/dist/mobile.d.cts +6 -0
- package/dist/mobile.d.ts +6 -0
- package/dist/mobile.js +22 -0
- package/dist/mobile.js.map +1 -0
- package/dist/orchestration-portable-Bsf8YRfp.d.cts +2192 -0
- package/dist/orchestration-portable-Zw0g5tbj.d.ts +2192 -0
- package/dist/orchestration-portable.cjs +9553 -0
- package/dist/orchestration-portable.cjs.map +1 -0
- package/dist/orchestration-portable.d.cts +5 -0
- package/dist/orchestration-portable.d.ts +5 -0
- package/dist/orchestration-portable.js +290 -0
- package/dist/orchestration-portable.js.map +1 -0
- package/dist/pairingInvite-BXPWY3aM.d.cts +149 -0
- package/dist/pairingInvite-Cuz0wuq9.d.ts +149 -0
- package/dist/promptConcat-WTN-uHcz.d.cts +516 -0
- package/dist/promptConcat-deDSWZE3.d.ts +516 -0
- package/dist/providerRegistry-9trr5aoK.d.ts +86 -0
- package/dist/providerRegistry-xk_B1Ekv.d.cts +86 -0
- package/dist/registry-8eztoD_r.d.cts +393 -0
- package/dist/registry-DV24sI-3.d.ts +393 -0
- package/dist/remoteClient-B_spK019.d.ts +87 -0
- package/dist/remoteClient-CBggnRy3.d.cts +87 -0
- package/dist/runtime-SKSXVYIM.js +18 -0
- package/dist/runtime-SKSXVYIM.js.map +1 -0
- package/dist/scriptDeploymentPipeline-BAeo1dPb.d.cts +2463 -0
- package/dist/scriptDeploymentPipeline-DsnT0AG6.d.ts +2463 -0
- package/dist/syncCloudDevices-BEqwgrhD.d.ts +49 -0
- package/dist/syncCloudDevices-Ds_Kcgrv.d.cts +49 -0
- package/dist/types-7pYti-k9.d.cts +255 -0
- package/dist/types-CdFVSntj.d.ts +255 -0
- package/package.json +110 -35
- package/dist/anthropic.cjs +0 -72
- package/dist/anthropic.cjs.map +0 -1
- package/dist/anthropic.d.cts +0 -21
- package/dist/anthropic.d.ts +0 -21
- package/dist/anthropic.js +0 -21
- package/dist/anthropic.js.map +0 -1
- package/dist/azure.cjs +0 -72
- package/dist/azure.cjs.map +0 -1
- package/dist/azure.d.cts +0 -21
- package/dist/azure.d.ts +0 -21
- package/dist/azure.js +0 -21
- package/dist/azure.js.map +0 -1
- package/dist/chunk-3CN7DFBL.js +0 -4894
- package/dist/chunk-3CN7DFBL.js.map +0 -1
- package/dist/chunk-4AZ4D7U5.js +0 -32
- package/dist/chunk-4AZ4D7U5.js.map +0 -1
- package/dist/chunk-6ON4XSOV.js +0 -63
- package/dist/chunk-6ON4XSOV.js.map +0 -1
- package/dist/chunk-DJQNGIXX.js +0 -4793
- package/dist/chunk-DJQNGIXX.js.map +0 -1
- package/dist/chunk-FKQP6AOQ.js +0 -32
- package/dist/chunk-FKQP6AOQ.js.map +0 -1
- package/dist/chunk-OVJ7JJBA.js +0 -35
- package/dist/chunk-OVJ7JJBA.js.map +0 -1
- package/dist/chunk-P4UZ7IXC.js +0 -42
- package/dist/chunk-YHJ2AEFR.js +0 -4933
- package/dist/chunk-YHJ2AEFR.js.map +0 -1
- package/dist/chunk-YVK7RYRO.js +0 -4973
- package/dist/chunk-YVK7RYRO.js.map +0 -1
- package/dist/code-assistant.json +0 -114
- package/dist/cohere.cjs +0 -72
- package/dist/cohere.cjs.map +0 -1
- package/dist/cohere.d.cts +0 -21
- package/dist/cohere.d.ts +0 -21
- package/dist/cohere.js +0 -21
- package/dist/cohere.js.map +0 -1
- package/dist/deepseek.cjs +0 -72
- package/dist/deepseek.cjs.map +0 -1
- package/dist/deepseek.d.cts +0 -21
- package/dist/deepseek.d.ts +0 -21
- package/dist/deepseek.js +0 -21
- package/dist/deepseek.js.map +0 -1
- package/dist/dist-65U7OYRG.js +0 -1257
- package/dist/dist-65U7OYRG.js.map +0 -1
- package/dist/fetchProvider-Cu4WkU5O.d.cts +0 -819
- package/dist/fetchProvider-Cu4WkU5O.d.ts +0 -819
- package/dist/frontend-ui-ux.json +0 -105
- package/dist/general-assistant.json +0 -95
- package/dist/git-master.json +0 -51
- package/dist/google-vertex.cjs +0 -72
- package/dist/google-vertex.cjs.map +0 -1
- package/dist/google-vertex.d.cts +0 -21
- package/dist/google-vertex.d.ts +0 -21
- package/dist/google-vertex.js +0 -21
- package/dist/google-vertex.js.map +0 -1
- package/dist/google.cjs +0 -72
- package/dist/google.cjs.map +0 -1
- package/dist/google.d.cts +0 -21
- package/dist/google.d.ts +0 -21
- package/dist/google.js +0 -21
- package/dist/google.js.map +0 -1
- package/dist/groq.cjs +0 -72
- package/dist/groq.cjs.map +0 -1
- package/dist/groq.d.cts +0 -21
- package/dist/groq.d.ts +0 -21
- package/dist/groq.js +0 -21
- package/dist/groq.js.map +0 -1
- package/dist/index.d.mts +0 -3203
- package/dist/index.mjs +0 -7064
- package/dist/index.mjs.map +0 -1
- package/dist/mistral.cjs +0 -72
- package/dist/mistral.cjs.map +0 -1
- package/dist/mistral.d.cts +0 -21
- package/dist/mistral.d.ts +0 -21
- package/dist/mistral.js +0 -21
- package/dist/mistral.js.map +0 -1
- package/dist/multipart-parser-EJCXIUHC.js +0 -372
- package/dist/multipart-parser-EJCXIUHC.js.map +0 -1
- package/dist/openai.cjs +0 -72
- package/dist/openai.cjs.map +0 -1
- package/dist/openai.d.cts +0 -21
- package/dist/openai.d.ts +0 -21
- package/dist/openai.js +0 -21
- package/dist/openai.js.map +0 -1
- package/dist/perplexity.cjs +0 -72
- package/dist/perplexity.cjs.map +0 -1
- package/dist/perplexity.d.cts +0 -21
- package/dist/perplexity.d.ts +0 -21
- package/dist/perplexity.js +0 -21
- package/dist/perplexity.js.map +0 -1
- package/dist/playwright.json +0 -52
- package/dist/promptConcat-BJdazTg5.d.cts +0 -1832
- package/dist/promptConcat-BJdazTg5.d.ts +0 -1832
- package/dist/promptConcat-CAkpni_8.d.cts +0 -1834
- package/dist/promptConcat-CAkpni_8.d.ts +0 -1834
- package/dist/promptConcat-CfH5-GAE.d.cts +0 -1036
- package/dist/promptConcat-ChcAZOOL.d.ts +0 -1036
- package/dist/promptConcat-G5TnJVRy.d.cts +0 -1800
- package/dist/promptConcat-G5TnJVRy.d.ts +0 -1800
- package/dist/promptConcat-L72eowzp.d.ts +0 -1090
- package/dist/promptConcat-eLHdN7K8.d.cts +0 -1090
- package/dist/src-VTSXKG72.js +0 -1409
- package/dist/src-VTSXKG72.js.map +0 -1
- package/dist/togetherai.cjs +0 -72
- package/dist/togetherai.cjs.map +0 -1
- package/dist/togetherai.d.cts +0 -21
- package/dist/togetherai.d.ts +0 -21
- package/dist/togetherai.js +0 -21
- package/dist/togetherai.js.map +0 -1
- package/dist/types-B0Jm2l38.d.cts +0 -767
- package/dist/types-B0Jm2l38.d.ts +0 -767
- package/dist/xai.cjs +0 -72
- package/dist/xai.cjs.map +0 -1
- package/dist/xai.d.cts +0 -21
- package/dist/xai.d.ts +0 -21
- package/dist/xai.js +0 -21
- package/dist/xai.js.map +0 -1
- /package/dist/{chunk-P4UZ7IXC.js.map → browser.js.map} +0 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OrchestrationError
|
|
3
|
+
} from "./chunk-FWSY5HOA.js";
|
|
4
|
+
|
|
5
|
+
// src/orchestration/remoteClient.ts
|
|
6
|
+
var REMOTE_ORCHESTRATION_PROTOCOL = "memeloop.resource.v1";
|
|
7
|
+
var REMOTE_OPERATIONS = /* @__PURE__ */ new Set([
|
|
8
|
+
"capabilities",
|
|
9
|
+
"apply",
|
|
10
|
+
"get",
|
|
11
|
+
"list",
|
|
12
|
+
"watch",
|
|
13
|
+
"delete"
|
|
14
|
+
]);
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
function errorData(error) {
|
|
19
|
+
if (error instanceof OrchestrationError) {
|
|
20
|
+
return {
|
|
21
|
+
code: error.code,
|
|
22
|
+
message: error.message,
|
|
23
|
+
retryable: error.retryable,
|
|
24
|
+
...error.retryAfterMs !== void 0 ? { retryAfterMs: error.retryAfterMs } : {},
|
|
25
|
+
...error.reason !== void 0 ? { reason: error.reason } : {},
|
|
26
|
+
...error.details !== void 0 ? { details: error.details } : {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
code: "INTERNAL",
|
|
31
|
+
message: error instanceof Error ? error.message : String(error),
|
|
32
|
+
retryable: false
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function throwResponseError(response) {
|
|
36
|
+
throw new OrchestrationError(response.error);
|
|
37
|
+
}
|
|
38
|
+
function assertResponse(request, response) {
|
|
39
|
+
if (!isRecord(response) || response.protocol !== REMOTE_ORCHESTRATION_PROTOCOL || response.requestId !== request.requestId || typeof response.ok !== "boolean" || response.ok && !("result" in response) || !response.ok && (!isRecord(response.error) || typeof response.error.code !== "string" || typeof response.error.message !== "string" || typeof response.error.retryable !== "boolean")) {
|
|
40
|
+
throw new OrchestrationError({
|
|
41
|
+
code: "INVALID",
|
|
42
|
+
message: "remote orchestration response correlation or protocol mismatch",
|
|
43
|
+
retryable: false
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
var requestSequence = 0;
|
|
48
|
+
function createRemoteOrchestrationClient(transport, options = {}) {
|
|
49
|
+
const createRequestId = options.createRequestId ?? (() => `resource-${Date.now().toString(36)}-${(++requestSequence).toString(36)}`);
|
|
50
|
+
function makeRequest(operation, payload) {
|
|
51
|
+
return {
|
|
52
|
+
protocol: REMOTE_ORCHESTRATION_PROTOCOL,
|
|
53
|
+
requestId: createRequestId(),
|
|
54
|
+
operation,
|
|
55
|
+
payload
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async function request(operation, payload, signal) {
|
|
59
|
+
const envelope = makeRequest(operation, payload);
|
|
60
|
+
const response = await transport.request(envelope, { signal });
|
|
61
|
+
assertResponse(envelope, response);
|
|
62
|
+
if (!response.ok) throwResponseError(response);
|
|
63
|
+
return response.result;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
getCapabilities() {
|
|
67
|
+
return request("capabilities", {});
|
|
68
|
+
},
|
|
69
|
+
apply(resource, applyOptions) {
|
|
70
|
+
return request("apply", {
|
|
71
|
+
resource,
|
|
72
|
+
...applyOptions ? { options: applyOptions } : {}
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
get(reference, getOptions) {
|
|
76
|
+
return request("get", {
|
|
77
|
+
reference,
|
|
78
|
+
...getOptions ? { options: getOptions } : {}
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
list(query, listOptions) {
|
|
82
|
+
return request("list", {
|
|
83
|
+
query,
|
|
84
|
+
...listOptions ? { options: listOptions } : {}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
async *watch(query, watchOptions) {
|
|
88
|
+
const envelope = makeRequest("watch", {
|
|
89
|
+
query,
|
|
90
|
+
...watchOptions ? {
|
|
91
|
+
options: {
|
|
92
|
+
...watchOptions,
|
|
93
|
+
signal: void 0
|
|
94
|
+
}
|
|
95
|
+
} : {}
|
|
96
|
+
});
|
|
97
|
+
for await (const response of transport.watch(envelope, {
|
|
98
|
+
signal: watchOptions?.signal
|
|
99
|
+
})) {
|
|
100
|
+
assertResponse(envelope, response);
|
|
101
|
+
if (!response.ok) throwResponseError(response);
|
|
102
|
+
yield response.result;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
delete(reference, deleteOptions) {
|
|
106
|
+
return request("delete", {
|
|
107
|
+
reference,
|
|
108
|
+
...deleteOptions ? { options: deleteOptions } : {}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function createReadOnlyOrchestrationClient(client, options = {}) {
|
|
114
|
+
const allowedKinds = options.allowedResourceKinds ? new Set(options.allowedResourceKinds) : void 0;
|
|
115
|
+
function assertAllowedKind(kind) {
|
|
116
|
+
if (!allowedKinds || allowedKinds.has(kind)) return;
|
|
117
|
+
throw new OrchestrationError({
|
|
118
|
+
code: "FORBIDDEN",
|
|
119
|
+
message: `remote orchestration access to resource kind '${kind}' is forbidden`,
|
|
120
|
+
retryable: false
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function forbidden(operation) {
|
|
124
|
+
throw new OrchestrationError({
|
|
125
|
+
code: "FORBIDDEN",
|
|
126
|
+
message: `remote orchestration operation '${operation}' is read-only`,
|
|
127
|
+
retryable: false
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
async getCapabilities() {
|
|
132
|
+
const capabilities = await client.getCapabilities();
|
|
133
|
+
return {
|
|
134
|
+
operations: ["get", "list", "watch"],
|
|
135
|
+
resourceKinds: capabilities.resourceKinds.filter((kind) => allowedKinds ? allowedKinds.has(kind) : true),
|
|
136
|
+
interfaces: capabilities.interfaces.includes("resource") ? ["resource"] : []
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
async apply() {
|
|
140
|
+
forbidden("apply");
|
|
141
|
+
},
|
|
142
|
+
async get(reference, getOptions) {
|
|
143
|
+
assertAllowedKind(reference.kind);
|
|
144
|
+
return await client.get(reference, getOptions);
|
|
145
|
+
},
|
|
146
|
+
async list(query, listOptions) {
|
|
147
|
+
assertAllowedKind(query.kind);
|
|
148
|
+
return await client.list(query, listOptions);
|
|
149
|
+
},
|
|
150
|
+
async *watch(query, watchOptions) {
|
|
151
|
+
assertAllowedKind(query.kind);
|
|
152
|
+
yield* client.watch(query, watchOptions);
|
|
153
|
+
},
|
|
154
|
+
async delete() {
|
|
155
|
+
forbidden("delete");
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function createNamespacedOrchestrationClient(client, options) {
|
|
160
|
+
const namespace = options.namespace.trim();
|
|
161
|
+
if (!namespace || namespace.length > 253) {
|
|
162
|
+
throw new TypeError("namespace must contain between 1 and 253 characters");
|
|
163
|
+
}
|
|
164
|
+
const allowedKinds = new Set(options.allowedResourceKinds);
|
|
165
|
+
const mutableKinds = new Set(options.mutableResourceKinds ?? options.allowedResourceKinds);
|
|
166
|
+
for (const kind of mutableKinds) {
|
|
167
|
+
if (!allowedKinds.has(kind)) {
|
|
168
|
+
throw new TypeError(`mutable resource kind '${kind}' must also be allowed`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function assertAllowedKind(kind) {
|
|
172
|
+
if (allowedKinds.has(kind)) return;
|
|
173
|
+
throw new OrchestrationError({
|
|
174
|
+
code: "FORBIDDEN",
|
|
175
|
+
message: `remote orchestration access to resource kind '${kind}' is forbidden`,
|
|
176
|
+
retryable: false
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function bindNamespace(metadata) {
|
|
180
|
+
if (metadata.namespace !== void 0 && metadata.namespace !== namespace) {
|
|
181
|
+
throw new OrchestrationError({
|
|
182
|
+
code: "FORBIDDEN",
|
|
183
|
+
message: `remote orchestration access outside namespace '${namespace}' is forbidden`,
|
|
184
|
+
retryable: false
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return { ...metadata, namespace };
|
|
188
|
+
}
|
|
189
|
+
function assertMutableKind(kind) {
|
|
190
|
+
assertAllowedKind(kind);
|
|
191
|
+
if (mutableKinds.has(kind)) return;
|
|
192
|
+
throw new OrchestrationError({
|
|
193
|
+
code: "FORBIDDEN",
|
|
194
|
+
message: `remote orchestration mutation of resource kind '${kind}' is forbidden`,
|
|
195
|
+
retryable: false
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
async getCapabilities() {
|
|
200
|
+
const capabilities = await client.getCapabilities();
|
|
201
|
+
const resourceKinds = capabilities.resourceKinds.filter((kind) => allowedKinds.has(kind));
|
|
202
|
+
const resourceOperations = Object.fromEntries(
|
|
203
|
+
resourceKinds.map((kind) => {
|
|
204
|
+
const sourceOperations = capabilities.resourceOperations?.[kind] ?? capabilities.operations;
|
|
205
|
+
return [
|
|
206
|
+
kind,
|
|
207
|
+
sourceOperations.filter((operation) => mutableKinds.has(kind) || operation !== "apply" && operation !== "delete")
|
|
208
|
+
];
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
return {
|
|
212
|
+
operations: capabilities.operations,
|
|
213
|
+
resourceKinds,
|
|
214
|
+
resourceOperations,
|
|
215
|
+
interfaces: capabilities.interfaces.includes("resource") ? ["resource"] : []
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
async apply(resource, applyOptions) {
|
|
219
|
+
assertMutableKind(resource.kind);
|
|
220
|
+
return await client.apply(
|
|
221
|
+
{
|
|
222
|
+
...resource,
|
|
223
|
+
metadata: bindNamespace(resource.metadata)
|
|
224
|
+
},
|
|
225
|
+
applyOptions
|
|
226
|
+
);
|
|
227
|
+
},
|
|
228
|
+
async get(reference, getOptions) {
|
|
229
|
+
assertAllowedKind(reference.kind);
|
|
230
|
+
return await client.get(bindNamespace(reference), getOptions);
|
|
231
|
+
},
|
|
232
|
+
async list(query, listOptions) {
|
|
233
|
+
assertAllowedKind(query.kind);
|
|
234
|
+
return await client.list(bindNamespace(query), listOptions);
|
|
235
|
+
},
|
|
236
|
+
watch(query, watchOptions) {
|
|
237
|
+
assertAllowedKind(query.kind);
|
|
238
|
+
return client.watch(bindNamespace(query), watchOptions);
|
|
239
|
+
},
|
|
240
|
+
async delete(reference, deleteOptions) {
|
|
241
|
+
assertMutableKind(reference.kind);
|
|
242
|
+
return await client.delete(bindNamespace(reference), deleteOptions);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function requirePayload(payload, key) {
|
|
247
|
+
if (!(key in payload)) {
|
|
248
|
+
throw new OrchestrationError({
|
|
249
|
+
code: "INVALID",
|
|
250
|
+
message: `remote orchestration request is missing payload.${key}`,
|
|
251
|
+
retryable: false
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return payload[key];
|
|
255
|
+
}
|
|
256
|
+
function success(request, result) {
|
|
257
|
+
return {
|
|
258
|
+
protocol: REMOTE_ORCHESTRATION_PROTOCOL,
|
|
259
|
+
requestId: request.requestId,
|
|
260
|
+
ok: true,
|
|
261
|
+
result
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function failure(request, error) {
|
|
265
|
+
const requestRecord = isRecord(request) ? request : void 0;
|
|
266
|
+
return {
|
|
267
|
+
protocol: REMOTE_ORCHESTRATION_PROTOCOL,
|
|
268
|
+
requestId: typeof requestRecord?.requestId === "string" ? requestRecord.requestId : "invalid",
|
|
269
|
+
ok: false,
|
|
270
|
+
error: errorData(error)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function createRemoteOrchestrationHandler(client) {
|
|
274
|
+
function validate(request) {
|
|
275
|
+
if (!isRecord(request) || request.protocol !== REMOTE_ORCHESTRATION_PROTOCOL || typeof request.requestId !== "string" || !request.requestId || request.requestId.length > 256 || !REMOTE_OPERATIONS.has(request.operation) || !isRecord(request.payload)) {
|
|
276
|
+
throw new OrchestrationError({
|
|
277
|
+
code: "INVALID",
|
|
278
|
+
message: "invalid remote orchestration request envelope",
|
|
279
|
+
retryable: false
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
async request(request) {
|
|
285
|
+
try {
|
|
286
|
+
validate(request);
|
|
287
|
+
const payload = request.payload;
|
|
288
|
+
switch (request.operation) {
|
|
289
|
+
case "capabilities":
|
|
290
|
+
return success(request, await client.getCapabilities());
|
|
291
|
+
case "apply":
|
|
292
|
+
return success(
|
|
293
|
+
request,
|
|
294
|
+
await client.apply(
|
|
295
|
+
requirePayload(payload, "resource"),
|
|
296
|
+
payload.options
|
|
297
|
+
)
|
|
298
|
+
);
|
|
299
|
+
case "get":
|
|
300
|
+
return success(
|
|
301
|
+
request,
|
|
302
|
+
await client.get(
|
|
303
|
+
requirePayload(payload, "reference"),
|
|
304
|
+
payload.options
|
|
305
|
+
)
|
|
306
|
+
);
|
|
307
|
+
case "list":
|
|
308
|
+
return success(
|
|
309
|
+
request,
|
|
310
|
+
await client.list(
|
|
311
|
+
requirePayload(payload, "query"),
|
|
312
|
+
payload.options
|
|
313
|
+
)
|
|
314
|
+
);
|
|
315
|
+
case "delete":
|
|
316
|
+
return success(
|
|
317
|
+
request,
|
|
318
|
+
await client.delete(
|
|
319
|
+
requirePayload(payload, "reference"),
|
|
320
|
+
payload.options
|
|
321
|
+
)
|
|
322
|
+
);
|
|
323
|
+
case "watch":
|
|
324
|
+
throw new OrchestrationError({
|
|
325
|
+
code: "INVALID",
|
|
326
|
+
message: "watch requests require the streaming protocol method",
|
|
327
|
+
retryable: false
|
|
328
|
+
});
|
|
329
|
+
default:
|
|
330
|
+
throw new OrchestrationError({
|
|
331
|
+
code: "UNSUPPORTED",
|
|
332
|
+
message: `unsupported remote orchestration operation '${String(request.operation)}'`,
|
|
333
|
+
retryable: false
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
} catch (error) {
|
|
337
|
+
return failure(request, error);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
async *watch(request, options = {}) {
|
|
341
|
+
try {
|
|
342
|
+
validate(request);
|
|
343
|
+
if (request.operation !== "watch") {
|
|
344
|
+
throw new OrchestrationError({
|
|
345
|
+
code: "INVALID",
|
|
346
|
+
message: "streaming protocol accepts only watch operations",
|
|
347
|
+
retryable: false
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
const watchOptions = request.payload.options;
|
|
351
|
+
for await (const event of client.watch(
|
|
352
|
+
requirePayload(request.payload, "query"),
|
|
353
|
+
{
|
|
354
|
+
...watchOptions,
|
|
355
|
+
signal: options.signal
|
|
356
|
+
}
|
|
357
|
+
)) {
|
|
358
|
+
yield success(request, event);
|
|
359
|
+
}
|
|
360
|
+
} catch (error) {
|
|
361
|
+
yield failure(request, error);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function createFetchOrchestrationTransport(options) {
|
|
367
|
+
const fetch_ = options.fetch ?? globalThis.fetch;
|
|
368
|
+
const maxResponseBytes = options.maxResponseBytes ?? 1024 * 1024;
|
|
369
|
+
const maxWatchLineBytes = options.maxWatchLineBytes ?? 1024 * 1024;
|
|
370
|
+
function assertWatchLineSize(line) {
|
|
371
|
+
if (new TextEncoder().encode(line).byteLength > maxWatchLineBytes) {
|
|
372
|
+
throw new OrchestrationError({
|
|
373
|
+
code: "EXHAUSTED",
|
|
374
|
+
message: `remote orchestration watch line exceeds ${maxWatchLineBytes} bytes`,
|
|
375
|
+
retryable: false
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
async function headers(accept) {
|
|
380
|
+
const additional = typeof options.headers === "function" ? await options.headers() : options.headers ?? {};
|
|
381
|
+
return {
|
|
382
|
+
Accept: accept,
|
|
383
|
+
"Content-Type": "application/json",
|
|
384
|
+
...additional
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
async function post(request, accept, signal) {
|
|
388
|
+
const response = await fetch_(options.endpoint, {
|
|
389
|
+
method: "POST",
|
|
390
|
+
headers: await headers(accept),
|
|
391
|
+
body: JSON.stringify(request),
|
|
392
|
+
signal,
|
|
393
|
+
...options.credentials ? { credentials: options.credentials } : {}
|
|
394
|
+
});
|
|
395
|
+
if (!response.ok) {
|
|
396
|
+
throw new OrchestrationError({
|
|
397
|
+
code: response.status === 401 || response.status === 403 ? "FORBIDDEN" : "UNAVAILABLE",
|
|
398
|
+
message: `remote orchestration endpoint returned HTTP ${response.status}`,
|
|
399
|
+
retryable: response.status >= 500
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
return response;
|
|
403
|
+
}
|
|
404
|
+
async function readBoundedText(response, limit) {
|
|
405
|
+
if (!response.body) return "";
|
|
406
|
+
const reader = response.body.getReader();
|
|
407
|
+
const decoder = new TextDecoder();
|
|
408
|
+
let size = 0;
|
|
409
|
+
let text = "";
|
|
410
|
+
try {
|
|
411
|
+
for (; ; ) {
|
|
412
|
+
const { done, value } = await reader.read();
|
|
413
|
+
if (done) break;
|
|
414
|
+
size += value.byteLength;
|
|
415
|
+
if (size > limit) {
|
|
416
|
+
await reader.cancel();
|
|
417
|
+
throw new OrchestrationError({
|
|
418
|
+
code: "EXHAUSTED",
|
|
419
|
+
message: `remote orchestration response exceeds ${limit} bytes`,
|
|
420
|
+
retryable: false
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
text += decoder.decode(value, { stream: true });
|
|
424
|
+
}
|
|
425
|
+
return text + decoder.decode();
|
|
426
|
+
} finally {
|
|
427
|
+
reader.releaseLock();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
async request(request, transportOptions = {}) {
|
|
432
|
+
const response = await post(request, "application/json", transportOptions.signal);
|
|
433
|
+
const text = await readBoundedText(response, maxResponseBytes);
|
|
434
|
+
return JSON.parse(text);
|
|
435
|
+
},
|
|
436
|
+
async *watch(request, transportOptions = {}) {
|
|
437
|
+
const response = await post(request, "application/x-ndjson", transportOptions.signal);
|
|
438
|
+
if (!response.body) {
|
|
439
|
+
throw new OrchestrationError({
|
|
440
|
+
code: "UNAVAILABLE",
|
|
441
|
+
message: "remote orchestration watch response has no body",
|
|
442
|
+
retryable: true
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
const reader = response.body.getReader();
|
|
446
|
+
const decoder = new TextDecoder();
|
|
447
|
+
let pending = "";
|
|
448
|
+
let streamCompleted = false;
|
|
449
|
+
try {
|
|
450
|
+
for (; ; ) {
|
|
451
|
+
const { done, value } = await reader.read();
|
|
452
|
+
if (done) {
|
|
453
|
+
streamCompleted = true;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
pending += decoder.decode(value, { stream: true });
|
|
457
|
+
let newline = pending.indexOf("\n");
|
|
458
|
+
while (newline >= 0) {
|
|
459
|
+
const line = pending.slice(0, newline).trim();
|
|
460
|
+
pending = pending.slice(newline + 1);
|
|
461
|
+
assertWatchLineSize(line);
|
|
462
|
+
if (line) yield JSON.parse(line);
|
|
463
|
+
newline = pending.indexOf("\n");
|
|
464
|
+
}
|
|
465
|
+
if (pending.length > maxWatchLineBytes) {
|
|
466
|
+
throw new OrchestrationError({
|
|
467
|
+
code: "EXHAUSTED",
|
|
468
|
+
message: `remote orchestration watch line exceeds ${maxWatchLineBytes} bytes`,
|
|
469
|
+
retryable: false
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
pending += decoder.decode();
|
|
474
|
+
if (pending.trim()) {
|
|
475
|
+
assertWatchLineSize(pending.trim());
|
|
476
|
+
yield JSON.parse(pending);
|
|
477
|
+
}
|
|
478
|
+
} finally {
|
|
479
|
+
if (!streamCompleted) {
|
|
480
|
+
await reader.cancel().catch(() => void 0);
|
|
481
|
+
}
|
|
482
|
+
reader.releaseLock();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export {
|
|
489
|
+
REMOTE_ORCHESTRATION_PROTOCOL,
|
|
490
|
+
createRemoteOrchestrationClient,
|
|
491
|
+
createReadOnlyOrchestrationClient,
|
|
492
|
+
createNamespacedOrchestrationClient,
|
|
493
|
+
createRemoteOrchestrationHandler,
|
|
494
|
+
createFetchOrchestrationTransport
|
|
495
|
+
};
|
|
496
|
+
//# sourceMappingURL=chunk-CCEFAOSH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/orchestration/remoteClient.ts"],"sourcesContent":["import type {\n AgentOrchestrationCapabilities,\n AgentOrchestrationClient,\n OrchestrationApplyOptions,\n OrchestrationDeleteOptions,\n OrchestrationDeleteResult,\n OrchestrationGetOptions,\n OrchestrationListOptions,\n OrchestrationResource,\n OrchestrationResourceList,\n OrchestrationResourceManifest,\n OrchestrationResourceQuery,\n OrchestrationResourceReference,\n OrchestrationResourceStatus,\n OrchestrationWatchEvent,\n OrchestrationWatchOptions,\n} from './client.js';\nimport { OrchestrationError } from './errors.js';\nimport type { OrchestrationErrorData } from './errors.js';\n\nexport const REMOTE_ORCHESTRATION_PROTOCOL = 'memeloop.resource.v1' as const;\nexport type RemoteOrchestrationOperation =\n | 'capabilities'\n | 'apply'\n | 'get'\n | 'list'\n | 'watch'\n | 'delete';\n\nexport interface RemoteOrchestrationRequest {\n protocol: typeof REMOTE_ORCHESTRATION_PROTOCOL;\n requestId: string;\n operation: RemoteOrchestrationOperation;\n payload: Record<string, unknown>;\n}\n\nexport type RemoteOrchestrationResponse =\n | {\n protocol: typeof REMOTE_ORCHESTRATION_PROTOCOL;\n requestId: string;\n ok: true;\n result: unknown;\n }\n | {\n protocol: typeof REMOTE_ORCHESTRATION_PROTOCOL;\n requestId: string;\n ok: false;\n error: OrchestrationErrorData;\n };\n\nexport interface RemoteOrchestrationTransportOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Portable host boundary. Browser, Electron renderer, React Native, and Tauri\n * WebView clients implement this interface; trusted hosts bind identity and\n * policy behind the server-side AgentOrchestrationClient.\n */\nexport interface RemoteOrchestrationTransport {\n request(\n request: RemoteOrchestrationRequest,\n options?: RemoteOrchestrationTransportOptions,\n ): Promise<RemoteOrchestrationResponse>;\n watch(\n request: RemoteOrchestrationRequest,\n options?: RemoteOrchestrationTransportOptions,\n ): AsyncIterable<RemoteOrchestrationResponse>;\n}\n\nexport interface RemoteOrchestrationClientOptions {\n createRequestId?: () => string;\n}\n\nexport interface ReadOnlyOrchestrationClientOptions {\n /** Resource kinds visible to the remote client. Omit to retain every kind exposed by the source client. */\n allowedResourceKinds?: readonly string[];\n}\n\nexport interface NamespacedOrchestrationClientOptions {\n /** Host-bound namespace. Callers may omit it, but cannot select another namespace. */\n namespace: string;\n /** Resource kinds the caller may access. An empty list denies every resource kind. */\n allowedResourceKinds: readonly string[];\n /**\n * Resource kinds the caller may apply or delete. Defaults to every allowed\n * kind for compatibility; hosts should narrow this when status resources are\n * controller-owned.\n */\n mutableResourceKinds?: readonly string[];\n}\n\nconst REMOTE_OPERATIONS = new Set<RemoteOrchestrationOperation>([\n 'capabilities',\n 'apply',\n 'get',\n 'list',\n 'watch',\n 'delete',\n]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction errorData(error: unknown): OrchestrationErrorData {\n if (error instanceof OrchestrationError) {\n return {\n code: error.code,\n message: error.message,\n retryable: error.retryable,\n ...(error.retryAfterMs !== undefined ? { retryAfterMs: error.retryAfterMs } : {}),\n ...(error.reason !== undefined ? { reason: error.reason } : {}),\n ...(error.details !== undefined ? { details: error.details } : {}),\n };\n }\n return {\n code: 'INTERNAL',\n message: error instanceof Error ? error.message : String(error),\n retryable: false,\n };\n}\n\nfunction throwResponseError(response: Extract<RemoteOrchestrationResponse, { ok: false }>): never {\n throw new OrchestrationError(response.error);\n}\n\nfunction assertResponse(\n request: RemoteOrchestrationRequest,\n response: RemoteOrchestrationResponse,\n): void {\n if (\n !isRecord(response) ||\n response.protocol !== REMOTE_ORCHESTRATION_PROTOCOL ||\n response.requestId !== request.requestId ||\n typeof response.ok !== 'boolean' ||\n (response.ok && !('result' in response)) ||\n (!response.ok &&\n (!isRecord(response.error) ||\n typeof response.error.code !== 'string' ||\n typeof response.error.message !== 'string' ||\n typeof response.error.retryable !== 'boolean'))\n ) {\n throw new OrchestrationError({\n code: 'INVALID',\n message: 'remote orchestration response correlation or protocol mismatch',\n retryable: false,\n });\n }\n}\n\nlet requestSequence = 0;\n\n/** Build the policy-scoped Agent facade over a browser-safe remote transport. */\nexport function createRemoteOrchestrationClient(\n transport: RemoteOrchestrationTransport,\n options: RemoteOrchestrationClientOptions = {},\n): AgentOrchestrationClient {\n const createRequestId = options.createRequestId ??\n (() => `resource-${Date.now().toString(36)}-${(++requestSequence).toString(36)}`);\n\n function makeRequest(\n operation: RemoteOrchestrationOperation,\n payload: Record<string, unknown>,\n ): RemoteOrchestrationRequest {\n return {\n protocol: REMOTE_ORCHESTRATION_PROTOCOL,\n requestId: createRequestId(),\n operation,\n payload,\n };\n }\n\n async function request<T>(\n operation: RemoteOrchestrationOperation,\n payload: Record<string, unknown>,\n signal?: AbortSignal,\n ): Promise<T> {\n const envelope = makeRequest(operation, payload);\n const response = await transport.request(envelope, { signal });\n assertResponse(envelope, response);\n if (!response.ok) throwResponseError(response);\n return response.result as T;\n }\n\n return {\n getCapabilities() {\n return request<AgentOrchestrationCapabilities>('capabilities', {});\n },\n apply<TSpec = Record<string, unknown>, TStatus = OrchestrationResourceStatus>(\n resource: OrchestrationResourceManifest<TSpec>,\n applyOptions?: OrchestrationApplyOptions,\n ) {\n return request<OrchestrationResource<TSpec, TStatus>>('apply', {\n resource,\n ...(applyOptions ? { options: applyOptions } : {}),\n });\n },\n get<TSpec = Record<string, unknown>, TStatus = OrchestrationResourceStatus>(\n reference: OrchestrationResourceReference,\n getOptions?: OrchestrationGetOptions,\n ) {\n return request<OrchestrationResource<TSpec, TStatus> | null>('get', {\n reference,\n ...(getOptions ? { options: getOptions } : {}),\n });\n },\n list<TSpec = Record<string, unknown>, TStatus = OrchestrationResourceStatus>(\n query: OrchestrationResourceQuery,\n listOptions?: OrchestrationListOptions,\n ) {\n return request<OrchestrationResourceList<TSpec, TStatus>>('list', {\n query,\n ...(listOptions ? { options: listOptions } : {}),\n });\n },\n async *watch<TSpec = Record<string, unknown>, TStatus = OrchestrationResourceStatus>(\n query: OrchestrationResourceQuery,\n watchOptions?: OrchestrationWatchOptions,\n ): AsyncIterable<OrchestrationWatchEvent<TSpec, TStatus>> {\n const envelope = makeRequest('watch', {\n query,\n ...(watchOptions\n ? {\n options: {\n ...watchOptions,\n signal: undefined,\n },\n }\n : {}),\n });\n for await (\n const response of transport.watch(envelope, {\n signal: watchOptions?.signal,\n })\n ) {\n assertResponse(envelope, response);\n if (!response.ok) throwResponseError(response);\n yield response.result as OrchestrationWatchEvent<TSpec, TStatus>;\n }\n },\n delete(reference: OrchestrationResourceReference, deleteOptions?: OrchestrationDeleteOptions) {\n return request<OrchestrationDeleteResult>('delete', {\n reference,\n ...(deleteOptions ? { options: deleteOptions } : {}),\n });\n },\n };\n}\n\n/**\n * Bind a remote/mobile caller to a read-only view of an existing policy-scoped\n * client. This is an enforcement boundary, not only capability advertising:\n * mutations and out-of-scope kinds fail before reaching the source client.\n */\nexport function createReadOnlyOrchestrationClient(\n client: AgentOrchestrationClient,\n options: ReadOnlyOrchestrationClientOptions = {},\n): AgentOrchestrationClient {\n const allowedKinds = options.allowedResourceKinds\n ? new Set(options.allowedResourceKinds)\n : undefined;\n\n function assertAllowedKind(kind: string): void {\n if (!allowedKinds || allowedKinds.has(kind)) return;\n throw new OrchestrationError({\n code: 'FORBIDDEN',\n message: `remote orchestration access to resource kind '${kind}' is forbidden`,\n retryable: false,\n });\n }\n\n function forbidden(operation: 'apply' | 'delete'): never {\n throw new OrchestrationError({\n code: 'FORBIDDEN',\n message: `remote orchestration operation '${operation}' is read-only`,\n retryable: false,\n });\n }\n\n return {\n async getCapabilities() {\n const capabilities = await client.getCapabilities();\n return {\n operations: ['get', 'list', 'watch'],\n resourceKinds: capabilities.resourceKinds.filter((kind) => allowedKinds ? allowedKinds.has(kind) : true),\n interfaces: capabilities.interfaces.includes('resource') ? ['resource'] : [],\n };\n },\n async apply() {\n forbidden('apply');\n },\n async get(reference, getOptions) {\n assertAllowedKind(reference.kind);\n return await client.get(reference, getOptions);\n },\n async list(query, listOptions) {\n assertAllowedKind(query.kind);\n return await client.list(query, listOptions);\n },\n async *watch(query, watchOptions) {\n assertAllowedKind(query.kind);\n yield* client.watch(query, watchOptions);\n },\n async delete() {\n forbidden('delete');\n },\n };\n}\n\n/**\n * Bind a mutable remote caller to one host-selected namespace and an explicit\n * resource-kind allowlist. The wrapper is an authorization boundary: it\n * rejects cross-namespace references before they reach the source client and\n * fills an omitted namespace with the host-bound value.\n */\nexport function createNamespacedOrchestrationClient(\n client: AgentOrchestrationClient,\n options: NamespacedOrchestrationClientOptions,\n): AgentOrchestrationClient {\n const namespace = options.namespace.trim();\n if (!namespace || namespace.length > 253) {\n throw new TypeError('namespace must contain between 1 and 253 characters');\n }\n const allowedKinds = new Set(options.allowedResourceKinds);\n const mutableKinds = new Set(options.mutableResourceKinds ?? options.allowedResourceKinds);\n for (const kind of mutableKinds) {\n if (!allowedKinds.has(kind)) {\n throw new TypeError(`mutable resource kind '${kind}' must also be allowed`);\n }\n }\n\n function assertAllowedKind(kind: string): void {\n if (allowedKinds.has(kind)) return;\n throw new OrchestrationError({\n code: 'FORBIDDEN',\n message: `remote orchestration access to resource kind '${kind}' is forbidden`,\n retryable: false,\n });\n }\n\n function bindNamespace<T extends { namespace?: string }>(metadata: T): T & { namespace: string } {\n if (metadata.namespace !== undefined && metadata.namespace !== namespace) {\n throw new OrchestrationError({\n code: 'FORBIDDEN',\n message: `remote orchestration access outside namespace '${namespace}' is forbidden`,\n retryable: false,\n });\n }\n return { ...metadata, namespace };\n }\n\n function assertMutableKind(kind: string): void {\n assertAllowedKind(kind);\n if (mutableKinds.has(kind)) return;\n throw new OrchestrationError({\n code: 'FORBIDDEN',\n message: `remote orchestration mutation of resource kind '${kind}' is forbidden`,\n retryable: false,\n });\n }\n\n return {\n async getCapabilities() {\n const capabilities = await client.getCapabilities();\n const resourceKinds = capabilities.resourceKinds.filter((kind) => allowedKinds.has(kind));\n const resourceOperations = Object.fromEntries(\n resourceKinds.map((kind) => {\n const sourceOperations = capabilities.resourceOperations?.[kind] ??\n capabilities.operations;\n return [\n kind,\n sourceOperations.filter((operation) => mutableKinds.has(kind) || (operation !== 'apply' && operation !== 'delete')),\n ];\n }),\n );\n return {\n operations: capabilities.operations,\n resourceKinds,\n resourceOperations,\n interfaces: capabilities.interfaces.includes('resource') ? ['resource'] : [],\n };\n },\n async apply(resource, applyOptions) {\n assertMutableKind(resource.kind);\n return await client.apply(\n {\n ...resource,\n metadata: bindNamespace(resource.metadata),\n },\n applyOptions,\n );\n },\n async get(reference, getOptions) {\n assertAllowedKind(reference.kind);\n return await client.get(bindNamespace(reference), getOptions);\n },\n async list(query, listOptions) {\n assertAllowedKind(query.kind);\n return await client.list(bindNamespace(query), listOptions);\n },\n watch(query, watchOptions) {\n assertAllowedKind(query.kind);\n return client.watch(bindNamespace(query), watchOptions);\n },\n async delete(reference, deleteOptions) {\n assertMutableKind(reference.kind);\n return await client.delete(bindNamespace(reference), deleteOptions);\n },\n };\n}\n\nfunction requirePayload(payload: Record<string, unknown>, key: string): unknown {\n if (!(key in payload)) {\n throw new OrchestrationError({\n code: 'INVALID',\n message: `remote orchestration request is missing payload.${key}`,\n retryable: false,\n });\n }\n return payload[key];\n}\n\nfunction success(\n request: RemoteOrchestrationRequest,\n result: unknown,\n): RemoteOrchestrationResponse {\n return {\n protocol: REMOTE_ORCHESTRATION_PROTOCOL,\n requestId: request.requestId,\n ok: true,\n result,\n };\n}\n\nfunction failure(request: unknown, error: unknown): RemoteOrchestrationResponse {\n const requestRecord = isRecord(request) ? request : undefined;\n return {\n protocol: REMOTE_ORCHESTRATION_PROTOCOL,\n requestId: typeof requestRecord?.requestId === 'string' ? requestRecord.requestId : 'invalid',\n ok: false,\n error: errorData(error),\n };\n}\n\n/**\n * Trusted-side protocol adapter. The injected client has already bound actor,\n * admission, quotas, and resource scope; wire callers cannot select an actor.\n */\nexport function createRemoteOrchestrationHandler(client: AgentOrchestrationClient): {\n request(request: RemoteOrchestrationRequest): Promise<RemoteOrchestrationResponse>;\n watch(\n request: RemoteOrchestrationRequest,\n options?: RemoteOrchestrationTransportOptions,\n ): AsyncIterable<RemoteOrchestrationResponse>;\n} {\n function validate(request: RemoteOrchestrationRequest): void {\n if (\n !isRecord(request) ||\n request.protocol !== REMOTE_ORCHESTRATION_PROTOCOL ||\n typeof request.requestId !== 'string' ||\n !request.requestId ||\n request.requestId.length > 256 ||\n !REMOTE_OPERATIONS.has(request.operation) ||\n !isRecord(request.payload)\n ) {\n throw new OrchestrationError({\n code: 'INVALID',\n message: 'invalid remote orchestration request envelope',\n retryable: false,\n });\n }\n }\n\n return {\n async request(request) {\n try {\n validate(request);\n const payload = request.payload;\n switch (request.operation) {\n case 'capabilities':\n return success(request, await client.getCapabilities());\n case 'apply':\n return success(\n request,\n await client.apply(\n requirePayload(payload, 'resource') as OrchestrationResourceManifest,\n payload.options as OrchestrationApplyOptions | undefined,\n ),\n );\n case 'get':\n return success(\n request,\n await client.get(\n requirePayload(payload, 'reference') as OrchestrationResourceReference,\n payload.options as OrchestrationGetOptions | undefined,\n ),\n );\n case 'list':\n return success(\n request,\n await client.list(\n requirePayload(payload, 'query') as OrchestrationResourceQuery,\n payload.options as OrchestrationListOptions | undefined,\n ),\n );\n case 'delete':\n return success(\n request,\n await client.delete(\n requirePayload(payload, 'reference') as OrchestrationResourceReference,\n payload.options as OrchestrationDeleteOptions | undefined,\n ),\n );\n case 'watch':\n throw new OrchestrationError({\n code: 'INVALID',\n message: 'watch requests require the streaming protocol method',\n retryable: false,\n });\n default:\n throw new OrchestrationError({\n code: 'UNSUPPORTED',\n message: `unsupported remote orchestration operation '${String(request.operation)}'`,\n retryable: false,\n });\n }\n } catch (error) {\n return failure(request, error);\n }\n },\n async *watch(request, options = {}) {\n try {\n validate(request);\n if (request.operation !== 'watch') {\n throw new OrchestrationError({\n code: 'INVALID',\n message: 'streaming protocol accepts only watch operations',\n retryable: false,\n });\n }\n const watchOptions = request.payload.options as OrchestrationWatchOptions | undefined;\n for await (\n const event of client.watch(\n requirePayload(request.payload, 'query') as OrchestrationResourceQuery,\n {\n ...watchOptions,\n signal: options.signal,\n },\n )\n ) {\n yield success(request, event);\n }\n } catch (error) {\n yield failure(request, error);\n }\n },\n };\n}\n\nexport interface FetchOrchestrationTransportOptions {\n endpoint: string;\n fetch?: typeof globalThis.fetch;\n headers?: Record<string, string> | (() => Promise<Record<string, string>>);\n credentials?: RequestCredentials;\n maxResponseBytes?: number;\n maxWatchLineBytes?: number;\n}\n\n/** Browser/Tauri/React-Native fetch transport with bounded NDJSON watch. */\nexport function createFetchOrchestrationTransport(\n options: FetchOrchestrationTransportOptions,\n): RemoteOrchestrationTransport {\n const fetch_ = options.fetch ?? globalThis.fetch;\n const maxResponseBytes = options.maxResponseBytes ?? 1024 * 1024;\n const maxWatchLineBytes = options.maxWatchLineBytes ?? 1024 * 1024;\n\n function assertWatchLineSize(line: string): void {\n if (new TextEncoder().encode(line).byteLength > maxWatchLineBytes) {\n throw new OrchestrationError({\n code: 'EXHAUSTED',\n message: `remote orchestration watch line exceeds ${maxWatchLineBytes} bytes`,\n retryable: false,\n });\n }\n }\n\n async function headers(accept: string): Promise<Record<string, string>> {\n const additional = typeof options.headers === 'function' ? await options.headers() : (options.headers ?? {});\n return {\n Accept: accept,\n 'Content-Type': 'application/json',\n ...additional,\n };\n }\n\n async function post(\n request: RemoteOrchestrationRequest,\n accept: string,\n signal?: AbortSignal,\n ): Promise<Response> {\n const response = await fetch_(options.endpoint, {\n method: 'POST',\n headers: await headers(accept),\n body: JSON.stringify(request),\n signal,\n ...(options.credentials ? { credentials: options.credentials } : {}),\n });\n if (!response.ok) {\n throw new OrchestrationError({\n code: response.status === 401 || response.status === 403 ? 'FORBIDDEN' : 'UNAVAILABLE',\n message: `remote orchestration endpoint returned HTTP ${response.status}`,\n retryable: response.status >= 500,\n });\n }\n return response;\n }\n\n async function readBoundedText(response: Response, limit: number): Promise<string> {\n if (!response.body) return '';\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let size = 0;\n let text = '';\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n size += value.byteLength;\n if (size > limit) {\n await reader.cancel();\n throw new OrchestrationError({\n code: 'EXHAUSTED',\n message: `remote orchestration response exceeds ${limit} bytes`,\n retryable: false,\n });\n }\n text += decoder.decode(value, { stream: true });\n }\n return text + decoder.decode();\n } finally {\n reader.releaseLock();\n }\n }\n\n return {\n async request(request, transportOptions = {}) {\n const response = await post(request, 'application/json', transportOptions.signal);\n const text = await readBoundedText(response, maxResponseBytes);\n return JSON.parse(text) as RemoteOrchestrationResponse;\n },\n async *watch(request, transportOptions = {}) {\n const response = await post(request, 'application/x-ndjson', transportOptions.signal);\n if (!response.body) {\n throw new OrchestrationError({\n code: 'UNAVAILABLE',\n message: 'remote orchestration watch response has no body',\n retryable: true,\n });\n }\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let pending = '';\n let streamCompleted = false;\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) {\n streamCompleted = true;\n break;\n }\n pending += decoder.decode(value, { stream: true });\n let newline = pending.indexOf('\\n');\n while (newline >= 0) {\n const line = pending.slice(0, newline).trim();\n pending = pending.slice(newline + 1);\n assertWatchLineSize(line);\n if (line) yield JSON.parse(line) as RemoteOrchestrationResponse;\n newline = pending.indexOf('\\n');\n }\n // UTF-8 is never smaller than the JS code-unit count. This cheap\n // guard avoids repeatedly re-encoding an attacker-controlled partial\n // line; the exact byte check runs once when the line is complete.\n if (pending.length > maxWatchLineBytes) {\n throw new OrchestrationError({\n code: 'EXHAUSTED',\n message: `remote orchestration watch line exceeds ${maxWatchLineBytes} bytes`,\n retryable: false,\n });\n }\n }\n pending += decoder.decode();\n if (pending.trim()) {\n assertWatchLineSize(pending.trim());\n yield JSON.parse(pending) as RemoteOrchestrationResponse;\n }\n } finally {\n if (!streamCompleted) {\n await reader.cancel().catch(() => undefined);\n }\n reader.releaseLock();\n }\n },\n };\n}\n"],"mappings":";;;;;AAoBO,IAAM,gCAAgC;AAwE7C,IAAM,oBAAoB,oBAAI,IAAkC;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,SAAS,OAAkD;AAClE,SAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,UAAU,OAAwC;AACzD,MAAI,iBAAiB,oBAAoB;AACvC,WAAO;AAAA,MACL,MAAM,MAAM;AAAA,MACZ,SAAS,MAAM;AAAA,MACf,WAAW,MAAM;AAAA,MACjB,GAAI,MAAM,iBAAiB,SAAY,EAAE,cAAc,MAAM,aAAa,IAAI,CAAC;AAAA,MAC/E,GAAI,MAAM,WAAW,SAAY,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;AAAA,MAC7D,GAAI,MAAM,YAAY,SAAY,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,IAClE;AAAA,EACF;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IAC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AAmB;AACtC,kBAAM,IAAI,mBAAmB;AAAA,cAC3B,MAAM;AAAA,cACN,SAAS,2CAA2C,iBAAiB;AAAA,cACrE,WAAW;AAAA,YACb,CAAC;AAAA,UACH;AAAA,QACF;AACA,mBAAW,QAAQ,OAAO;AAC1B,YAAI,QAAQ,KAAK,GAAG;AAClB,8BAAoB,QAAQ,KAAK,CAAC;AAClC,gBAAM,KAAK,MAAM,OAAO;AAAA,QAC1B;AAAA,MACF,UAAE;AACA,YAAI,CAAC,iBAAiB;AACpB,gBAAM,OAAO,OAAO,EAAE,MAAM,MAAM,MAAS;AAAA,QAC7C;AACA,eAAO,YAAY;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/orchestration/errors.ts
|
|
2
|
+
var ORCHESTRATION_ERROR_CODES = [
|
|
3
|
+
"UNSUPPORTED",
|
|
4
|
+
"FORBIDDEN",
|
|
5
|
+
"CONFLICT",
|
|
6
|
+
"STALE_EPOCH",
|
|
7
|
+
"NOT_FOUND",
|
|
8
|
+
"INVALID",
|
|
9
|
+
"EXHAUSTED",
|
|
10
|
+
"UNAVAILABLE",
|
|
11
|
+
"TIMEOUT",
|
|
12
|
+
"CANCELLED",
|
|
13
|
+
"UNKNOWN_EFFECT",
|
|
14
|
+
"WATCH_COMPACTED",
|
|
15
|
+
"INTERNAL"
|
|
16
|
+
];
|
|
17
|
+
var OrchestrationError = class extends Error {
|
|
18
|
+
code;
|
|
19
|
+
retryable;
|
|
20
|
+
retryAfterMs;
|
|
21
|
+
reason;
|
|
22
|
+
details;
|
|
23
|
+
constructor(data) {
|
|
24
|
+
super(data.message);
|
|
25
|
+
this.name = "OrchestrationError";
|
|
26
|
+
this.code = data.code;
|
|
27
|
+
this.retryable = data.retryable;
|
|
28
|
+
this.retryAfterMs = data.retryAfterMs;
|
|
29
|
+
this.reason = data.reason;
|
|
30
|
+
this.details = data.details;
|
|
31
|
+
}
|
|
32
|
+
toJSON() {
|
|
33
|
+
return {
|
|
34
|
+
code: this.code,
|
|
35
|
+
message: this.message,
|
|
36
|
+
retryable: this.retryable,
|
|
37
|
+
retryAfterMs: this.retryAfterMs,
|
|
38
|
+
reason: this.reason,
|
|
39
|
+
details: this.details
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
function isOrchestrationError(error) {
|
|
44
|
+
return error instanceof OrchestrationError;
|
|
45
|
+
}
|
|
46
|
+
function toOrchestrationErrorData(error, fallback = {
|
|
47
|
+
code: "INTERNAL",
|
|
48
|
+
retryable: false
|
|
49
|
+
}) {
|
|
50
|
+
if (isOrchestrationError(error)) return error.toJSON();
|
|
51
|
+
return {
|
|
52
|
+
...fallback,
|
|
53
|
+
message: error instanceof Error ? error.message : String(error)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
ORCHESTRATION_ERROR_CODES,
|
|
59
|
+
OrchestrationError,
|
|
60
|
+
isOrchestrationError,
|
|
61
|
+
toOrchestrationErrorData
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=chunk-FWSY5HOA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/orchestration/errors.ts"],"sourcesContent":["export const ORCHESTRATION_ERROR_CODES = [\n 'UNSUPPORTED',\n 'FORBIDDEN',\n 'CONFLICT',\n 'STALE_EPOCH',\n 'NOT_FOUND',\n 'INVALID',\n 'EXHAUSTED',\n 'UNAVAILABLE',\n 'TIMEOUT',\n 'CANCELLED',\n 'UNKNOWN_EFFECT',\n 'WATCH_COMPACTED',\n 'INTERNAL',\n] as const;\n\nexport type OrchestrationErrorCode = typeof ORCHESTRATION_ERROR_CODES[number];\n\nexport interface OrchestrationErrorData {\n code: OrchestrationErrorCode;\n message: string;\n retryable: boolean;\n retryAfterMs?: number;\n reason?: string;\n details?: Record<string, unknown>;\n}\n\nexport class OrchestrationError extends Error {\n readonly code: OrchestrationErrorCode;\n readonly retryable: boolean;\n readonly retryAfterMs?: number;\n readonly reason?: string;\n readonly details?: Record<string, unknown>;\n\n constructor(data: OrchestrationErrorData) {\n super(data.message);\n this.name = 'OrchestrationError';\n this.code = data.code;\n this.retryable = data.retryable;\n this.retryAfterMs = data.retryAfterMs;\n this.reason = data.reason;\n this.details = data.details;\n }\n\n toJSON(): OrchestrationErrorData {\n return {\n code: this.code,\n message: this.message,\n retryable: this.retryable,\n retryAfterMs: this.retryAfterMs,\n reason: this.reason,\n details: this.details,\n };\n }\n}\n\nexport function isOrchestrationError(error: unknown): error is OrchestrationError {\n return error instanceof OrchestrationError;\n}\n\nexport function toOrchestrationErrorData(\n error: unknown,\n fallback: Pick<OrchestrationErrorData, 'code' | 'retryable'> = {\n code: 'INTERNAL',\n retryable: false,\n },\n): OrchestrationErrorData {\n if (isOrchestrationError(error)) return error.toJSON();\n return {\n ...fallback,\n message: error instanceof Error ? error.message : String(error),\n };\n}\n"],"mappings":";AAAO,IAAM,4BAA4B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAaO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAA8B;AACxC,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,YAAY,KAAK;AACtB,SAAK,eAAe,KAAK;AACzB,SAAK,SAAS,KAAK;AACnB,SAAK,UAAU,KAAK;AAAA,EACtB;AAAA,EAEA,SAAiC;AAC/B,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,WAAW,KAAK;AAAA,MAChB,cAAc,KAAK;AAAA,MACnB,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,IAChB;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,OAA6C;AAChF,SAAO,iBAAiB;AAC1B;AAEO,SAAS,yBACd,OACA,WAA+D;AAAA,EAC7D,MAAM;AAAA,EACN,WAAW;AACb,GACwB;AACxB,MAAI,qBAAqB,KAAK,EAAG,QAAO,MAAM,OAAO;AACrD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,EAChE;AACF;","names":[]}
|