@standardagents/builder 0.41.7 → 0.41.8
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/built-in-routes.js +48 -39
- package/dist/built-in-routes.js.map +1 -1
- package/dist/{discovery-CIGNVJfG.d.ts → discovery-D5pmuazY.d.ts} +1 -1
- package/dist/{index-PSu6cMEz.d.ts → index-ChHAVogf.d.ts} +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.js +88 -11
- package/dist/index.js.map +1 -1
- package/dist/packing.d.ts +3 -3
- package/dist/plugin.js +9 -1
- package/dist/plugin.js.map +1 -1
- package/dist/resolver-BMZAzKD3.d.ts +4522 -0
- package/dist/runtime.d.ts +10 -4519
- package/dist/runtime.js +80 -11
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +2 -2
- package/dist/{types-D1ABHvAH.d.ts → types-Dhd0M369.d.ts} +1 -1
- package/package.json +5 -5
package/dist/runtime.js
CHANGED
|
@@ -30198,6 +30198,41 @@ function canAccessThread(auth, thread) {
|
|
|
30198
30198
|
return thread.user_id === auth.user.id;
|
|
30199
30199
|
}
|
|
30200
30200
|
|
|
30201
|
+
// src/users/upstream-timing.ts
|
|
30202
|
+
var UPSTREAM_TIMING_HEADER = "x-standard-upstream-timing";
|
|
30203
|
+
var MAX_HEADER_CHARS = 512;
|
|
30204
|
+
function formatUpstreamTiming(name, durationMs) {
|
|
30205
|
+
const safe = Number.isFinite(durationMs) && durationMs > 0 ? durationMs : 0;
|
|
30206
|
+
return `${name};dur=${Math.round(safe * 10) / 10}`;
|
|
30207
|
+
}
|
|
30208
|
+
function appendUpstreamTiming(current, name, durationMs) {
|
|
30209
|
+
const entry = formatUpstreamTiming(name, durationMs);
|
|
30210
|
+
if (!current) return entry;
|
|
30211
|
+
const combined = `${current}, ${entry}`;
|
|
30212
|
+
return combined.length > MAX_HEADER_CHARS ? current : combined;
|
|
30213
|
+
}
|
|
30214
|
+
function withUpstreamTiming(request, value) {
|
|
30215
|
+
const headers = new Headers(request.headers);
|
|
30216
|
+
headers.set(UPSTREAM_TIMING_HEADER, value);
|
|
30217
|
+
return new Request(request, { headers });
|
|
30218
|
+
}
|
|
30219
|
+
function responseWithUpstreamTiming(response, name, durationMs) {
|
|
30220
|
+
if (response.status === 101) return response;
|
|
30221
|
+
const value = appendUpstreamTiming(response.headers.get(UPSTREAM_TIMING_HEADER), name, durationMs);
|
|
30222
|
+
try {
|
|
30223
|
+
response.headers.set(UPSTREAM_TIMING_HEADER, value);
|
|
30224
|
+
return response;
|
|
30225
|
+
} catch {
|
|
30226
|
+
const headers = new Headers(response.headers);
|
|
30227
|
+
headers.set(UPSTREAM_TIMING_HEADER, value);
|
|
30228
|
+
return new Response(response.body, {
|
|
30229
|
+
status: response.status,
|
|
30230
|
+
statusText: response.statusText,
|
|
30231
|
+
headers
|
|
30232
|
+
});
|
|
30233
|
+
}
|
|
30234
|
+
}
|
|
30235
|
+
|
|
30201
30236
|
// src/runtime.ts
|
|
30202
30237
|
init_client_forwarding();
|
|
30203
30238
|
init_DurableThread();
|
|
@@ -30451,6 +30486,9 @@ var UserStateImpl = class {
|
|
|
30451
30486
|
host;
|
|
30452
30487
|
/** Caller descriptor for grant `allow` policy checks. */
|
|
30453
30488
|
caller;
|
|
30489
|
+
/** One identity lookup per execution: the singleton RPC runs at most once. */
|
|
30490
|
+
identityLookup = null;
|
|
30491
|
+
identityLookupMs = null;
|
|
30454
30492
|
constructor(userId, host, caller) {
|
|
30455
30493
|
this.userId = userId;
|
|
30456
30494
|
this.host = host;
|
|
@@ -30462,6 +30500,22 @@ var UserStateImpl = class {
|
|
|
30462
30500
|
return ns.get(ns.idFromName("singleton"));
|
|
30463
30501
|
}
|
|
30464
30502
|
async identity() {
|
|
30503
|
+
if (!this.identityLookup) {
|
|
30504
|
+
const started = Date.now();
|
|
30505
|
+
this.identityLookup = this.lookupIdentity().finally(() => {
|
|
30506
|
+
this.identityLookupMs = Date.now() - started;
|
|
30507
|
+
});
|
|
30508
|
+
this.identityLookup.catch(() => {
|
|
30509
|
+
this.identityLookup = null;
|
|
30510
|
+
});
|
|
30511
|
+
}
|
|
30512
|
+
return this.identityLookup;
|
|
30513
|
+
}
|
|
30514
|
+
/** Milliseconds the execution spent resolving identity, once it has. */
|
|
30515
|
+
timing() {
|
|
30516
|
+
return { identity_ms: this.identityLookupMs };
|
|
30517
|
+
}
|
|
30518
|
+
async lookupIdentity() {
|
|
30465
30519
|
const user = await this.singleton().getUserById(this.userId);
|
|
30466
30520
|
if (!user) throw new Error(`Unknown user: ${this.userId}`);
|
|
30467
30521
|
return {
|
|
@@ -30560,6 +30614,9 @@ function createExecutionChain() {
|
|
|
30560
30614
|
};
|
|
30561
30615
|
}
|
|
30562
30616
|
|
|
30617
|
+
// src/durable-objects/DurableUserHub.ts
|
|
30618
|
+
init_bridge_owner();
|
|
30619
|
+
|
|
30563
30620
|
// src/users/grants.ts
|
|
30564
30621
|
var INSTANCE_GRANTS_MAX_BYTES = 64 * 1024;
|
|
30565
30622
|
var INSTANCE_GRANTS_MAX_COUNT = 64;
|
|
@@ -30800,11 +30857,7 @@ var DurableUserHub = class extends DurableObject {
|
|
|
30800
30857
|
if (request.headers.get("Upgrade") === "websocket") {
|
|
30801
30858
|
const pair = new WebSocketPair();
|
|
30802
30859
|
const [client, server] = [pair[0], pair[1]];
|
|
30803
|
-
const info =
|
|
30804
|
-
clientId: url.searchParams.get("client_id"),
|
|
30805
|
-
clientName: url.searchParams.get("client_name"),
|
|
30806
|
-
clientKind: url.searchParams.get("client_kind")
|
|
30807
|
-
};
|
|
30860
|
+
const info = parseBridgeClientParams(url).info;
|
|
30808
30861
|
this.ensureHeartbeatAutoResponse();
|
|
30809
30862
|
this.ctx.acceptWebSocket(server);
|
|
30810
30863
|
server.serializeAttachment({ type: "hub_client", ...info });
|
|
@@ -30903,13 +30956,21 @@ var DurableUserHub = class extends DurableObject {
|
|
|
30903
30956
|
{ status: 500 }
|
|
30904
30957
|
);
|
|
30905
30958
|
}
|
|
30959
|
+
const queuedAt = Date.now();
|
|
30906
30960
|
return this.executionChain.run(async () => {
|
|
30961
|
+
const queueMs = Date.now() - queuedAt;
|
|
30962
|
+
const timed = withUpstreamTiming(
|
|
30963
|
+
request,
|
|
30964
|
+
appendUpstreamTiming(request.headers.get(UPSTREAM_TIMING_HEADER), "queue", queueMs)
|
|
30965
|
+
);
|
|
30907
30966
|
const user = new UserStateImpl(userId, this.scopeHost(), {
|
|
30908
30967
|
kind: "userEndpoint",
|
|
30909
30968
|
name: match.key
|
|
30910
30969
|
});
|
|
30911
30970
|
try {
|
|
30912
|
-
|
|
30971
|
+
const response = await handler.__handler(timed, user, match.params);
|
|
30972
|
+
const identityMs = user.timing().identity_ms;
|
|
30973
|
+
return identityMs === null ? response : responseWithUpstreamTiming(response, "identity", identityMs);
|
|
30913
30974
|
} catch (error) {
|
|
30914
30975
|
return Response.json(
|
|
30915
30976
|
{ error: error instanceof Error ? error.message : "User endpoint failed" },
|
|
@@ -30956,6 +31017,8 @@ var DurableUserHub = class extends DurableObject {
|
|
|
30956
31017
|
this.ctx.waitUntil(run());
|
|
30957
31018
|
}
|
|
30958
31019
|
async webSocketClose(ws) {
|
|
31020
|
+
this.clientSockets.delete(ws);
|
|
31021
|
+
this.clientInfo.delete(ws);
|
|
30959
31022
|
const attachment = ws.deserializeAttachment();
|
|
30960
31023
|
if (attachment?.type === "user_stream") {
|
|
30961
31024
|
this.dispatchUserHooks(String(attachment.userId), "user_client_detached", [
|
|
@@ -30964,10 +31027,7 @@ var DurableUserHub = class extends DurableObject {
|
|
|
30964
31027
|
kind: typeof attachment.clientKind === "string" ? attachment.clientKind : void 0
|
|
30965
31028
|
}
|
|
30966
31029
|
]);
|
|
30967
|
-
return;
|
|
30968
31030
|
}
|
|
30969
|
-
this.clientSockets.delete(ws);
|
|
30970
|
-
this.clientInfo.delete(ws);
|
|
30971
31031
|
}
|
|
30972
31032
|
// ─── User scope: credential grants (spec: Users §6) ───────────────────────
|
|
30973
31033
|
/**
|
|
@@ -31088,7 +31148,16 @@ var DurableUserHub = class extends DurableObject {
|
|
|
31088
31148
|
});
|
|
31089
31149
|
}
|
|
31090
31150
|
async webSocketMessage(ws, _message) {
|
|
31091
|
-
|
|
31151
|
+
const attachment = ws.deserializeAttachment();
|
|
31152
|
+
if (attachment?.type !== "hub_client") return;
|
|
31153
|
+
if (!this.clientSockets.has(ws)) {
|
|
31154
|
+
this.clientSockets.add(ws);
|
|
31155
|
+
this.clientInfo.set(ws, {
|
|
31156
|
+
clientId: typeof attachment.clientId === "string" ? attachment.clientId : null,
|
|
31157
|
+
clientName: typeof attachment.clientName === "string" ? attachment.clientName : null,
|
|
31158
|
+
clientKind: typeof attachment.clientKind === "string" ? attachment.clientKind : null
|
|
31159
|
+
});
|
|
31160
|
+
}
|
|
31092
31161
|
}
|
|
31093
31162
|
async webSocketError(ws) {
|
|
31094
31163
|
await this.webSocketClose(ws);
|
|
@@ -31518,6 +31587,6 @@ init_ProviderRegistry();
|
|
|
31518
31587
|
init_types2();
|
|
31519
31588
|
init_resolver();
|
|
31520
31589
|
|
|
31521
|
-
export { CLIENT_STREAM_CHUNK_BYTES, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, NamespaceResolutionError, ProviderRegistry, ThreadWatchdog, applyRuntimeCors, authenticate, buildImageDescription, callClient, callClientStream, canAccessThread, cat, createNamespaceContext, createThreadEndpointHandler, decodeStreamChunk, defineController2 as defineController, emitThreadEvent, encodeStreamChunk, endpointCallerFromAuth, enhanceFlowState, exists, find, forceTurn, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isAdminOnlyApiRoute, isHostedInstance, isPublicApiRoute, isQualifiedName, isSameOriginBrowserRequest, isTrustedLocalDevelopmentRequest, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, runtimeCorsHeaders, runtimePreflightResponse, stat, supportsClientForwarding, tail, unlink, updateThread, writeFile, writeImage };
|
|
31590
|
+
export { CLIENT_STREAM_CHUNK_BYTES, CodeExecutionBridge, DurableAgentBuilder, DurableThread, DurableUserHub, FlowStateSdk, NamespaceResolutionError, ProviderRegistry, ThreadWatchdog, applyRuntimeCors, authenticate, buildImageDescription, callClient, callClientStream, canAccessThread, cat, createNamespaceContext, createThreadEndpointHandler, decodeStreamChunk, defineController2 as defineController, emitThreadEvent, encodeStreamChunk, endpointCallerFromAuth, enhanceFlowState, exists, find, forceTurn, formatUpstreamTiming, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isAdminOnlyApiRoute, isHostedInstance, isPublicApiRoute, isQualifiedName, isSameOriginBrowserRequest, isTrustedLocalDevelopmentRequest, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, runtimeCorsHeaders, runtimePreflightResponse, stat, supportsClientForwarding, tail, unlink, updateThread, withUpstreamTiming, writeFile, writeImage };
|
|
31522
31591
|
//# sourceMappingURL=runtime.js.map
|
|
31523
31592
|
//# sourceMappingURL=runtime.js.map
|