@standardagents/builder 0.26.1 → 0.27.1
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 +193 -4
- package/dist/built-in-routes.js.map +1 -1
- package/dist/index.js +580 -48
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +68 -8
- package/dist/runtime.js +580 -48
- package/dist/runtime.js.map +1 -1
- package/package.json +5 -5
package/dist/built-in-routes.js
CHANGED
|
@@ -1113,6 +1113,25 @@ async function awaitBounded(work, budgetMs, label) {
|
|
|
1113
1113
|
if (timer) clearTimeout(timer);
|
|
1114
1114
|
}
|
|
1115
1115
|
}
|
|
1116
|
+
function chunkCarriesPayload(chunk) {
|
|
1117
|
+
switch (chunk.type) {
|
|
1118
|
+
case "content-delta":
|
|
1119
|
+
case "reasoning-delta":
|
|
1120
|
+
return typeof chunk.delta === "string" && chunk.delta.length > 0;
|
|
1121
|
+
case "tool-call-delta":
|
|
1122
|
+
return typeof chunk.argumentsDelta === "string" && chunk.argumentsDelta.length > 0;
|
|
1123
|
+
case "tool-call-start":
|
|
1124
|
+
case "tool-call-done":
|
|
1125
|
+
case "finish":
|
|
1126
|
+
case "image-done":
|
|
1127
|
+
case "web-search-done":
|
|
1128
|
+
case "provider-tool-done":
|
|
1129
|
+
case "error":
|
|
1130
|
+
return true;
|
|
1131
|
+
default:
|
|
1132
|
+
return false;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1116
1135
|
function modelSupportsImageInput(modelDef) {
|
|
1117
1136
|
const supportsImages = modelDef.capabilities?.supportsImages;
|
|
1118
1137
|
if (typeof supportsImages === "boolean") {
|
|
@@ -1924,7 +1943,7 @@ var init_LLMRequest = __esm({
|
|
|
1924
1943
|
if (next.done) break;
|
|
1925
1944
|
const chunk = next.value;
|
|
1926
1945
|
state.thread.instance.noteExecutionProgress?.();
|
|
1927
|
-
if (firstChunkAt === 0) {
|
|
1946
|
+
if (firstChunkAt === 0 && chunkCarriesPayload(chunk)) {
|
|
1928
1947
|
firstChunkAt = Date.now();
|
|
1929
1948
|
emitLogPatch({ time_to_first_token_ms: firstChunkAt - requestSentAt });
|
|
1930
1949
|
}
|
|
@@ -12796,6 +12815,38 @@ var init_ThreadStateImpl = __esm({
|
|
|
12796
12815
|
}
|
|
12797
12816
|
await this._threadInstance.setValue(key, value);
|
|
12798
12817
|
}
|
|
12818
|
+
// Account-wide sibling of the thread KV: values scoped to the thread's user,
|
|
12819
|
+
// shared across every thread that user owns (backed by the singleton
|
|
12820
|
+
// DurableAgentBuilder `user_values` table).
|
|
12821
|
+
async getUserValue(key) {
|
|
12822
|
+
const userId = this._metadata.user_id;
|
|
12823
|
+
if (!userId) return null;
|
|
12824
|
+
const stub = this._getAgentBuilderStub();
|
|
12825
|
+
if (typeof stub.getUserValue !== "function") {
|
|
12826
|
+
throw new Error("getUserValue is not supported by this runtime");
|
|
12827
|
+
}
|
|
12828
|
+
return await stub.getUserValue(userId, key);
|
|
12829
|
+
}
|
|
12830
|
+
async setUserValue(key, value) {
|
|
12831
|
+
const userId = this._metadata.user_id;
|
|
12832
|
+
if (!userId) {
|
|
12833
|
+
throw new Error("setUserValue requires a thread with an associated user");
|
|
12834
|
+
}
|
|
12835
|
+
const stub = this._getAgentBuilderStub();
|
|
12836
|
+
if (typeof stub.setUserValue !== "function") {
|
|
12837
|
+
throw new Error("setUserValue is not supported by this runtime");
|
|
12838
|
+
}
|
|
12839
|
+
await stub.setUserValue(userId, key, value);
|
|
12840
|
+
}
|
|
12841
|
+
async listUserValues(options = {}) {
|
|
12842
|
+
const userId = this._metadata.user_id;
|
|
12843
|
+
if (!userId) return { entries: [], total: 0 };
|
|
12844
|
+
const stub = this._getAgentBuilderStub();
|
|
12845
|
+
if (typeof stub.listUserValues !== "function") {
|
|
12846
|
+
throw new Error("listUserValues is not supported by this runtime");
|
|
12847
|
+
}
|
|
12848
|
+
return stub.listUserValues(userId, options);
|
|
12849
|
+
}
|
|
12799
12850
|
// ─────────────────────────────────────────────────────────────────────────
|
|
12800
12851
|
// Client-forwarded tools
|
|
12801
12852
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -12839,7 +12890,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
12839
12890
|
const instance = this._threadInstance;
|
|
12840
12891
|
const toolCallId = this._flowState?.currentToolCall?.id;
|
|
12841
12892
|
const mustPark = request.requestPermission != null && await this.forwardedCallNeedsApproval(request);
|
|
12842
|
-
if (mustPark && toolCallId && this._executionState && typeof instance.dispatchClientTool === "function" && typeof instance.hasBridge === "function" && instance.hasBridge()) {
|
|
12893
|
+
if (mustPark && toolCallId && this._executionState && typeof instance.dispatchClientTool === "function" && typeof instance.hasBridge === "function" && await instance.hasBridge()) {
|
|
12843
12894
|
const side = this._flowState?.currentSide === "b" ? "b" : "a";
|
|
12844
12895
|
await instance.dispatchClientTool(request, toolCallId, side);
|
|
12845
12896
|
this._executionState.stop();
|
|
@@ -66124,7 +66175,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
|
|
|
66124
66175
|
});
|
|
66125
66176
|
|
|
66126
66177
|
// src/version.ts
|
|
66127
|
-
var BUILDER_VERSION = "0.
|
|
66178
|
+
var BUILDER_VERSION = "0.27.1".length > 0 ? "0.27.1" : "dev";
|
|
66128
66179
|
|
|
66129
66180
|
// src/api/diagnostics.get.ts
|
|
66130
66181
|
init_LLMRequest();
|
|
@@ -71627,7 +71678,9 @@ var tool_result_post_default = defineController2(async ({ req, params, env: env2
|
|
|
71627
71678
|
toolCallId,
|
|
71628
71679
|
body.ok === true,
|
|
71629
71680
|
typeof body.result === "string" ? body.result : void 0,
|
|
71630
|
-
typeof body.error === "string" ? body.error : void 0
|
|
71681
|
+
typeof body.error === "string" ? body.error : void 0,
|
|
71682
|
+
typeof body.client_id === "string" ? body.client_id : void 0,
|
|
71683
|
+
typeof body.generation === "number" ? body.generation : void 0
|
|
71631
71684
|
);
|
|
71632
71685
|
if (!delivered) {
|
|
71633
71686
|
return Response.json({ status: "ignored" }, { status: 200 });
|
|
@@ -72031,6 +72084,139 @@ var env_patch_default2 = defineController2(async ({ req, env: env2 }) => {
|
|
|
72031
72084
|
}
|
|
72032
72085
|
});
|
|
72033
72086
|
|
|
72087
|
+
// src/api/users/me/kv/index.delete.ts
|
|
72088
|
+
var index_delete_default = defineController2(async ({ req, env: env2 }) => {
|
|
72089
|
+
try {
|
|
72090
|
+
const authResult = await requireAuth(req, env2);
|
|
72091
|
+
if (authResult instanceof Response) {
|
|
72092
|
+
return authResult;
|
|
72093
|
+
}
|
|
72094
|
+
if (authResult.authType === "super_admin") {
|
|
72095
|
+
return Response.json(
|
|
72096
|
+
{ error: "Super admin sessions do not have per-user storage. Sign in as a user account." },
|
|
72097
|
+
{ status: 400 }
|
|
72098
|
+
);
|
|
72099
|
+
}
|
|
72100
|
+
const url = new URL(req.url);
|
|
72101
|
+
const key = url.searchParams.get("key");
|
|
72102
|
+
if (!key) {
|
|
72103
|
+
return Response.json({ error: "key query parameter required" }, { status: 400 });
|
|
72104
|
+
}
|
|
72105
|
+
const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
|
|
72106
|
+
const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
72107
|
+
if (typeof agentBuilder.setUserValue !== "function") {
|
|
72108
|
+
return Response.json(
|
|
72109
|
+
{ error: "User value storage is not supported by this runtime" },
|
|
72110
|
+
{ status: 500 }
|
|
72111
|
+
);
|
|
72112
|
+
}
|
|
72113
|
+
await agentBuilder.setUserValue(authResult.user.id, key, null);
|
|
72114
|
+
return Response.json({ status: "ok", key });
|
|
72115
|
+
} catch (error) {
|
|
72116
|
+
console.error("Delete user kv error:", error);
|
|
72117
|
+
return Response.json(
|
|
72118
|
+
{ error: error.message || "Failed to delete user value" },
|
|
72119
|
+
{ status: 500 }
|
|
72120
|
+
);
|
|
72121
|
+
}
|
|
72122
|
+
});
|
|
72123
|
+
|
|
72124
|
+
// src/api/users/me/kv/index.get.ts
|
|
72125
|
+
var index_get_default4 = defineController2(async ({ req, env: env2 }) => {
|
|
72126
|
+
try {
|
|
72127
|
+
const authResult = await requireAuth(req, env2);
|
|
72128
|
+
if (authResult instanceof Response) {
|
|
72129
|
+
return authResult;
|
|
72130
|
+
}
|
|
72131
|
+
if (authResult.authType === "super_admin") {
|
|
72132
|
+
return Response.json(
|
|
72133
|
+
{ error: "Super admin sessions do not have per-user storage. Sign in as a user account." },
|
|
72134
|
+
{ status: 400 }
|
|
72135
|
+
);
|
|
72136
|
+
}
|
|
72137
|
+
const url = new URL(req.url);
|
|
72138
|
+
const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
|
|
72139
|
+
const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
72140
|
+
const key = url.searchParams.get("key");
|
|
72141
|
+
if (key) {
|
|
72142
|
+
if (typeof agentBuilder.getUserValue !== "function") {
|
|
72143
|
+
return Response.json(
|
|
72144
|
+
{ error: "User value storage is not supported by this runtime" },
|
|
72145
|
+
{ status: 500 }
|
|
72146
|
+
);
|
|
72147
|
+
}
|
|
72148
|
+
const value = await agentBuilder.getUserValue(authResult.user.id, key);
|
|
72149
|
+
return Response.json({ key, value });
|
|
72150
|
+
}
|
|
72151
|
+
if (typeof agentBuilder.listUserValues !== "function") {
|
|
72152
|
+
return Response.json(
|
|
72153
|
+
{ error: "User value storage is not supported by this runtime" },
|
|
72154
|
+
{ status: 500 }
|
|
72155
|
+
);
|
|
72156
|
+
}
|
|
72157
|
+
const limitParam = Number.parseInt(url.searchParams.get("limit") ?? "", 10);
|
|
72158
|
+
const offsetParam = Number.parseInt(url.searchParams.get("offset") ?? "", 10);
|
|
72159
|
+
const result = await agentBuilder.listUserValues(authResult.user.id, {
|
|
72160
|
+
prefix: url.searchParams.get("prefix"),
|
|
72161
|
+
limit: Number.isFinite(limitParam) ? limitParam : void 0,
|
|
72162
|
+
offset: Number.isFinite(offsetParam) ? offsetParam : void 0
|
|
72163
|
+
});
|
|
72164
|
+
return Response.json(result);
|
|
72165
|
+
} catch (error) {
|
|
72166
|
+
console.error("Get user kv error:", error);
|
|
72167
|
+
return Response.json(
|
|
72168
|
+
{ error: error.message || "Failed to read user values" },
|
|
72169
|
+
{ status: 500 }
|
|
72170
|
+
);
|
|
72171
|
+
}
|
|
72172
|
+
});
|
|
72173
|
+
|
|
72174
|
+
// src/api/users/me/kv/index.post.ts
|
|
72175
|
+
var index_post_default8 = defineController2(async ({ req, env: env2 }) => {
|
|
72176
|
+
try {
|
|
72177
|
+
const authResult = await requireAuth(req, env2);
|
|
72178
|
+
if (authResult instanceof Response) {
|
|
72179
|
+
return authResult;
|
|
72180
|
+
}
|
|
72181
|
+
if (authResult.authType === "super_admin") {
|
|
72182
|
+
return Response.json(
|
|
72183
|
+
{ error: "Super admin sessions do not have per-user storage. Sign in as a user account." },
|
|
72184
|
+
{ status: 400 }
|
|
72185
|
+
);
|
|
72186
|
+
}
|
|
72187
|
+
let body;
|
|
72188
|
+
try {
|
|
72189
|
+
const parsed = await req.json();
|
|
72190
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
72191
|
+
return Response.json({ error: "JSON object body required" }, { status: 400 });
|
|
72192
|
+
}
|
|
72193
|
+
body = parsed;
|
|
72194
|
+
} catch {
|
|
72195
|
+
return Response.json({ error: "Invalid JSON body" }, { status: 400 });
|
|
72196
|
+
}
|
|
72197
|
+
const key = body.key;
|
|
72198
|
+
if (typeof key !== "string" || key.length === 0) {
|
|
72199
|
+
return Response.json({ error: "key required" }, { status: 400 });
|
|
72200
|
+
}
|
|
72201
|
+
const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
|
|
72202
|
+
const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
72203
|
+
if (typeof agentBuilder.setUserValue !== "function") {
|
|
72204
|
+
return Response.json(
|
|
72205
|
+
{ error: "User value storage is not supported by this runtime" },
|
|
72206
|
+
{ status: 500 }
|
|
72207
|
+
);
|
|
72208
|
+
}
|
|
72209
|
+
await agentBuilder.setUserValue(authResult.user.id, key, body.value ?? null);
|
|
72210
|
+
return Response.json({ status: "ok", key });
|
|
72211
|
+
} catch (error) {
|
|
72212
|
+
console.error("Set user kv error:", error);
|
|
72213
|
+
return Response.json(
|
|
72214
|
+
{ error: error.message || "Failed to write user value" },
|
|
72215
|
+
{ status: 500 }
|
|
72216
|
+
);
|
|
72217
|
+
}
|
|
72218
|
+
});
|
|
72219
|
+
|
|
72034
72220
|
// src/api/auth/device/[code]/approve.get.ts
|
|
72035
72221
|
function page(title, body, ok) {
|
|
72036
72222
|
return new Response(
|
|
@@ -73256,6 +73442,9 @@ var routeHandlers = {
|
|
|
73256
73442
|
"GET:/auth/sa/start": start_get_default,
|
|
73257
73443
|
"GET:/users/me/env": env_get_default2,
|
|
73258
73444
|
"PATCH:/users/me/env": env_patch_default2,
|
|
73445
|
+
"DELETE:/users/me/kv": index_delete_default,
|
|
73446
|
+
"GET:/users/me/kv": index_get_default4,
|
|
73447
|
+
"POST:/users/me/kv": index_post_default8,
|
|
73259
73448
|
"GET:/auth/device/:code/approve": approve_get_default,
|
|
73260
73449
|
"GET:/skills/:name/files/**": path_get_default,
|
|
73261
73450
|
"DELETE:/threads/:id/fs/**": path_default3,
|