@standardagents/builder 0.41.6 → 0.41.7
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 +143 -3
- package/dist/built-in-routes.js.map +1 -1
- package/dist/{index-By8TkPrK.d.ts → index-PSu6cMEz.d.ts} +3 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +124 -10
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +4 -2
- package/dist/runtime.js +124 -10
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +5 -5
package/dist/runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { j as AuthContext, e as ThreadEnv, w as Agent, y as ThreadMetadata, z as ToolResult, M as Message, o as ClientToolRequest, p as ClientToolResponse, V as ProxyStreamReceiver, W as ProxyStreamFrame, q as ClientStreamRequest, X as ProxyStreamTarget, t as ClientStreamResponse, Y as ProxyStreamOpenResult, H as FileRecord, Z as SkillStorageScope, F as FlowState, N as FileStats, K as GrepResult, J as AttachmentRef, U as MessageContent, G as Env, x as ThreadInstance } from './index-
|
|
2
|
-
export { A as AuthUser, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, u as ClientDuplex, v as ClientForwarding, B as Controller, a as ControllerContext, D as FlowResult, P as ImageContentPart, I as ImageMetadata, L as LLMResponse, Q as MultimodalContent, R as RequestContext, S as StorageBackend, E as TelemetryEvent, O as TextContentPart, b as ThreadEndpointContext, T as ToolCall, g as authenticate, k as callClient, l as callClientStream, c as createThreadEndpointHandler, n as decodeStreamChunk, d as defineController, m as encodeStreamChunk, i as endpointCallerFromAuth, h as requireAdmin, r as requireAuth, s as supportsClientForwarding } from './index-
|
|
1
|
+
import { j as AuthContext, e as ThreadEnv, w as Agent, y as ThreadMetadata, z as ToolResult, M as Message, o as ClientToolRequest, p as ClientToolResponse, V as ProxyStreamReceiver, W as ProxyStreamFrame, q as ClientStreamRequest, X as ProxyStreamTarget, t as ClientStreamResponse, Y as ProxyStreamOpenResult, H as FileRecord, Z as SkillStorageScope, F as FlowState, N as FileStats, K as GrepResult, J as AttachmentRef, U as MessageContent, G as Env, x as ThreadInstance } from './index-PSu6cMEz.js';
|
|
2
|
+
export { A as AuthUser, f as BuilderThreadEndpointHandler, C as CLIENT_STREAM_CHUNK_BYTES, u as ClientDuplex, v as ClientForwarding, B as Controller, a as ControllerContext, D as FlowResult, P as ImageContentPart, I as ImageMetadata, L as LLMResponse, Q as MultimodalContent, R as RequestContext, S as StorageBackend, E as TelemetryEvent, O as TextContentPart, b as ThreadEndpointContext, T as ToolCall, g as authenticate, k as callClient, l as callClientStream, c as createThreadEndpointHandler, n as decodeStreamChunk, d as defineController, m as encodeStreamChunk, i as endpointCallerFromAuth, h as requireAdmin, r as requireAuth, s as supportsClientForwarding } from './index-PSu6cMEz.js';
|
|
3
3
|
import { CodeExecutionOptions, CodeExecutionResult, SubagentRegistryEntry, InjectMessageInput, QueueMessageInput, CredentialGrant, SkillMetadata, SkillFileInput, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, PromptEnvPart, VariableDefinition, SubpromptConfig as SubpromptConfig$1, PromptToolConfig as PromptToolConfig$1, ReasoningConfig, HumanSide as HumanSide$1, SubagentRelationship as SubagentRelationship$1, ParentHookRequirement, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart, ThreadState, NamespaceContext, DefinitionLoader } from '@standardagents/spec';
|
|
4
4
|
export { AgentType, DefineHandlerOptions, DefinitionLoader, GlobalNamespaceContext, HANDLER_SYMBOL, HandlerDefinition, HookExecutionContext, HookExecutionSource, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, ParentHookRequirement, ParentHookStage, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ModelCapabilities as ProviderModelCapabilities, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, ThreadHookName, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHandler, defineHook, defineModel, definePrompt, defineProvider, defineTool, isHandler, isPacked, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue } from '@standardagents/spec';
|
|
5
5
|
import { DurableObject, WorkerEntrypoint } from 'cloudflare:workers';
|
|
@@ -1888,6 +1888,8 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1888
1888
|
}
|
|
1889
1889
|
|
|
1890
1890
|
interface DurableUserHubEnv {
|
|
1891
|
+
/** Secret JSON registry of runtime-managed grants shared by all users. */
|
|
1892
|
+
AGENT_BUILDER_CREDENTIAL_GRANTS?: string;
|
|
1891
1893
|
[key: string]: unknown;
|
|
1892
1894
|
}
|
|
1893
1895
|
interface HubClientInfo {
|
package/dist/runtime.js
CHANGED
|
@@ -30561,6 +30561,105 @@ function createExecutionChain() {
|
|
|
30561
30561
|
}
|
|
30562
30562
|
|
|
30563
30563
|
// src/users/grants.ts
|
|
30564
|
+
var INSTANCE_GRANTS_MAX_BYTES = 64 * 1024;
|
|
30565
|
+
var INSTANCE_GRANTS_MAX_COUNT = 64;
|
|
30566
|
+
var GRANT_NAME = /^[a-z0-9][a-z0-9._-]{0,127}$/;
|
|
30567
|
+
var HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
30568
|
+
var QUERY_NAME = /^[A-Za-z0-9._~-]{1,128}$/;
|
|
30569
|
+
var SUPPORTED_KINDS = /* @__PURE__ */ new Set(["bearer", "header", "query", "basic"]);
|
|
30570
|
+
var RECORD_KEYS = /* @__PURE__ */ new Set(["name", "kind", "origins", "inject", "allow", "metadata", "secret"]);
|
|
30571
|
+
var ALLOW_KEYS = /* @__PURE__ */ new Set(["tools", "endpoints", "userEndpoints", "agents"]);
|
|
30572
|
+
var INJECT_KEYS = /* @__PURE__ */ new Set(["header", "format", "query"]);
|
|
30573
|
+
function parseInstanceCredentialGrants(value) {
|
|
30574
|
+
const records = /* @__PURE__ */ new Map();
|
|
30575
|
+
if (typeof value !== "string" || value.length === 0 || value.length > INSTANCE_GRANTS_MAX_BYTES) {
|
|
30576
|
+
return records;
|
|
30577
|
+
}
|
|
30578
|
+
let parsed;
|
|
30579
|
+
try {
|
|
30580
|
+
parsed = JSON.parse(value);
|
|
30581
|
+
} catch {
|
|
30582
|
+
return records;
|
|
30583
|
+
}
|
|
30584
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return records;
|
|
30585
|
+
const envelope = parsed;
|
|
30586
|
+
if (envelope.version !== 1 || !Array.isArray(envelope.grants) || envelope.grants.length > INSTANCE_GRANTS_MAX_COUNT) {
|
|
30587
|
+
return records;
|
|
30588
|
+
}
|
|
30589
|
+
for (const candidate of envelope.grants) {
|
|
30590
|
+
const record = validateCredentialGrantRecord(candidate);
|
|
30591
|
+
if (!record || records.has(record.grant.name)) return /* @__PURE__ */ new Map();
|
|
30592
|
+
records.set(record.grant.name, record);
|
|
30593
|
+
}
|
|
30594
|
+
return records;
|
|
30595
|
+
}
|
|
30596
|
+
function validateCredentialGrantRecord(value, routeName) {
|
|
30597
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
30598
|
+
const input = value;
|
|
30599
|
+
if (Object.keys(input).some((key) => !RECORD_KEYS.has(key))) return null;
|
|
30600
|
+
const name = input.name;
|
|
30601
|
+
if (typeof name !== "string" || !GRANT_NAME.test(name)) return null;
|
|
30602
|
+
if (input.name !== void 0 && input.name !== name) return null;
|
|
30603
|
+
if (typeof input.secret !== "string" || input.secret.length === 0 || input.secret.length > 16 * 1024) return null;
|
|
30604
|
+
if (typeof input.kind !== "string" || !SUPPORTED_KINDS.has(input.kind)) return null;
|
|
30605
|
+
if ((input.kind === "bearer" || input.kind === "header") && /[\r\n]/.test(input.secret)) return null;
|
|
30606
|
+
if (!Array.isArray(input.origins) || input.origins.length === 0 || input.origins.length > 64) return null;
|
|
30607
|
+
const origins = [];
|
|
30608
|
+
for (const origin of input.origins) {
|
|
30609
|
+
if (typeof origin !== "string" || origin.length > 512) return null;
|
|
30610
|
+
if (origin.startsWith("*.")) {
|
|
30611
|
+
if (!/^\*\.[a-z0-9.-]+$/i.test(origin)) return null;
|
|
30612
|
+
} else {
|
|
30613
|
+
try {
|
|
30614
|
+
const url = new URL(origin);
|
|
30615
|
+
if (url.origin !== origin || url.protocol !== "https:" || url.username || url.password) return null;
|
|
30616
|
+
} catch {
|
|
30617
|
+
return null;
|
|
30618
|
+
}
|
|
30619
|
+
}
|
|
30620
|
+
origins.push(origin);
|
|
30621
|
+
}
|
|
30622
|
+
if (!input.allow || typeof input.allow !== "object" || Array.isArray(input.allow)) return null;
|
|
30623
|
+
const allowInput = input.allow;
|
|
30624
|
+
if (Object.keys(allowInput).some((key) => !ALLOW_KEYS.has(key))) return null;
|
|
30625
|
+
const allow = {};
|
|
30626
|
+
for (const key of ["tools", "endpoints", "userEndpoints", "agents"]) {
|
|
30627
|
+
const list = allowInput[key];
|
|
30628
|
+
if (list === void 0) continue;
|
|
30629
|
+
if (!Array.isArray(list) || list.length > 128 || !list.every((item) => typeof item === "string" && item.length > 0 && item.length <= 256)) {
|
|
30630
|
+
return null;
|
|
30631
|
+
}
|
|
30632
|
+
allow[key] = [...list];
|
|
30633
|
+
}
|
|
30634
|
+
if (Object.keys(allow).length === 0) return null;
|
|
30635
|
+
const inject = input.inject;
|
|
30636
|
+
if (inject !== void 0 && (!inject || typeof inject !== "object" || Array.isArray(inject))) return null;
|
|
30637
|
+
if (inject !== void 0) {
|
|
30638
|
+
const injection = inject;
|
|
30639
|
+
if (Object.keys(injection).some((key) => !INJECT_KEYS.has(key))) return null;
|
|
30640
|
+
if (injection.header !== void 0 && (typeof injection.header !== "string" || !HEADER_NAME.test(injection.header))) return null;
|
|
30641
|
+
if (injection.format !== void 0 && (typeof injection.format !== "string" || injection.format.length > 1024 || /[\r\n]/.test(injection.format))) return null;
|
|
30642
|
+
if (injection.query !== void 0 && (typeof injection.query !== "string" || !QUERY_NAME.test(injection.query))) return null;
|
|
30643
|
+
}
|
|
30644
|
+
const metadata = input.metadata;
|
|
30645
|
+
if (metadata !== void 0 && (!metadata || typeof metadata !== "object" || Array.isArray(metadata))) return null;
|
|
30646
|
+
if (metadata !== void 0) {
|
|
30647
|
+
try {
|
|
30648
|
+
if (JSON.stringify(metadata).length > 16 * 1024) return null;
|
|
30649
|
+
} catch {
|
|
30650
|
+
return null;
|
|
30651
|
+
}
|
|
30652
|
+
}
|
|
30653
|
+
const grant = {
|
|
30654
|
+
name,
|
|
30655
|
+
kind: input.kind,
|
|
30656
|
+
origins,
|
|
30657
|
+
allow,
|
|
30658
|
+
...inject === void 0 ? {} : { inject },
|
|
30659
|
+
...metadata === void 0 ? {} : { metadata }
|
|
30660
|
+
};
|
|
30661
|
+
return { grant, secret: input.secret };
|
|
30662
|
+
}
|
|
30564
30663
|
function originAllowed(origins, target) {
|
|
30565
30664
|
if (!Array.isArray(origins)) return false;
|
|
30566
30665
|
for (const allowed of origins) {
|
|
@@ -30906,14 +31005,20 @@ var DurableUserHub = class extends DurableObject {
|
|
|
30906
31005
|
`SELECT name, config FROM user_grants WHERE user_id = ? ORDER BY name ASC`,
|
|
30907
31006
|
userId
|
|
30908
31007
|
);
|
|
30909
|
-
|
|
31008
|
+
const grants = /* @__PURE__ */ new Map();
|
|
31009
|
+
for (const record of parseInstanceCredentialGrants(this.env.AGENT_BUILDER_CREDENTIAL_GRANTS).values()) {
|
|
31010
|
+
const { name, ...config } = record.grant;
|
|
31011
|
+
grants.set(name, { name, ...config });
|
|
31012
|
+
}
|
|
31013
|
+
for (const row of cursor.toArray()) {
|
|
30910
31014
|
let config = {};
|
|
30911
31015
|
try {
|
|
30912
31016
|
config = JSON.parse(row.config);
|
|
30913
31017
|
} catch {
|
|
30914
31018
|
}
|
|
30915
|
-
|
|
30916
|
-
}
|
|
31019
|
+
grants.set(row.name, { name: row.name, ...config });
|
|
31020
|
+
}
|
|
31021
|
+
return [...grants.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
30917
31022
|
}
|
|
30918
31023
|
/** Perform a privileged fetch with the grant's credential injected. */
|
|
30919
31024
|
async grantFetch(userId, grantName, req) {
|
|
@@ -30923,15 +31028,24 @@ var DurableUserHub = class extends DurableObject {
|
|
|
30923
31028
|
userId,
|
|
30924
31029
|
grantName
|
|
30925
31030
|
);
|
|
30926
|
-
const
|
|
30927
|
-
|
|
31031
|
+
const stored = cursor.toArray()[0];
|
|
31032
|
+
const instance = stored ? null : parseInstanceCredentialGrants(this.env.AGENT_BUILDER_CREDENTIAL_GRANTS).get(grantName) ?? null;
|
|
31033
|
+
if (!stored && !instance) {
|
|
30928
31034
|
return Response.json({ error: "grant_not_found", grant: grantName }, { status: 404 });
|
|
30929
31035
|
}
|
|
30930
31036
|
let config;
|
|
30931
|
-
|
|
30932
|
-
|
|
30933
|
-
|
|
30934
|
-
|
|
31037
|
+
let secret;
|
|
31038
|
+
if (stored) {
|
|
31039
|
+
try {
|
|
31040
|
+
config = JSON.parse(stored.config);
|
|
31041
|
+
} catch {
|
|
31042
|
+
return Response.json({ error: "grant_config_invalid" }, { status: 500 });
|
|
31043
|
+
}
|
|
31044
|
+
secret = stored.secret;
|
|
31045
|
+
} else {
|
|
31046
|
+
const { name: _name, ...instanceConfig } = instance.grant;
|
|
31047
|
+
config = instanceConfig;
|
|
31048
|
+
secret = instance.secret;
|
|
30935
31049
|
}
|
|
30936
31050
|
let target;
|
|
30937
31051
|
try {
|
|
@@ -30946,7 +31060,7 @@ var DurableUserHub = class extends DurableObject {
|
|
|
30946
31060
|
return Response.json({ error: "grant_caller_denied" }, { status: 403 });
|
|
30947
31061
|
}
|
|
30948
31062
|
const headers = new Headers(req.headers);
|
|
30949
|
-
if (!injectGrantCredential(config,
|
|
31063
|
+
if (!injectGrantCredential(config, secret, target, headers)) {
|
|
30950
31064
|
return Response.json({ error: "grant_kind_unsupported" }, { status: 501 });
|
|
30951
31065
|
}
|
|
30952
31066
|
try {
|