@terminals-tech/sdk 1.0.0-rc.1 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/WebContainerManager-SHXC5VKI.js +22 -0
- package/dist/browser-http-client-ZQLDWZMU.js +317 -0
- package/dist/cache-VKYSQRXX.js +45 -0
- package/dist/capabilities-MIPUMBLL.js +96 -0
- package/dist/chunk-2ESYSVXG.js +48 -0
- package/dist/chunk-2WTYE4SW.js +190 -0
- package/dist/chunk-3CEM77QZ.js +474 -0
- package/dist/chunk-3LFMIVJM.js +40 -0
- package/dist/chunk-ABCK4FWN.js +136 -0
- package/dist/chunk-AFDUOYHD.js +2060 -0
- package/dist/chunk-BCOQMFKT.js +265 -0
- package/dist/chunk-BKB3MD5Y.js +723 -0
- package/dist/chunk-BYXBJQAS.js +0 -0
- package/dist/chunk-DKFJIILR.js +9798 -0
- package/dist/chunk-EXI3LJVJ.js +51 -0
- package/dist/chunk-FOXUEYWK.js +42 -0
- package/dist/chunk-GJWAJAX3.js +173 -0
- package/dist/chunk-H3POJCFA.js +333 -0
- package/dist/chunk-KHR7ZYCX.js +4034 -0
- package/dist/chunk-NTMBOESX.js +152 -0
- package/dist/chunk-OSSRZOGC.js +190 -0
- package/dist/chunk-PUZ2S62E.js +977 -0
- package/dist/chunk-PWAHFID5.js +381 -0
- package/dist/chunk-Q2VI6ICE.js +188 -0
- package/dist/chunk-Q4B7YS7T.js +557 -0
- package/dist/chunk-QJFKEQHF.js +6460 -0
- package/dist/chunk-QWXPVB2L.js +320 -0
- package/dist/chunk-QWZRZKLZ.js +896 -0
- package/dist/chunk-SHPGIVDH.js +5521 -0
- package/dist/chunk-TSQ3BGLA.js +11945 -0
- package/dist/chunk-UJDUQNE2.js +79 -0
- package/dist/chunk-UKVUPKZP.js +296 -0
- package/dist/chunk-VZA2NUH3.js +118 -0
- package/dist/chunk-WGBCRNMB.js +1817 -0
- package/dist/chunk-WU4OTGJE.js +752 -0
- package/dist/chunk-XPJ63Y6T.js +70 -0
- package/dist/chunk-Y2EULKA2.js +172 -0
- package/dist/chunk-YJEZWCYV.js +94 -0
- package/dist/chunk-ZVO47SQV.js +150 -0
- package/dist/container-lite-KQX3NMPY.js +327 -0
- package/dist/core-H2UUDATO.js +146 -0
- package/dist/crypto-D4LMI2RN.js +45 -0
- package/dist/db-BWC2GGBN.js +50 -0
- package/dist/demo-VXMGMJNK.js +87 -0
- package/dist/diagnostics-6RQTBR6I.js +113 -0
- package/dist/dist-OPDCWARF.js +727 -0
- package/dist/dist-VXJEKX3T.js +2441 -0
- package/dist/dist-VYGJXGUS.js +1008 -0
- package/dist/embeddings-7QXTXUMC.js +15 -0
- package/dist/embeddings-MAEWWUHW.js +9 -0
- package/dist/graph-RKMNE2X5.js +36 -0
- package/dist/hvm-DRQK2MUT.js +126 -0
- package/dist/index.cjs +11706 -4004
- package/dist/index.d.cts +1299 -1339
- package/dist/index.d.ts +1299 -1339
- package/dist/index.js +189 -7938
- package/dist/mcp-NK34ZNM5.js +101 -0
- package/dist/mcp-client-service-browser-SGB2K3VZ.js +14 -0
- package/dist/neuro-state-XHRGIRVO.js +498 -0
- package/dist/nodes-DXKYDTVO.js +224 -0
- package/dist/package-EXUIU2RL.js +93 -0
- package/dist/package-VGL7HYTO.js +106 -0
- package/dist/package-XHMLOAQ4.js +98 -0
- package/dist/pg-events-QJAM2HIP.js +15 -0
- package/dist/pgliteService-IUGNNOVU.js +258 -0
- package/dist/policy-IRJCM6FS.js +13 -0
- package/dist/registry-BL3TDQDB.js +26 -0
- package/dist/registry-FW63E7FE.js +16 -0
- package/dist/registry-ZQ2IBLF6.js +9 -0
- package/dist/scheduler-H6Q53IMI.js +122 -0
- package/dist/secret-store-H7273UIT.js +18 -0
- package/dist/server-7DM74VFW.js +18 -0
- package/dist/skills-KLTTT2RM.js +6375 -0
- package/dist/stack-CHDAFU2S.js +103 -0
- package/dist/storage-L7MWNSPG.js +13 -0
- package/dist/supabaseService-6AYP2VY3.js +476 -0
- package/dist/topology-CIWWNVAN.js +13 -0
- package/dist/webcontainer-3LDJVIIL.js +281 -0
- package/package.json +2 -2
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BASE_PHASE_LOCKING_VALUE_NODE_ID,
|
|
3
|
+
BASE_RESONANCE_IQ_ENCODE_NODE_ID,
|
|
4
|
+
BASE_RESONANCE_IQ_PHASE_SHIFT_NODE_ID,
|
|
5
|
+
BASE_RESONANCE_METRICS_NODE_ID,
|
|
6
|
+
COMPUTE_BEND_NODE_ID,
|
|
7
|
+
HVM_PROOF_EDGE_CHECK_NODE_ID,
|
|
8
|
+
SYSTEM_SCHEDULE_NODE_ID,
|
|
9
|
+
SYSTEM_SIGNAL_EMIT_NODE_ID,
|
|
10
|
+
executeBendCompute,
|
|
11
|
+
executeHvmProofEdgeCheck,
|
|
12
|
+
executeIqEncode,
|
|
13
|
+
executeIqPhaseShift,
|
|
14
|
+
executePhaseLockingValueNode,
|
|
15
|
+
executeResonanceMetrics,
|
|
16
|
+
executeSystemSchedule,
|
|
17
|
+
executeSystemSignalEmit
|
|
18
|
+
} from "./chunk-BKB3MD5Y.js";
|
|
19
|
+
import {
|
|
20
|
+
getProvider
|
|
21
|
+
} from "./chunk-H3POJCFA.js";
|
|
22
|
+
import {
|
|
23
|
+
registerNode
|
|
24
|
+
} from "./chunk-3CEM77QZ.js";
|
|
25
|
+
|
|
26
|
+
// ../../lib/types/safe-types.ts
|
|
27
|
+
function isObject(value) {
|
|
28
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29
|
+
}
|
|
30
|
+
function isArray(value) {
|
|
31
|
+
return Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
function isString(value) {
|
|
34
|
+
return typeof value === "string";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ../../lib/terminals-tech/machines/core/nodes/provider.chat.ts
|
|
38
|
+
var PROVIDER_CHAT_NODE_ID = "provider.chat.v1";
|
|
39
|
+
var manifest = {
|
|
40
|
+
id: PROVIDER_CHAT_NODE_ID,
|
|
41
|
+
version: "0.1.0",
|
|
42
|
+
kind: "task",
|
|
43
|
+
label: "Provider Chat",
|
|
44
|
+
description: "Calls a chat model on a selected provider",
|
|
45
|
+
runtimes: ["worker"],
|
|
46
|
+
entrypoints: { worker: { module: "local" } },
|
|
47
|
+
inputsSchema: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
provider: {
|
|
51
|
+
type: "string",
|
|
52
|
+
description: "provider id (openai, nous, prime, ...)"
|
|
53
|
+
},
|
|
54
|
+
model: { type: "string" },
|
|
55
|
+
messages: {
|
|
56
|
+
type: "array",
|
|
57
|
+
items: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: { role: { type: "string" }, content: { type: "string" } },
|
|
60
|
+
required: ["role", "content"]
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
temperature: { type: "number" },
|
|
64
|
+
secretRef: {
|
|
65
|
+
type: "string",
|
|
66
|
+
description: "reference key in Secrets store"
|
|
67
|
+
},
|
|
68
|
+
baseUrl: { type: "string", description: "override baseUrl for vendor" }
|
|
69
|
+
},
|
|
70
|
+
required: ["provider", "model", "messages"]
|
|
71
|
+
},
|
|
72
|
+
outputsSchema: {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: { message: { type: "string" }, usage: { type: "object" } }
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
registerNode(manifest);
|
|
78
|
+
async function executeProviderChat(inputs, context) {
|
|
79
|
+
const adapter = getProvider(inputs.provider);
|
|
80
|
+
if (!adapter?.chat?.generate) throw new Error(`provider not found: ${inputs.provider}`);
|
|
81
|
+
const secrets = inputs.secretRef && context.getSecret ? await context.getSecret(inputs.secretRef) : {};
|
|
82
|
+
const out = await adapter.chat.generate(
|
|
83
|
+
{
|
|
84
|
+
model: inputs.model,
|
|
85
|
+
messages: inputs.messages,
|
|
86
|
+
temperature: inputs.temperature
|
|
87
|
+
},
|
|
88
|
+
secrets
|
|
89
|
+
);
|
|
90
|
+
return { message: out.message, usage: out.usage };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ../../lib/terminals-tech/machines/core/runners/registry.ts
|
|
94
|
+
var RunnerRegistry = class {
|
|
95
|
+
workerRunners = /* @__PURE__ */ new Map();
|
|
96
|
+
// key: manifest id
|
|
97
|
+
tierRunners = /* @__PURE__ */ new Map();
|
|
98
|
+
// key: tier name
|
|
99
|
+
/**
|
|
100
|
+
* Register a worker runner for a specific node manifest ID.
|
|
101
|
+
*
|
|
102
|
+
* @param manifestId - Node manifest ID (e.g., 'http-fetch')
|
|
103
|
+
* @param fn - Worker runner function
|
|
104
|
+
*/
|
|
105
|
+
registerWorker(manifestId, fn) {
|
|
106
|
+
this.workerRunners.set(manifestId, fn);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Retrieve a registered worker runner by manifest ID.
|
|
110
|
+
*
|
|
111
|
+
* @param manifestId - Node manifest ID
|
|
112
|
+
* @returns Worker runner function or null if not found
|
|
113
|
+
*/
|
|
114
|
+
getWorker(manifestId) {
|
|
115
|
+
return this.workerRunners.get(manifestId) || null;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Register a generic runner for a runtime tier.
|
|
119
|
+
*
|
|
120
|
+
* @param tier - Runtime tier name (e.g., 'stack', 'webcontainer')
|
|
121
|
+
* @param fn - Runner function for that tier
|
|
122
|
+
*/
|
|
123
|
+
registerRunner(tier, fn) {
|
|
124
|
+
this.tierRunners.set(tier, fn);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve a registered runner for a runtime tier.
|
|
128
|
+
*
|
|
129
|
+
* @param tier - Runtime tier name
|
|
130
|
+
* @returns Runner function or null if not found
|
|
131
|
+
*/
|
|
132
|
+
getRunner(tier) {
|
|
133
|
+
return this.tierRunners.get(tier) || null;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var runners = new RunnerRegistry();
|
|
137
|
+
import("./demo-VXMGMJNK.js").catch((err) => console.warn("[RunnerRegistry] demo runner import failed", err));
|
|
138
|
+
import("./stack-CHDAFU2S.js").catch((err) => console.warn("[RunnerRegistry] stack runner import failed", err));
|
|
139
|
+
runners.registerWorker(PROVIDER_CHAT_NODE_ID, async (_m, input, ctx) => {
|
|
140
|
+
const typedInput = input;
|
|
141
|
+
const secrets = typedInput.__secrets || {};
|
|
142
|
+
try {
|
|
143
|
+
const { decrypt } = await import("./crypto-D4LMI2RN.js");
|
|
144
|
+
const { resolveSecretValue } = await import("./secret-store-H7273UIT.js");
|
|
145
|
+
const outSecrets = {};
|
|
146
|
+
for (const [k, v] of Object.entries(secrets)) {
|
|
147
|
+
try {
|
|
148
|
+
const parsed = JSON.parse(String(v));
|
|
149
|
+
if (isObject(parsed) && "iv" in parsed && "ct" in parsed) {
|
|
150
|
+
outSecrets[k] = decrypt(parsed);
|
|
151
|
+
} else {
|
|
152
|
+
outSecrets[k] = String(v);
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
outSecrets[k] = String(v);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const { __secrets: _secrets, ...clean } = typedInput;
|
|
159
|
+
const out = await executeProviderChat(
|
|
160
|
+
clean,
|
|
161
|
+
{
|
|
162
|
+
getSecret: async (ref) => {
|
|
163
|
+
if (ref) {
|
|
164
|
+
const value = await resolveSecretValue(ref, {
|
|
165
|
+
ownerId: ctx.userId || "anonymous",
|
|
166
|
+
stackId: ctx.stackId,
|
|
167
|
+
nodeId: ctx.nodeId,
|
|
168
|
+
appletId: ctx.appletId,
|
|
169
|
+
worldId: ctx.worldId,
|
|
170
|
+
terminalId: ctx.terminalId
|
|
171
|
+
});
|
|
172
|
+
if (value) {
|
|
173
|
+
const resolved = typeof value === "string" ? value : "";
|
|
174
|
+
return { ...outSecrets, [ref]: resolved, apiKey: resolved };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return outSecrets;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
return out;
|
|
182
|
+
} catch {
|
|
183
|
+
const { __secrets: _secrets, ...clean } = typedInput;
|
|
184
|
+
const out = await executeProviderChat(
|
|
185
|
+
clean,
|
|
186
|
+
{
|
|
187
|
+
getSecret: async (ref) => {
|
|
188
|
+
const secretsRecord = {};
|
|
189
|
+
if (isObject(secrets)) {
|
|
190
|
+
for (const [key, val] of Object.entries(secrets)) {
|
|
191
|
+
secretsRecord[key] = isString(val) ? val : String(val ?? "");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (ref) {
|
|
195
|
+
const secretValue = isObject(secrets) ? secrets[ref] : void 0;
|
|
196
|
+
return {
|
|
197
|
+
...secretsRecord,
|
|
198
|
+
[ref]: isString(secretValue) ? secretValue : String(secretValue ?? "")
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return secretsRecord;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
runners.registerWorker("base.time.timeline.v1", async (_m, input) => {
|
|
209
|
+
const mod = await import("./core-H2UUDATO.js");
|
|
210
|
+
const windowVal = isObject(input) && "window" in input && isString(input.window) ? input.window : void 0;
|
|
211
|
+
const tl = mod.makeTimeline(windowVal);
|
|
212
|
+
const eventsVal = isObject(input) && "events" in input ? input.events : void 0;
|
|
213
|
+
const events = isArray(eventsVal) ? eventsVal : [];
|
|
214
|
+
return tl.process(events);
|
|
215
|
+
});
|
|
216
|
+
runners.registerWorker(SYSTEM_SCHEDULE_NODE_ID, async (_m, input, ctx) => {
|
|
217
|
+
return await executeSystemSchedule(input, { stackId: ctx.stackId });
|
|
218
|
+
});
|
|
219
|
+
runners.registerWorker(HVM_PROOF_EDGE_CHECK_NODE_ID, async (_m, input, ctx) => {
|
|
220
|
+
return await executeHvmProofEdgeCheck(input, {
|
|
221
|
+
stackId: ctx.stackId,
|
|
222
|
+
nodeId: ctx.nodeId
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
runners.registerWorker(COMPUTE_BEND_NODE_ID, async (_m, input, ctx) => {
|
|
226
|
+
return await executeBendCompute(input, {
|
|
227
|
+
stackId: ctx.stackId,
|
|
228
|
+
nodeId: ctx.nodeId
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
runners.registerWorker(SYSTEM_SIGNAL_EMIT_NODE_ID, async (_m, input, ctx) => {
|
|
232
|
+
return await executeSystemSignalEmit(input, {
|
|
233
|
+
stackId: ctx.stackId,
|
|
234
|
+
nodeId: ctx.nodeId
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
runners.registerWorker(BASE_RESONANCE_IQ_ENCODE_NODE_ID, async (_m, input) => {
|
|
238
|
+
return await executeIqEncode(input);
|
|
239
|
+
});
|
|
240
|
+
runners.registerWorker(BASE_RESONANCE_IQ_PHASE_SHIFT_NODE_ID, async (_m, input) => {
|
|
241
|
+
return await executeIqPhaseShift(input);
|
|
242
|
+
});
|
|
243
|
+
runners.registerWorker(BASE_RESONANCE_METRICS_NODE_ID, async (_m, input) => {
|
|
244
|
+
return await executeResonanceMetrics(input);
|
|
245
|
+
});
|
|
246
|
+
runners.registerWorker(BASE_PHASE_LOCKING_VALUE_NODE_ID, async (_m, input) => {
|
|
247
|
+
return await executePhaseLockingValueNode(input);
|
|
248
|
+
});
|
|
249
|
+
runners.registerWorker("base.time.memory.v1", async (_m, input) => {
|
|
250
|
+
const mod = await import("./core-H2UUDATO.js");
|
|
251
|
+
return mod.temporalKV().handle(input);
|
|
252
|
+
});
|
|
253
|
+
runners.registerWorker("base.field.store3d.v1", async (_m, input) => {
|
|
254
|
+
const mod = await import("./core-H2UUDATO.js");
|
|
255
|
+
return mod.fieldStore3d().handle(input);
|
|
256
|
+
});
|
|
257
|
+
runners.registerWorker("base.field.projector.v1", async (_m, input) => {
|
|
258
|
+
const emb = await import("./embeddings-MAEWWUHW.js");
|
|
259
|
+
const pointsVal = isObject(input) && "points" in input ? input.points : void 0;
|
|
260
|
+
const points = isArray(pointsVal) ? pointsVal.filter(
|
|
261
|
+
(point) => isObject(point) && typeof point.x === "number" && typeof point.y === "number" && typeof point.z === "number"
|
|
262
|
+
) : [];
|
|
263
|
+
const modelVal = isObject(input) && "model" in input ? input.model : void 0;
|
|
264
|
+
const model = isString(modelVal) ? modelVal : "default";
|
|
265
|
+
const embeddings = await emb.encodePoints(points, { model });
|
|
266
|
+
return { embeddings };
|
|
267
|
+
});
|
|
268
|
+
runners.registerWorker("base.semantic.zero-agent.v1", async (_m, input) => {
|
|
269
|
+
const mod = await import("./core-H2UUDATO.js");
|
|
270
|
+
return mod.zeroAgent().handle(input);
|
|
271
|
+
});
|
|
272
|
+
runners.registerWorker("base.semantic.entity-graph.v1", async (_m, input) => {
|
|
273
|
+
const g = await import("./graph-RKMNE2X5.js");
|
|
274
|
+
return g.entityGraph().handle(input);
|
|
275
|
+
});
|
|
276
|
+
runners.registerWorker("base.interface.oracle-adapter.v1", async (_m, input, ctx) => {
|
|
277
|
+
const mod = await import("./core-H2UUDATO.js");
|
|
278
|
+
return mod.httpOracle(ctx?.policies).handle(input);
|
|
279
|
+
});
|
|
280
|
+
runners.registerWorker("astro.transform.buildAgentPrompt.v1", async (_m, input) => {
|
|
281
|
+
const questionVal = isObject(input) && "question" in input ? input.question : void 0;
|
|
282
|
+
const q = String(questionVal || "");
|
|
283
|
+
const product = isObject(input) && "product" in input ? input.product : null;
|
|
284
|
+
const record = isObject(input) && "record" in input ? input.record : null;
|
|
285
|
+
const lines = [];
|
|
286
|
+
if (product) lines.push(`Context (product): ${JSON.stringify(product).slice(0, 2e3)}`);
|
|
287
|
+
if (record) lines.push(`Context (record): ${JSON.stringify(record).slice(0, 2e3)}`);
|
|
288
|
+
const prompt = `${lines.join("\n")}
|
|
289
|
+
|
|
290
|
+
Question: ${q}
|
|
291
|
+
Answer with observed facts first, then suggested follow-ups and uncertainties.`;
|
|
292
|
+
return { prompt };
|
|
293
|
+
});
|
|
294
|
+
runners.registerWorker("transform.object.pickPath.v1", async (_m, input) => {
|
|
295
|
+
const objVal = isObject(input) && "object" in input ? input.object : void 0;
|
|
296
|
+
const obj = isObject(objVal) ? objVal : {};
|
|
297
|
+
const pathVal = isObject(input) && "path" in input ? input.path : void 0;
|
|
298
|
+
const path = String(pathVal || "");
|
|
299
|
+
const segs = path.split(".").filter(Boolean);
|
|
300
|
+
let cur = obj;
|
|
301
|
+
for (const s of segs) {
|
|
302
|
+
if (isObject(cur) && s in cur) {
|
|
303
|
+
cur = cur[s];
|
|
304
|
+
} else {
|
|
305
|
+
cur = void 0;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return { value: cur };
|
|
310
|
+
});
|
|
311
|
+
if (!runners.getWorker("provider.http.invoke.v1")) {
|
|
312
|
+
runners.registerWorker("provider.http.invoke.v1", async (_m, input, ctx) => {
|
|
313
|
+
const { isNetworkAllowed, requireNetworkApproval } = await import("./policy-IRJCM6FS.js");
|
|
314
|
+
const urlVal = isObject(input) && "url" in input ? input.url : void 0;
|
|
315
|
+
const url = String(urlVal || "");
|
|
316
|
+
const methodVal = isObject(input) && "method" in input ? input.method : void 0;
|
|
317
|
+
const method = String(methodVal || "GET").toUpperCase();
|
|
318
|
+
const headersVal = isObject(input) && "headers" in input ? input.headers : void 0;
|
|
319
|
+
const headers = isObject(headersVal) ? headersVal : {};
|
|
320
|
+
const body = isObject(input) && "body" in input ? input.body : void 0;
|
|
321
|
+
const parseVal = isObject(input) && "parse" in input ? input.parse : void 0;
|
|
322
|
+
const parse = String(parseVal || "json");
|
|
323
|
+
if (!(isNetworkAllowed(ctx?.policies, url) || await requireNetworkApproval(ctx.stackId, ctx.nodeId, ctx?.policies, url))) {
|
|
324
|
+
throw new Error("egress not allowed (approval required)");
|
|
325
|
+
}
|
|
326
|
+
const res = await fetch(url, {
|
|
327
|
+
method,
|
|
328
|
+
headers,
|
|
329
|
+
body: body ? JSON.stringify(body) : void 0
|
|
330
|
+
});
|
|
331
|
+
const text = await res.text();
|
|
332
|
+
if (!res.ok) throw new Error(`http ${res.status}: ${text.slice(0, 256)}`);
|
|
333
|
+
try {
|
|
334
|
+
return parse === "json" ? JSON.parse(text) : { text };
|
|
335
|
+
} catch {
|
|
336
|
+
return { text };
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (!runners.getWorker("items.pickPreferred.v1")) {
|
|
341
|
+
runners.registerWorker("items.pickPreferred.v1", async (_m, input) => {
|
|
342
|
+
const itemsVal = isObject(input) && "items" in input ? input.items : void 0;
|
|
343
|
+
const items = isArray(itemsVal) ? itemsVal : [];
|
|
344
|
+
const preferVal = isObject(input) && "prefer" in input ? input.prefer : void 0;
|
|
345
|
+
const prefer = isArray(preferVal) ? preferVal : [];
|
|
346
|
+
const typeKeyVal = isObject(input) && "typeKey" in input ? input.typeKey : void 0;
|
|
347
|
+
const typeKey = String(typeKeyVal || "type");
|
|
348
|
+
const groupKeyVal = isObject(input) && "groupKey" in input ? input.groupKey : void 0;
|
|
349
|
+
const groupKey = String(groupKeyVal || "group");
|
|
350
|
+
const key = (p) => {
|
|
351
|
+
if (isObject(p) && typeKey in p) {
|
|
352
|
+
return String(p[typeKey] || "").toLowerCase();
|
|
353
|
+
}
|
|
354
|
+
return "";
|
|
355
|
+
};
|
|
356
|
+
const groups = /* @__PURE__ */ new Map();
|
|
357
|
+
for (const p of items) {
|
|
358
|
+
const id = isObject(p) && groupKey in p ? String(p[groupKey] ?? "group") : "group";
|
|
359
|
+
const arr = groups.get(id) || [];
|
|
360
|
+
arr.push(p);
|
|
361
|
+
groups.set(id, arr);
|
|
362
|
+
}
|
|
363
|
+
const selected = [];
|
|
364
|
+
for (const [, arr] of groups.entries()) {
|
|
365
|
+
let pick = null;
|
|
366
|
+
for (const t of prefer) {
|
|
367
|
+
pick = arr.find((p) => key(p).includes(String(t).toLowerCase()));
|
|
368
|
+
if (pick) break;
|
|
369
|
+
}
|
|
370
|
+
pick = pick || arr[0];
|
|
371
|
+
if (pick) selected.push(pick);
|
|
372
|
+
}
|
|
373
|
+
return { selected };
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
if (!runners.getWorker("transform.buildPrompt.v1")) {
|
|
377
|
+
runners.registerWorker("transform.buildPrompt.v1", async (_m, input) => {
|
|
378
|
+
const questionVal = isObject(input) && "question" in input ? input.question : void 0;
|
|
379
|
+
const q = String(questionVal || "");
|
|
380
|
+
const ctxVal = isObject(input) && "context" in input ? input.context : void 0;
|
|
381
|
+
const ctx = isObject(ctxVal) ? ctxVal : {};
|
|
382
|
+
const preview = JSON.stringify(ctx).slice(0, 2e3);
|
|
383
|
+
const prompt = `Context: ${preview}
|
|
384
|
+
|
|
385
|
+
Question: ${q}
|
|
386
|
+
Answer with observed facts first, then follow-ups and uncertainties.`;
|
|
387
|
+
return { prompt };
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
if (!runners.getWorker("intel.embedText.v1")) {
|
|
391
|
+
runners.registerWorker("intel.embedText.v1", async (_m, input) => {
|
|
392
|
+
const { encodeTextBatch } = await import("./embeddings-MAEWWUHW.js");
|
|
393
|
+
const textVal = isObject(input) && "text" in input ? input.text : void 0;
|
|
394
|
+
const text = String(textVal || "");
|
|
395
|
+
const [vec] = await encodeTextBatch([text]);
|
|
396
|
+
return { vector: vec };
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
runners.registerWorker("intel.llm.http.v1", async (_m, input, ctx) => {
|
|
400
|
+
const { isNetworkAllowed, requireNetworkApproval } = await import("./policy-IRJCM6FS.js");
|
|
401
|
+
const typedInput = input;
|
|
402
|
+
const promptVal = isObject(input) && "prompt" in input ? input.prompt : void 0;
|
|
403
|
+
const prompt = String(promptVal || "");
|
|
404
|
+
const modelVal = isObject(input) && "model" in input ? input.model : void 0;
|
|
405
|
+
const model = String(modelVal || "openrouter/auto");
|
|
406
|
+
const apiKeyVal = isObject(input) && "apiKey" in input ? input.apiKey : void 0;
|
|
407
|
+
const secretsApiKey = isObject(typedInput.__secrets) ? typedInput.__secrets.OPENROUTER_API_KEY : void 0;
|
|
408
|
+
let apiKey = String(apiKeyVal || (isString(secretsApiKey) ? secretsApiKey : "") || "");
|
|
409
|
+
if (!apiKey) {
|
|
410
|
+
try {
|
|
411
|
+
const { resolveSecretValue } = await import("./secret-store-H7273UIT.js");
|
|
412
|
+
const value = await resolveSecretValue("OPENROUTER_API_KEY", {
|
|
413
|
+
ownerId: ctx.userId || "anonymous",
|
|
414
|
+
stackId: ctx.stackId,
|
|
415
|
+
nodeId: ctx.nodeId,
|
|
416
|
+
appletId: ctx.appletId,
|
|
417
|
+
worldId: ctx.worldId,
|
|
418
|
+
terminalId: ctx.terminalId
|
|
419
|
+
});
|
|
420
|
+
if (value) apiKey = value;
|
|
421
|
+
} catch {
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const url = "https://openrouter.ai/api/v1/chat/completions";
|
|
425
|
+
if (!(isNetworkAllowed(ctx?.policies, url) || await requireNetworkApproval(ctx.stackId, ctx.nodeId, ctx?.policies, url))) {
|
|
426
|
+
throw new Error("egress not allowed (approval required)");
|
|
427
|
+
}
|
|
428
|
+
const res = await fetch(url, {
|
|
429
|
+
method: "POST",
|
|
430
|
+
headers: {
|
|
431
|
+
"Content-Type": "application/json",
|
|
432
|
+
...apiKey ? { Authorization: `Bearer ${apiKey}` } : {}
|
|
433
|
+
},
|
|
434
|
+
body: JSON.stringify({
|
|
435
|
+
model,
|
|
436
|
+
messages: [{ role: "user", content: prompt }],
|
|
437
|
+
stream: false
|
|
438
|
+
})
|
|
439
|
+
});
|
|
440
|
+
const json = await res.json().catch(() => ({ error: "failed to parse" }));
|
|
441
|
+
if (!res.ok) throw new Error(json?.error || `llm http ${res.status}`);
|
|
442
|
+
const text = json?.choices?.[0]?.message?.content || "";
|
|
443
|
+
return {
|
|
444
|
+
text,
|
|
445
|
+
messages: json?.choices?.[0]?.messages || [{ role: "assistant", content: text }]
|
|
446
|
+
};
|
|
447
|
+
});
|
|
448
|
+
runners.registerWorker("integration.source.poll.v1", async (_m, input, ctx) => {
|
|
449
|
+
const { getProvider: getProvider2 } = await import("./registry-FW63E7FE.js");
|
|
450
|
+
const providerIdVal = isObject(input) && "provider" in input ? input.provider : void 0;
|
|
451
|
+
const providerId = String(providerIdVal || "");
|
|
452
|
+
const resourceVal = isObject(input) && "resource" in input ? input.resource : void 0;
|
|
453
|
+
const resource = String(resourceVal || "");
|
|
454
|
+
const configVal = isObject(input) && "config" in input ? input.config : void 0;
|
|
455
|
+
const config = isObject(configVal) ? configVal : {};
|
|
456
|
+
const cursorKeyVal = isObject(input) && "cursorKey" in input ? input.cursorKey : void 0;
|
|
457
|
+
const cursorKey = String(cursorKeyVal || `${providerId}:${resource}`);
|
|
458
|
+
const prov = getProvider2(providerId);
|
|
459
|
+
if (!prov?.integration) throw new Error(`provider not found: ${providerId}`);
|
|
460
|
+
const secrets = {};
|
|
461
|
+
try {
|
|
462
|
+
const { resolveSecretValue } = await import("./secret-store-H7273UIT.js");
|
|
463
|
+
const names = ["DISCORD_BOT_TOKEN"];
|
|
464
|
+
for (const n of names) {
|
|
465
|
+
const value = await resolveSecretValue(n, {
|
|
466
|
+
ownerId: ctx.userId || "anonymous",
|
|
467
|
+
stackId: ctx.stackId,
|
|
468
|
+
nodeId: ctx.nodeId,
|
|
469
|
+
appletId: ctx.appletId,
|
|
470
|
+
worldId: ctx.worldId,
|
|
471
|
+
terminalId: ctx.terminalId
|
|
472
|
+
});
|
|
473
|
+
if (value) secrets[n] = value;
|
|
474
|
+
}
|
|
475
|
+
} catch {
|
|
476
|
+
}
|
|
477
|
+
const mem = (await import("./core-H2UUDATO.js")).temporalKV();
|
|
478
|
+
const cur = await mem.handle({ get: { key: cursorKey } });
|
|
479
|
+
const cursor = cur?.value ? String(cur.value) : void 0;
|
|
480
|
+
const req = prov.integration.buildRequest("poll", { resource, config, cursor }, secrets);
|
|
481
|
+
const { isNetworkAllowed, requireNetworkApproval } = await import("./policy-IRJCM6FS.js");
|
|
482
|
+
if (!(isNetworkAllowed(ctx?.policies, req.url) || await requireNetworkApproval(ctx.stackId, ctx.nodeId, ctx?.policies, req.url))) {
|
|
483
|
+
throw new Error("egress not allowed (approval required)");
|
|
484
|
+
}
|
|
485
|
+
const res = await fetch(req.url, {
|
|
486
|
+
method: req.method,
|
|
487
|
+
headers: req.headers
|
|
488
|
+
});
|
|
489
|
+
const text = await res.text();
|
|
490
|
+
const raw = req.parse === "json" ? JSON.parse(text) : text;
|
|
491
|
+
const items = prov.integration.toEnvelope(raw, resource);
|
|
492
|
+
const nextCursor = prov.integration.extractCursor && prov.integration.extractCursor(raw, cursor) || cursor || null;
|
|
493
|
+
if (nextCursor && nextCursor !== cursor)
|
|
494
|
+
await mem.handle({ put: { key: cursorKey, value: nextCursor } });
|
|
495
|
+
return { items, cursor: nextCursor };
|
|
496
|
+
});
|
|
497
|
+
runners.registerWorker("integration.sink.post.v1", async (_m, input, ctx) => {
|
|
498
|
+
const { getProvider: getProvider2 } = await import("./registry-FW63E7FE.js");
|
|
499
|
+
const providerIdVal = isObject(input) && "provider" in input ? input.provider : void 0;
|
|
500
|
+
const providerId = String(providerIdVal || "");
|
|
501
|
+
const resourceVal = isObject(input) && "resource" in input ? input.resource : void 0;
|
|
502
|
+
const resource = String(resourceVal || "");
|
|
503
|
+
const configVal = isObject(input) && "config" in input ? input.config : void 0;
|
|
504
|
+
const config = isObject(configVal) ? configVal : {};
|
|
505
|
+
const singleItem = isObject(input) && "item" in input ? input.item : void 0;
|
|
506
|
+
const itemsVal = isObject(input) && "items" in input ? input.items : void 0;
|
|
507
|
+
const itemsArray = isArray(itemsVal) ? itemsVal : void 0;
|
|
508
|
+
const items = itemsArray || (singleItem !== void 0 ? [singleItem] : []);
|
|
509
|
+
const prov = getProvider2(providerId);
|
|
510
|
+
if (!prov?.integration) throw new Error(`provider not found: ${providerId}`);
|
|
511
|
+
const secrets = {};
|
|
512
|
+
try {
|
|
513
|
+
const { resolveSecretValue } = await import("./secret-store-H7273UIT.js");
|
|
514
|
+
const names = ["DISCORD_BOT_TOKEN"];
|
|
515
|
+
for (const n of names) {
|
|
516
|
+
const value = await resolveSecretValue(n, {
|
|
517
|
+
ownerId: ctx.userId || "anonymous",
|
|
518
|
+
stackId: ctx.stackId,
|
|
519
|
+
nodeId: ctx.nodeId,
|
|
520
|
+
appletId: ctx.appletId,
|
|
521
|
+
worldId: ctx.worldId,
|
|
522
|
+
terminalId: ctx.terminalId
|
|
523
|
+
});
|
|
524
|
+
if (value) secrets[n] = value;
|
|
525
|
+
}
|
|
526
|
+
} catch {
|
|
527
|
+
}
|
|
528
|
+
const { isNetworkAllowed, requireNetworkApproval } = await import("./policy-IRJCM6FS.js");
|
|
529
|
+
let lastStatus = 0;
|
|
530
|
+
let allOk = true;
|
|
531
|
+
for (const it of items) {
|
|
532
|
+
const itemPayload = isObject(it) ? it : { value: it };
|
|
533
|
+
const req = prov.integration.buildRequest(
|
|
534
|
+
"post",
|
|
535
|
+
{ resource, config, item: itemPayload },
|
|
536
|
+
secrets
|
|
537
|
+
);
|
|
538
|
+
if (!(isNetworkAllowed(ctx?.policies, req.url) || await requireNetworkApproval(ctx.stackId, ctx.nodeId, ctx?.policies, req.url))) {
|
|
539
|
+
throw new Error("egress not allowed (approval required)");
|
|
540
|
+
}
|
|
541
|
+
const res = await fetch(req.url, {
|
|
542
|
+
method: req.method,
|
|
543
|
+
headers: req.headers,
|
|
544
|
+
body: req.body ? JSON.stringify(req.body) : void 0
|
|
545
|
+
});
|
|
546
|
+
lastStatus = res.status;
|
|
547
|
+
allOk = allOk && res.ok;
|
|
548
|
+
}
|
|
549
|
+
if (items.length === 0) {
|
|
550
|
+
return { ok: true, status: 204 };
|
|
551
|
+
}
|
|
552
|
+
return { ok: allOk, status: lastStatus };
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
export {
|
|
556
|
+
runners
|
|
557
|
+
};
|