@ixo/oracle-runtime-workers 0.2.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 +110 -0
- package/package.json +77 -0
- package/src/attachments/classify.ts +114 -0
- package/src/attachments/content-blocks.ts +51 -0
- package/src/attachments/download.ts +235 -0
- package/src/attachments/extract.ts +241 -0
- package/src/attachments/index.ts +84 -0
- package/src/attachments/magic.ts +133 -0
- package/src/attachments/pipeline.ts +409 -0
- package/src/attachments/retention.ts +205 -0
- package/src/attachments/route.ts +41 -0
- package/src/attachments/sandbox-archive.ts +90 -0
- package/src/attachments/sanitize.ts +35 -0
- package/src/attachments/types.ts +86 -0
- package/src/attachments/view.ts +107 -0
- package/src/core/env.ts +200 -0
- package/src/core/index.ts +513 -0
- package/src/core/llm.ts +842 -0
- package/src/core/main-agent-types.ts +123 -0
- package/src/core/main-agent.ts +399 -0
- package/src/core/manifest.ts +365 -0
- package/src/core/meta-tools.ts +232 -0
- package/src/core/middlewares/byo-history-sanitizer.ts +165 -0
- package/src/core/middlewares/capability-gate.ts +76 -0
- package/src/core/middlewares/index.ts +18 -0
- package/src/core/middlewares/page-context.ts +98 -0
- package/src/core/middlewares/safety-guardrail.ts +117 -0
- package/src/core/middlewares/summarization.ts +99 -0
- package/src/core/middlewares/tool-repetition-guard.ts +125 -0
- package/src/core/middlewares/tool-validation.ts +83 -0
- package/src/core/middlewares/work-status.ts +57 -0
- package/src/core/openrouter-pricing.ts +124 -0
- package/src/core/plugin-loader.ts +192 -0
- package/src/core/plugins/index.ts +6 -0
- package/src/core/plugins/skills/index.ts +8 -0
- package/src/core/plugins/skills/skills-tools.ts +356 -0
- package/src/core/plugins/skills/skills.plugin.ts +113 -0
- package/src/core/plugins/weather/index.ts +8 -0
- package/src/core/plugins/weather/weather-client.ts +153 -0
- package/src/core/plugins/weather/weather-middleware.ts +27 -0
- package/src/core/plugins/weather/weather-sub-agent.ts +65 -0
- package/src/core/plugins/weather/weather-tools.ts +103 -0
- package/src/core/plugins/weather/weather.plugin.ts +227 -0
- package/src/core/prompt-composer.ts +469 -0
- package/src/core/registries.ts +642 -0
- package/src/core/runtime-context.ts +619 -0
- package/src/core/state.ts +108 -0
- package/src/core/sub-agent-fallback.ts +187 -0
- package/src/core/subagent-as-tool.ts +322 -0
- package/src/core/template.ts +245 -0
- package/src/core/utils.ts +246 -0
- package/src/core/wrap-plugin-tool.ts +100 -0
- package/src/do/ambient.ts +266 -0
- package/src/do/contracts.ts +562 -0
- package/src/do/debug-timers.ts +120 -0
- package/src/do/fresh-stub.ts +32 -0
- package/src/do/gateway-retry.ts +73 -0
- package/src/do/secrets-adapter.ts +32 -0
- package/src/do/size-alerts.ts +76 -0
- package/src/do/sse-stream.ts +472 -0
- package/src/do/transcript.ts +192 -0
- package/src/do/turn-body.ts +84 -0
- package/src/do/turn-metadata.ts +146 -0
- package/src/do/ucan-service.ts +339 -0
- package/src/do/user-oracle-do.ts +3035 -0
- package/src/gateway-worker.ts +82 -0
- package/src/index.ts +237 -0
- package/src/llm/byo-adapter.ts +59 -0
- package/src/llm/byo-catalog.ts +520 -0
- package/src/llm/byo-client.ts +280 -0
- package/src/llm/byo-routes.ts +255 -0
- package/src/llm/byo-service.ts +836 -0
- package/src/llm/chatgpt-oauth.ts +430 -0
- package/src/llm/provider-error.ts +283 -0
- package/src/matrix/gateway-do.ts +918 -0
- package/src/matrix/ingest.ts +209 -0
- package/src/matrix/replay-format.ts +34 -0
- package/src/matrix/reply-chain.ts +109 -0
- package/src/matrix/room-state-codec.ts +115 -0
- package/src/matrix/user-homeserver.ts +106 -0
- package/src/matrix/work-status.ts +294 -0
- package/src/memory/session-history-indexer.ts +328 -0
- package/src/owner-store/ixo-vfs-store.ts +570 -0
- package/src/owner-store/matrix-media-store.ts +136 -0
- package/src/owner-store/migrating-store.ts +185 -0
- package/src/owner-store/owner-copy-errors.ts +175 -0
- package/src/owner-store/retry.ts +45 -0
- package/src/owner-store/tus-upload.ts +333 -0
- package/src/owner-store/types.ts +0 -0
- package/src/plugin-api/define-plugin.ts +45 -0
- package/src/plugin-api/index.ts +56 -0
- package/src/plugin-api/oracle-plugin.ts +145 -0
- package/src/plugin-api/tool-helper.ts +82 -0
- package/src/plugin-api/types.ts +816 -0
- package/src/plugin-api/ucan-errors.ts +16 -0
- package/src/plugins/agui/agui-agent.ts +115 -0
- package/src/plugins/agui/agui.plugin.ts +148 -0
- package/src/plugins/agui/index.ts +2 -0
- package/src/plugins/attachments/attachments.plugin.ts +54 -0
- package/src/plugins/attachments/index.ts +6 -0
- package/src/plugins/attachments/view-attachment-tool.ts +91 -0
- package/src/plugins/base64.ts +26 -0
- package/src/plugins/composio/composio-tools.ts +365 -0
- package/src/plugins/composio/composio-ucan.ts +43 -0
- package/src/plugins/composio/composio.plugin.ts +214 -0
- package/src/plugins/composio/index.ts +15 -0
- package/src/plugins/domain-indexer/domain-indexer-agent.ts +57 -0
- package/src/plugins/domain-indexer/domain-indexer-tools.ts +253 -0
- package/src/plugins/domain-indexer/domain-indexer.plugin.ts +100 -0
- package/src/plugins/domain-indexer/index.ts +3 -0
- package/src/plugins/editor/blocknote-bridge.ts +120 -0
- package/src/plugins/editor/content-session.ts +331 -0
- package/src/plugins/editor/content-tools.ts +686 -0
- package/src/plugins/editor/document-model.ts +0 -0
- package/src/plugins/editor/editor-access-denied-tool.ts +58 -0
- package/src/plugins/editor/editor-agent.ts +34 -0
- package/src/plugins/editor/editor-config.ts +64 -0
- package/src/plugins/editor/editor-mx.ts +128 -0
- package/src/plugins/editor/editor.plugin.ts +143 -0
- package/src/plugins/editor/failures.ts +154 -0
- package/src/plugins/editor/index.ts +31 -0
- package/src/plugins/editor/jsdom-shim.ts +55 -0
- package/src/plugins/editor/prompts.ts +59 -0
- package/src/plugins/editor/prop-policy.ts +147 -0
- package/src/plugins/editor/provider.ts +386 -0
- package/src/plugins/editor/room-membership.ts +95 -0
- package/src/plugins/editor/standalone-editor-tool.ts +200 -0
- package/src/plugins/firecrawl/firecrawl-agent.ts +93 -0
- package/src/plugins/firecrawl/firecrawl-tools.ts +220 -0
- package/src/plugins/firecrawl/firecrawl.plugin.ts +105 -0
- package/src/plugins/firecrawl/index.ts +15 -0
- package/src/plugins/flows/action-metadata.ts +3505 -0
- package/src/plugins/flows/actions.ts +190 -0
- package/src/plugins/flows/edit.ts +314 -0
- package/src/plugins/flows/errors.ts +38 -0
- package/src/plugins/flows/explain.ts +43 -0
- package/src/plugins/flows/flow-doc.ts +111 -0
- package/src/plugins/flows/flows.plugin.ts +129 -0
- package/src/plugins/flows/forms.ts +330 -0
- package/src/plugins/flows/index.ts +2 -0
- package/src/plugins/flows/linkage.ts +147 -0
- package/src/plugins/flows/port-types.ts +53 -0
- package/src/plugins/flows/prompts.ts +65 -0
- package/src/plugins/flows/read.ts +392 -0
- package/src/plugins/flows/references.ts +66 -0
- package/src/plugins/flows/test-support.ts +165 -0
- package/src/plugins/flows/tools/authoring.ts +516 -0
- package/src/plugins/flows/tools/discovery.ts +119 -0
- package/src/plugins/flows/tools/forms.ts +142 -0
- package/src/plugins/flows/tools/inspect.ts +165 -0
- package/src/plugins/flows/tools/linkage.ts +117 -0
- package/src/plugins/flows/tools/settings.ts +184 -0
- package/src/plugins/flows/translator.ts +328 -0
- package/src/plugins/flows/types.ts +210 -0
- package/src/plugins/flows/ydoc-helpers.ts +543 -0
- package/src/plugins/index.ts +70 -0
- package/src/plugins/mcp-call-timeout.ts +38 -0
- package/src/plugins/mcp-tool-adapter.ts +87 -0
- package/src/plugins/memory/index.ts +17 -0
- package/src/plugins/memory/memory-tools.ts +463 -0
- package/src/plugins/memory/memory-ucan.ts +51 -0
- package/src/plugins/memory/memory.plugin.ts +122 -0
- package/src/plugins/memory/types.ts +147 -0
- package/src/plugins/portal/action-log.ts +34 -0
- package/src/plugins/portal/index.ts +2 -0
- package/src/plugins/portal/portal.plugin.ts +203 -0
- package/src/plugins/sandbox/index.ts +34 -0
- package/src/plugins/sandbox/sandbox-bridge.ts +295 -0
- package/src/plugins/sandbox/sandbox-mcp.ts +127 -0
- package/src/plugins/sandbox/sandbox-write-blob.ts +103 -0
- package/src/plugins/sandbox/sandbox.plugin.ts +599 -0
- package/src/plugins/tasks/index.ts +17 -0
- package/src/plugins/tasks/manifest.ts +81 -0
- package/src/plugins/tasks/middleware.ts +219 -0
- package/src/plugins/tasks/tasks-tools.ts +414 -0
- package/src/plugins/tasks/tasks.plugin.ts +74 -0
- package/src/plugins/ucan-failure.ts +133 -0
- package/src/plugins/user-preferences/index.ts +22 -0
- package/src/plugins/user-preferences/schema.ts +31 -0
- package/src/plugins/user-preferences/user-preferences-store.ts +172 -0
- package/src/plugins/user-preferences/user-preferences-tool.ts +131 -0
- package/src/plugins/user-preferences/user-preferences.plugin.ts +137 -0
- package/src/plugins/vfs/index.ts +40 -0
- package/src/plugins/vfs/vfs-auth.ts +56 -0
- package/src/plugins/vfs/vfs-client.ts +655 -0
- package/src/plugins/vfs/vfs-content.ts +181 -0
- package/src/plugins/vfs/vfs-errors.ts +163 -0
- package/src/plugins/vfs/vfs-sandbox-tools.ts +272 -0
- package/src/plugins/vfs/vfs-tools.ts +635 -0
- package/src/plugins/vfs/vfs.plugin.ts +201 -0
- package/src/realtime/frontend-call-registry.ts +163 -0
- package/src/realtime/realtime-endpoint.ts +619 -0
- package/src/realtime/session-socket-hub.ts +249 -0
- package/src/realtime/socket-io-codec.ts +187 -0
- package/src/secrets/jwe.ts +74 -0
- package/src/secrets/pin-cipher.ts +43 -0
- package/src/secrets/secrets-service.ts +319 -0
- package/src/shell/app.ts +564 -0
- package/src/shell/auth.ts +290 -0
- package/src/sqlite/blob-codec.ts +100 -0
- package/src/sqlite/blob-compactor.ts +146 -0
- package/src/sqlite/cache-config.ts +45 -0
- package/src/sqlite/database.ts +643 -0
- package/src/sqlite/do-vfs.ts +1485 -0
- package/src/sqlite/index.ts +61 -0
- package/src/sqlite/serialization.ts +370 -0
- package/src/sqlite/sessions-store.ts +311 -0
- package/src/sqlite/sqlite-saver.ts +919 -0
- package/src/sqlite/vacuum-policy.ts +77 -0
- package/src/sqlite/wa-sqlite-loader.ts +123 -0
- package/src/sqlite/wasm.d.ts +10 -0
- package/src/tasks/schedule.ts +174 -0
- package/src/tasks/scheduler.ts +753 -0
- package/src/tasks/spec.ts +125 -0
- package/src/tasks/store.ts +351 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workers implementations of the core's `AmbientServices` adapters, built
|
|
3
|
+
* once per `UserOracleDO` instance:
|
|
4
|
+
*
|
|
5
|
+
* - matrix → RPC through the oracle's `MatrixGatewayDO` (the only object
|
|
6
|
+
* holding the bot's crypto).
|
|
7
|
+
* - ucan → `WorkersUcanService` (oracle signing key from env).
|
|
8
|
+
* - blobStore → this object's storage with an expiry column.
|
|
9
|
+
* - secrets → per-room JWE secrets via `WorkersSecretsService` when the
|
|
10
|
+
* host supplies the adapter (`do/secrets-adapter.ts`); the
|
|
11
|
+
* empty fallback stays for hosts without a seated key/room.
|
|
12
|
+
* - emit → routed to the SSE writer of the turn that owns the
|
|
13
|
+
* payload's `sessionId` (same shape as the Node `wsEmitter`).
|
|
14
|
+
*/
|
|
15
|
+
import type {
|
|
16
|
+
AmbientServices,
|
|
17
|
+
DelegationLike,
|
|
18
|
+
EmitAdapter,
|
|
19
|
+
RawEventPayload,
|
|
20
|
+
SecretsAdapter,
|
|
21
|
+
} from '../core/runtime-context';
|
|
22
|
+
import type { LlmAdapter } from '../core/runtime-context';
|
|
23
|
+
import type {
|
|
24
|
+
Logger,
|
|
25
|
+
MatrixEvent,
|
|
26
|
+
OracleIdentity,
|
|
27
|
+
RoomStateSnapshot,
|
|
28
|
+
} from '../plugin-api/types';
|
|
29
|
+
import type { MatrixGatewayObject } from './contracts';
|
|
30
|
+
import { type WorkersUcanService } from './ucan-service';
|
|
31
|
+
|
|
32
|
+
export interface EventSink {
|
|
33
|
+
emit(eventName: string, payload: RawEventPayload): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Fan-out addressed by `payload.sessionId`: the sinks registered for that
|
|
38
|
+
* session (the SSE stream of the in-flight turn) plus every tap (the
|
|
39
|
+
* realtime socket hub, which routes by session itself) — the Workers shape
|
|
40
|
+
* of Node's `wsEmitter` + `server.to(sessionId)`.
|
|
41
|
+
*/
|
|
42
|
+
export class SessionEventRouter implements EmitAdapter {
|
|
43
|
+
private readonly sinks = new Map<string, Set<EventSink>>();
|
|
44
|
+
private readonly taps = new Set<EventSink>();
|
|
45
|
+
register(sessionId: string, sink: EventSink): void {
|
|
46
|
+
let set = this.sinks.get(sessionId);
|
|
47
|
+
if (!set) {
|
|
48
|
+
set = new Set();
|
|
49
|
+
this.sinks.set(sessionId, set);
|
|
50
|
+
}
|
|
51
|
+
set.add(sink);
|
|
52
|
+
}
|
|
53
|
+
unregister(sessionId: string, sink: EventSink): void {
|
|
54
|
+
const set = this.sinks.get(sessionId);
|
|
55
|
+
if (!set) return;
|
|
56
|
+
set.delete(sink);
|
|
57
|
+
if (set.size === 0) this.sinks.delete(sessionId);
|
|
58
|
+
}
|
|
59
|
+
/** A sink that sees every session's events (it filters by `sessionId`). */
|
|
60
|
+
tap(sink: EventSink): void {
|
|
61
|
+
this.taps.add(sink);
|
|
62
|
+
}
|
|
63
|
+
emit(eventName: string, payload: RawEventPayload): void {
|
|
64
|
+
const sessionId =
|
|
65
|
+
typeof payload.sessionId === 'string' ? payload.sessionId : undefined;
|
|
66
|
+
if (!sessionId) return;
|
|
67
|
+
for (const sink of this.sinks.get(sessionId) ?? []) {
|
|
68
|
+
sink.emit(eventName, payload);
|
|
69
|
+
}
|
|
70
|
+
for (const sink of this.taps) sink.emit(eventName, payload);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Taps only — for frames the in-flight turn's SSE stream already wrote
|
|
75
|
+
* itself (`tool_call`, `action_call`, `router_update`) and that the
|
|
76
|
+
* session's sockets must see too, as Node's WebSocket gateway relays them.
|
|
77
|
+
* Skipping the session sinks keeps the SSE stream from receiving them twice.
|
|
78
|
+
*/
|
|
79
|
+
emitToTaps(eventName: string, payload: RawEventPayload): void {
|
|
80
|
+
if (typeof payload.sessionId !== 'string') return;
|
|
81
|
+
for (const sink of this.taps) sink.emit(eventName, payload);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const BLOB_ID_RE = /^blob_[0-9a-f]{16}$/;
|
|
86
|
+
const BLOB_DEFAULT_TTL_SECONDS = 60 * 60;
|
|
87
|
+
const BLOB_MAX_TTL_SECONDS = 24 * 60 * 60;
|
|
88
|
+
|
|
89
|
+
export function createBlobStore(
|
|
90
|
+
storage: DurableObjectStorage,
|
|
91
|
+
): AmbientServices['blobStore'] {
|
|
92
|
+
return {
|
|
93
|
+
isValidBlobId: (value: unknown): value is string =>
|
|
94
|
+
typeof value === 'string' && BLOB_ID_RE.test(value),
|
|
95
|
+
put: async ({ userDid, name, value, ttlSeconds }) => {
|
|
96
|
+
const bytes = new Uint8Array(8);
|
|
97
|
+
crypto.getRandomValues(bytes);
|
|
98
|
+
const id = `blob_${Array.from(bytes)
|
|
99
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
100
|
+
.join('')}`;
|
|
101
|
+
const ttl = Math.min(
|
|
102
|
+
Math.max(1, ttlSeconds ?? BLOB_DEFAULT_TTL_SECONDS),
|
|
103
|
+
BLOB_MAX_TTL_SECONDS,
|
|
104
|
+
);
|
|
105
|
+
await storage.put(`blob:${userDid}:${id}`, {
|
|
106
|
+
name,
|
|
107
|
+
value,
|
|
108
|
+
expiresAt: Date.now() + ttl * 1000,
|
|
109
|
+
});
|
|
110
|
+
return id;
|
|
111
|
+
},
|
|
112
|
+
get: async ({ userDid, blobId }) => {
|
|
113
|
+
if (!BLOB_ID_RE.test(blobId)) return null;
|
|
114
|
+
const key = `blob:${userDid}:${blobId}`;
|
|
115
|
+
const hit = await storage.get<{
|
|
116
|
+
name: string;
|
|
117
|
+
value: string;
|
|
118
|
+
expiresAt: number;
|
|
119
|
+
}>(key);
|
|
120
|
+
if (!hit) return null;
|
|
121
|
+
if (hit.expiresAt <= Date.now()) {
|
|
122
|
+
await storage.delete(key);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return { name: hit.name, value: hit.value };
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function createMatrixAdapter(
|
|
131
|
+
gateway: DurableObjectStub<MatrixGatewayObject>,
|
|
132
|
+
): AmbientServices['matrix'] {
|
|
133
|
+
return {
|
|
134
|
+
postToRoom: (roomId, content) =>
|
|
135
|
+
gateway.sendEvent(roomId, 'm.room.message', JSON.stringify(content)),
|
|
136
|
+
postEvent: (roomId, eventType, content) =>
|
|
137
|
+
gateway.sendEvent(roomId, eventType, JSON.stringify(content)),
|
|
138
|
+
botCredentials: () => gateway.botCredentials(),
|
|
139
|
+
getRoomState: async (roomId): Promise<RoomStateSnapshot> => {
|
|
140
|
+
const raw = await gateway.getRoomState(roomId);
|
|
141
|
+
return { roomId, state: JSON.parse(raw) as unknown[] };
|
|
142
|
+
},
|
|
143
|
+
getEventById: async (roomId, eventId): Promise<MatrixEvent> => {
|
|
144
|
+
const raw = await gateway.getEvent(roomId, eventId);
|
|
145
|
+
if (!raw) throw new Error(`Event ${eventId} not found in ${roomId}`);
|
|
146
|
+
const ev = JSON.parse(raw) as {
|
|
147
|
+
event_id: string;
|
|
148
|
+
type: string;
|
|
149
|
+
content: unknown;
|
|
150
|
+
sender?: string;
|
|
151
|
+
origin_server_ts?: number;
|
|
152
|
+
};
|
|
153
|
+
return {
|
|
154
|
+
eventId: ev.event_id,
|
|
155
|
+
type: ev.type,
|
|
156
|
+
content: ev.content,
|
|
157
|
+
senderId: ev.sender,
|
|
158
|
+
originServerTs: ev.origin_server_ts,
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function abilityCovers(granted: string, required: string): boolean {
|
|
165
|
+
if (granted === '*' || granted === required) return true;
|
|
166
|
+
if (granted.endsWith('/*')) {
|
|
167
|
+
const ns = granted.slice(0, -2);
|
|
168
|
+
return required === ns || required.startsWith(`${ns}/`);
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function createUcanAdapter(
|
|
174
|
+
service: WorkersUcanService,
|
|
175
|
+
delegationFor: (userDid: string) => { raw?: string } | undefined,
|
|
176
|
+
): AmbientServices['ucan'] {
|
|
177
|
+
const has = (delegation: DelegationLike, resource: string, action: string) =>
|
|
178
|
+
(delegation?.capabilities ?? []).some(
|
|
179
|
+
(c) =>
|
|
180
|
+
(c.resource === resource || c.resource.startsWith(resource)) &&
|
|
181
|
+
abilityCovers(c.action, action),
|
|
182
|
+
);
|
|
183
|
+
return {
|
|
184
|
+
hasCapability: has,
|
|
185
|
+
requireCapability: (delegation, resource, action) => {
|
|
186
|
+
if (!has(delegation, resource, action))
|
|
187
|
+
throw new Error(`Missing UCAN capability ${action} on ${resource}`);
|
|
188
|
+
},
|
|
189
|
+
mintInvocation: async (userDid, target, opts) => {
|
|
190
|
+
const delegation = delegationFor(userDid);
|
|
191
|
+
if (!delegation?.raw)
|
|
192
|
+
throw new Error(
|
|
193
|
+
`No delegation from ${userDid} available to mint an invocation from`,
|
|
194
|
+
);
|
|
195
|
+
const minted = await service.createInvocationFromDelegation(
|
|
196
|
+
delegation.raw,
|
|
197
|
+
target.did,
|
|
198
|
+
{
|
|
199
|
+
can: opts?.can ?? '*',
|
|
200
|
+
with: target.capability,
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
if ('error' in minted) throw new Error(minted.error);
|
|
204
|
+
return minted.invocation;
|
|
205
|
+
},
|
|
206
|
+
resolveServiceDid: (url) => service.resolveServiceDid(url),
|
|
207
|
+
hasSigningKey: () => service.hasSigningKey(),
|
|
208
|
+
createInvocationFromDelegation: (car, url, cap, o) =>
|
|
209
|
+
service.createInvocationFromDelegation(car, url, cap, o),
|
|
210
|
+
mintSelfSignedInvocation: (url, cap, o) =>
|
|
211
|
+
service.mintSelfSignedInvocation(url, cap, o),
|
|
212
|
+
getServiceDelegation: (did, o) => service.getServiceDelegation(did, o),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface CreateAmbientInput {
|
|
217
|
+
/** Host task scheduler surface for this user, when tasks are enabled. */
|
|
218
|
+
tasks?: import('../plugin-api/types').OracleTasksSurface;
|
|
219
|
+
preferences?: import('../plugin-api/types').UserPreferencesSurface;
|
|
220
|
+
/** Host bridge to the user's browser (realtime channel), when terminated here. */
|
|
221
|
+
frontend?: import('../plugin-api/types').FrontendCallSurface;
|
|
222
|
+
/** Per-turn cleanup registry (see `RuntimeContext.onTurnEnd`). */
|
|
223
|
+
onTurnEnd?: (dispose: () => void | Promise<void>) => void;
|
|
224
|
+
config: Record<string, unknown>;
|
|
225
|
+
identity: OracleIdentity;
|
|
226
|
+
availablePlugins: ReadonlySet<string>;
|
|
227
|
+
llm: LlmAdapter;
|
|
228
|
+
logger: Logger;
|
|
229
|
+
storage: DurableObjectStorage;
|
|
230
|
+
gateway: DurableObjectStub<MatrixGatewayObject>;
|
|
231
|
+
ucan: WorkersUcanService;
|
|
232
|
+
delegationFor: (userDid: string) => { raw?: string } | undefined;
|
|
233
|
+
events: SessionEventRouter;
|
|
234
|
+
/**
|
|
235
|
+
* Per-room JWE secrets adapter (`createSecretsAdapter` over
|
|
236
|
+
* `WorkersSecretsService`). Omitted → the empty fallback: plugins see an
|
|
237
|
+
* empty index and degrade exactly as on Node without a key.
|
|
238
|
+
*/
|
|
239
|
+
secrets?: SecretsAdapter;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function createAmbientServices(
|
|
243
|
+
input: CreateAmbientInput,
|
|
244
|
+
): AmbientServices {
|
|
245
|
+
return {
|
|
246
|
+
...(input.tasks ? { tasks: input.tasks } : {}),
|
|
247
|
+
...(input.preferences ? { preferences: input.preferences } : {}),
|
|
248
|
+
...(input.frontend ? { frontend: input.frontend } : {}),
|
|
249
|
+
config: input.config,
|
|
250
|
+
identity: input.identity,
|
|
251
|
+
availablePlugins: input.availablePlugins,
|
|
252
|
+
llm: input.llm,
|
|
253
|
+
logger: input.logger,
|
|
254
|
+
emit: input.events,
|
|
255
|
+
blobStore: createBlobStore(input.storage),
|
|
256
|
+
matrix: createMatrixAdapter(input.gateway),
|
|
257
|
+
ucan: createUcanAdapter(input.ucan, input.delegationFor),
|
|
258
|
+
secrets: input.secrets ?? {
|
|
259
|
+
// Empty fallback for hosts without a secrets service (no key seated,
|
|
260
|
+
// no account room) — plugins see an empty index and degrade exactly
|
|
261
|
+
// as on Node without a key.
|
|
262
|
+
getIndex: async () => ({}),
|
|
263
|
+
getValues: async () => ({}),
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|