@standardagents/builder 0.27.1 → 0.27.3
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 +18 -1
- package/dist/built-in-routes.js.map +1 -1
- package/dist/{index-DJ7B8CTp.d.ts → index-DReIS8eP.d.ts} +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +142 -10
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.js +142 -10
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +5 -5
|
@@ -262,6 +262,7 @@ interface ThreadInstance {
|
|
|
262
262
|
hooks(): HookRegistry;
|
|
263
263
|
getValue<T = unknown>(key: string): Promise<T | null>;
|
|
264
264
|
setValue(key: string, value: unknown): Promise<void>;
|
|
265
|
+
emitThreadEvent?(threadId: string, event: string, data: unknown): void | Promise<void>;
|
|
265
266
|
callClientTool?(request: ClientToolRequest): Promise<ClientToolResponse>;
|
|
266
267
|
registerCodeExecutionBridge?(runId: string, bridge: {
|
|
267
268
|
call(functionId: string, encodedArgs: unknown[]): Promise<unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModelDefinition, AgentDefinition } from './runtime.js';
|
|
2
2
|
export { AgentBuilderEnv, AuthContext, AuthUser, BroadcastOptions, CodeExecutionBridge, DurableAgentBuilder, DurableThread, FlowStateSdk, FlowStateWithSdk, ImageContextConfig, InjectMessageOptions, LLMProviderInterface, NamespaceResolutionError, PromptContent, PromptDefinition, PromptIncludePart, PromptPart, PromptToolConfig, Provider, ProviderContentPart, ProviderFilePart, ProviderImagePart, ProviderRegistry, ProviderTextPart, SessionToolBinding, SessionToolConfig, SideConfig, SubagentToolConfig, SubpromptConfig, ThreadRegistryEntry, ThreadWatchdog, ThreadWatchdogState, ToolConfig, UpdateThreadParams, User, WatchdogCheckin, WatchdogProbeResult, authenticate, buildImageDescription, cat, createNamespaceContext, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isQualifiedName, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage } from './runtime.js';
|
|
3
3
|
export { AgentPluginOptions, agentbuilder, builder } from './plugin.js';
|
|
4
|
-
export { A as Agent, m as AttachmentRef, f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, E as Env, l as FileRecord, n as FileStats, j as FlowResult, F as FlowState, G as GrepResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, r as MessageContent, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, g as ThreadInstance, h as ThreadMetadata, T as ToolCall, i as ToolResult, c as createThreadEndpointHandler, d as defineController } from './index-
|
|
4
|
+
export { A as Agent, m as AttachmentRef, f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, E as Env, l as FileRecord, n as FileStats, j as FlowResult, F as FlowState, G as GrepResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, r as MessageContent, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, g as ThreadInstance, h as ThreadMetadata, T as ToolCall, i as ToolResult, c as createThreadEndpointHandler, d as defineController } from './index-DReIS8eP.js';
|
|
5
5
|
export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderConfigSlot, ProviderConfigSlots, ProviderConfigValueSource, ProviderDefinition, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ProviderMethodOverrides, ModelCapabilities as ProviderModelCapabilities, ProviderOverride, ProviderOverrideContext, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSyncOverride, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineProvider, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue } from '@standardagents/spec';
|
|
6
6
|
export { C as ConstituentItem, D as DiscoveredPackage, N as NamespacedRegistry, P as PackingAnalysis, a as PackingOptions, b as PackingResult, c as UnpackOptions, d as UnpackResult } from './types-Bpe7IANZ.js';
|
|
7
7
|
export { D as DiscoveryConfig, P as PackageDiscoveryService, d as discoverPackages } from './discovery-DiMJWisl.js';
|
package/dist/index.js
CHANGED
|
@@ -12703,6 +12703,7 @@ var init_ThreadStateImpl = __esm({
|
|
|
12703
12703
|
_executionState = null;
|
|
12704
12704
|
_childrenCache = [];
|
|
12705
12705
|
_terminatedCache = null;
|
|
12706
|
+
_pendingEventDeliveries = /* @__PURE__ */ new Set();
|
|
12706
12707
|
constructor(flowState, threadInstance, metadata, runtimeContext = {}) {
|
|
12707
12708
|
this._flowState = flowState;
|
|
12708
12709
|
this._threadInstance = threadInstance;
|
|
@@ -13154,6 +13155,22 @@ var init_ThreadStateImpl = __esm({
|
|
|
13154
13155
|
emit(event, data) {
|
|
13155
13156
|
if (this._flowState?.emitEvent) {
|
|
13156
13157
|
this._flowState.emitEvent(event, data);
|
|
13158
|
+
return;
|
|
13159
|
+
}
|
|
13160
|
+
if (this._threadInstance.emitThreadEvent) {
|
|
13161
|
+
const delivery = this._threadInstance.emitThreadEvent(this.threadId, event, data);
|
|
13162
|
+
if (delivery && typeof delivery.then === "function") {
|
|
13163
|
+
const pending = Promise.resolve(delivery).catch((error) => {
|
|
13164
|
+
console.error(`[ThreadState] Custom event "${event}" delivery failed:`, error);
|
|
13165
|
+
}).finally(() => this._pendingEventDeliveries.delete(pending));
|
|
13166
|
+
this._pendingEventDeliveries.add(pending);
|
|
13167
|
+
}
|
|
13168
|
+
}
|
|
13169
|
+
}
|
|
13170
|
+
/** Runtime-only drain used by thread endpoint wrappers before responding. */
|
|
13171
|
+
async flushPendingEventDeliveries() {
|
|
13172
|
+
while (this._pendingEventDeliveries.size > 0) {
|
|
13173
|
+
await Promise.all([...this._pendingEventDeliveries]);
|
|
13157
13174
|
}
|
|
13158
13175
|
}
|
|
13159
13176
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -22230,7 +22247,9 @@ function createThreadEndpointHandler(handler) {
|
|
|
22230
22247
|
}
|
|
22231
22248
|
endpointParams[key === "_" ? "*" : key] = value;
|
|
22232
22249
|
}
|
|
22233
|
-
|
|
22250
|
+
const response = await handler(req, threadState, endpointParams);
|
|
22251
|
+
await threadState.flushPendingEventDeliveries();
|
|
22252
|
+
return response;
|
|
22234
22253
|
} catch (error) {
|
|
22235
22254
|
console.error(`Error in thread endpoint for ${threadId}:`, error);
|
|
22236
22255
|
return Response.json(
|
|
@@ -25587,9 +25606,9 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
25587
25606
|
* Each migration is run in order, starting from the current version + 1.
|
|
25588
25607
|
*/
|
|
25589
25608
|
async runMigrations(fromVersion) {
|
|
25590
|
-
for (const
|
|
25591
|
-
if (
|
|
25592
|
-
await
|
|
25609
|
+
for (const migration47 of migrations) {
|
|
25610
|
+
if (migration47.version > fromVersion) {
|
|
25611
|
+
await migration47.up(this.ctx.storage.sql);
|
|
25593
25612
|
}
|
|
25594
25613
|
}
|
|
25595
25614
|
}
|
|
@@ -28341,6 +28360,9 @@ ${resultContent}${attachmentSummary}`;
|
|
|
28341
28360
|
* Broadcast a custom event to all connected message WebSocket clients
|
|
28342
28361
|
* Used by tools via emitThreadEvent() to send user-defined events
|
|
28343
28362
|
*/
|
|
28363
|
+
emitThreadEvent(_threadId, type, data) {
|
|
28364
|
+
this.broadcastEvent(type, data);
|
|
28365
|
+
}
|
|
28344
28366
|
broadcastEvent(type, data) {
|
|
28345
28367
|
const payload = JSON.stringify({
|
|
28346
28368
|
type: "event",
|
|
@@ -30291,9 +30313,119 @@ var migration45 = {
|
|
|
30291
30313
|
}
|
|
30292
30314
|
};
|
|
30293
30315
|
|
|
30316
|
+
// src/durable-objects/agentbuilder-migrations/0012_allow_api_instance_role.ts
|
|
30317
|
+
var migration46 = {
|
|
30318
|
+
version: 12,
|
|
30319
|
+
async up(sql) {
|
|
30320
|
+
sql.exec(`CREATE TABLE oauth_accounts_0012_backup AS SELECT * FROM oauth_accounts`);
|
|
30321
|
+
sql.exec(`CREATE TABLE api_keys_0012_backup AS SELECT * FROM api_keys`);
|
|
30322
|
+
sql.exec(`CREATE TABLE sessions_0012_backup AS SELECT * FROM sessions`);
|
|
30323
|
+
sql.exec(`DROP TABLE oauth_accounts`);
|
|
30324
|
+
sql.exec(`DROP TABLE api_keys`);
|
|
30325
|
+
sql.exec(`DROP TABLE sessions`);
|
|
30326
|
+
sql.exec(`ALTER TABLE users RENAME TO users_0012_old`);
|
|
30327
|
+
sql.exec(`
|
|
30328
|
+
CREATE TABLE users (
|
|
30329
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
30330
|
+
username TEXT UNIQUE NOT NULL,
|
|
30331
|
+
password_hash TEXT NOT NULL,
|
|
30332
|
+
role TEXT NOT NULL DEFAULT 'admin' CHECK (role IN ('admin')),
|
|
30333
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
30334
|
+
updated_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
30335
|
+
platform_user_id TEXT,
|
|
30336
|
+
email TEXT,
|
|
30337
|
+
display_name TEXT,
|
|
30338
|
+
avatar_url TEXT,
|
|
30339
|
+
instance_role TEXT NOT NULL DEFAULT 'admin' CHECK (instance_role IN ('admin', 'user', 'api')),
|
|
30340
|
+
source TEXT NOT NULL DEFAULT 'local' CHECK (source IN ('local', 'standard_agents')),
|
|
30341
|
+
replica_active INTEGER NOT NULL DEFAULT 1,
|
|
30342
|
+
replica_updated_at INTEGER,
|
|
30343
|
+
deleted_at INTEGER,
|
|
30344
|
+
permissions TEXT
|
|
30345
|
+
)
|
|
30346
|
+
`);
|
|
30347
|
+
sql.exec(`
|
|
30348
|
+
INSERT INTO users (
|
|
30349
|
+
id, username, password_hash, role, created_at, updated_at,
|
|
30350
|
+
platform_user_id, email, display_name, avatar_url, instance_role,
|
|
30351
|
+
source, replica_active, replica_updated_at, deleted_at, permissions
|
|
30352
|
+
)
|
|
30353
|
+
SELECT
|
|
30354
|
+
id, username, password_hash, role, created_at, updated_at,
|
|
30355
|
+
platform_user_id, email, display_name, avatar_url, instance_role,
|
|
30356
|
+
source, replica_active, replica_updated_at, deleted_at, permissions
|
|
30357
|
+
FROM users_0012_old
|
|
30358
|
+
`);
|
|
30359
|
+
sql.exec(`DROP TABLE users_0012_old`);
|
|
30360
|
+
sql.exec(`CREATE INDEX idx_users_username ON users(username)`);
|
|
30361
|
+
sql.exec(`CREATE INDEX idx_users_role ON users(role)`);
|
|
30362
|
+
sql.exec(`CREATE INDEX idx_users_platform_user_id ON users(platform_user_id)`);
|
|
30363
|
+
sql.exec(`CREATE INDEX idx_users_replica_active ON users(replica_active)`);
|
|
30364
|
+
sql.exec(`CREATE INDEX idx_users_instance_role ON users(instance_role)`);
|
|
30365
|
+
sql.exec(`
|
|
30366
|
+
CREATE TABLE oauth_accounts (
|
|
30367
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
30368
|
+
user_id TEXT NOT NULL,
|
|
30369
|
+
provider TEXT NOT NULL CHECK (provider IN ('github', 'google')),
|
|
30370
|
+
provider_user_id TEXT NOT NULL,
|
|
30371
|
+
provider_username TEXT,
|
|
30372
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
30373
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
30374
|
+
)
|
|
30375
|
+
`);
|
|
30376
|
+
sql.exec(`INSERT INTO oauth_accounts SELECT * FROM oauth_accounts_0012_backup`);
|
|
30377
|
+
sql.exec(`CREATE UNIQUE INDEX idx_oauth_accounts_provider ON oauth_accounts(provider, provider_user_id)`);
|
|
30378
|
+
sql.exec(`CREATE INDEX idx_oauth_accounts_user_id ON oauth_accounts(user_id)`);
|
|
30379
|
+
sql.exec(`
|
|
30380
|
+
CREATE TABLE api_keys (
|
|
30381
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
30382
|
+
name TEXT NOT NULL,
|
|
30383
|
+
key_hash TEXT NOT NULL,
|
|
30384
|
+
key_prefix TEXT NOT NULL,
|
|
30385
|
+
last_five TEXT NOT NULL,
|
|
30386
|
+
user_id TEXT NOT NULL,
|
|
30387
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
30388
|
+
last_used_at INTEGER,
|
|
30389
|
+
platform_key_id TEXT,
|
|
30390
|
+
scope TEXT,
|
|
30391
|
+
source TEXT NOT NULL DEFAULT 'local' CHECK (source IN ('local', 'standard_agents')),
|
|
30392
|
+
replica_active INTEGER NOT NULL DEFAULT 1,
|
|
30393
|
+
replica_updated_at INTEGER,
|
|
30394
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
30395
|
+
)
|
|
30396
|
+
`);
|
|
30397
|
+
sql.exec(`INSERT INTO api_keys SELECT * FROM api_keys_0012_backup`);
|
|
30398
|
+
sql.exec(`CREATE INDEX idx_api_keys_key_hash ON api_keys(key_hash)`);
|
|
30399
|
+
sql.exec(`CREATE INDEX idx_api_keys_user_id ON api_keys(user_id)`);
|
|
30400
|
+
sql.exec(`CREATE INDEX idx_api_keys_key_prefix ON api_keys(key_prefix)`);
|
|
30401
|
+
sql.exec(`CREATE INDEX idx_api_keys_platform_key_id ON api_keys(platform_key_id)`);
|
|
30402
|
+
sql.exec(`CREATE INDEX idx_api_keys_replica_active ON api_keys(replica_active)`);
|
|
30403
|
+
sql.exec(`
|
|
30404
|
+
CREATE TABLE sessions (
|
|
30405
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
30406
|
+
user_id TEXT NOT NULL,
|
|
30407
|
+
token_hash TEXT NOT NULL,
|
|
30408
|
+
expires_at INTEGER NOT NULL,
|
|
30409
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now')),
|
|
30410
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
30411
|
+
)
|
|
30412
|
+
`);
|
|
30413
|
+
sql.exec(`INSERT INTO sessions SELECT * FROM sessions_0012_backup`);
|
|
30414
|
+
sql.exec(`CREATE INDEX idx_sessions_token_hash ON sessions(token_hash)`);
|
|
30415
|
+
sql.exec(`CREATE INDEX idx_sessions_user_id ON sessions(user_id)`);
|
|
30416
|
+
sql.exec(`CREATE INDEX idx_sessions_expires_at ON sessions(expires_at)`);
|
|
30417
|
+
sql.exec(`DROP TABLE oauth_accounts_0012_backup`);
|
|
30418
|
+
sql.exec(`DROP TABLE api_keys_0012_backup`);
|
|
30419
|
+
sql.exec(`DROP TABLE sessions_0012_backup`);
|
|
30420
|
+
sql.exec(`
|
|
30421
|
+
INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '12')
|
|
30422
|
+
`);
|
|
30423
|
+
}
|
|
30424
|
+
};
|
|
30425
|
+
|
|
30294
30426
|
// src/durable-objects/agentbuilder-migrations/index.ts
|
|
30295
|
-
var migrations2 = [migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42, migration43, migration44, migration45];
|
|
30296
|
-
var LATEST_SCHEMA_VERSION2 =
|
|
30427
|
+
var migrations2 = [migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42, migration43, migration44, migration45, migration46];
|
|
30428
|
+
var LATEST_SCHEMA_VERSION2 = 12;
|
|
30297
30429
|
|
|
30298
30430
|
// src/utils/crypto.ts
|
|
30299
30431
|
var CryptoUtil = class {
|
|
@@ -31055,9 +31187,9 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
31055
31187
|
}
|
|
31056
31188
|
}
|
|
31057
31189
|
async runMigrations(fromVersion) {
|
|
31058
|
-
for (const
|
|
31059
|
-
if (
|
|
31060
|
-
await
|
|
31190
|
+
for (const migration47 of migrations2) {
|
|
31191
|
+
if (migration47.version > fromVersion) {
|
|
31192
|
+
await migration47.up(this.ctx.storage.sql);
|
|
31061
31193
|
}
|
|
31062
31194
|
}
|
|
31063
31195
|
}
|
|
@@ -32412,7 +32544,7 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
32412
32544
|
return cursor.toArray().map((row) => ({
|
|
32413
32545
|
id: row.id,
|
|
32414
32546
|
username: row.username,
|
|
32415
|
-
role: row.role === "user" ? "user" : "admin",
|
|
32547
|
+
role: row.role === "user" ? "user" : row.role === "api" ? "api" : "admin",
|
|
32416
32548
|
platform_user_id: row.platform_user_id ?? null,
|
|
32417
32549
|
email: row.email ?? null,
|
|
32418
32550
|
display_name: row.display_name ?? null,
|