@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/runtime.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { e as ThreadEnv, A as Agent, h as ThreadMetadata, i as ToolResult, M as Message, l as FileRecord, F as FlowState, n as FileStats, G as GrepResult, m as AttachmentRef, r as MessageContent, E as Env, g as ThreadInstance } from './index-DJ7B8CTp.js';
2
- export { f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, j as FlowResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, T as ToolCall, c as createThreadEndpointHandler, d as defineController } from './index-DJ7B8CTp.js';
1
+ import { e as ThreadEnv, A as Agent, h as ThreadMetadata, i as ToolResult, M as Message, l as FileRecord, F as FlowState, n as FileStats, G as GrepResult, m as AttachmentRef, r as MessageContent, E as Env, g as ThreadInstance } from './index-DReIS8eP.js';
2
+ export { f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, j as FlowResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, T as ToolCall, c as createThreadEndpointHandler, d as defineController } from './index-DReIS8eP.js';
3
3
  import { CodeExecutionOptions, CodeExecutionResult, SubagentRegistryEntry, InjectMessageInput, QueueMessageInput, ClientToolRequest, ClientToolResponse, SkillMetadata, SkillFileInput, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, PromptEnvPart, VariableDefinition, SubpromptConfig as SubpromptConfig$1, PromptToolConfig as PromptToolConfig$1, SubagentToolConfig as SubagentToolConfig$1, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart, NamespaceContext, DefinitionLoader } from '@standardagents/spec';
4
4
  export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, 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, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel } from '@standardagents/spec';
5
5
  import { DurableObject, WorkerEntrypoint } from 'cloudflare:workers';
@@ -1124,6 +1124,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
1124
1124
  * Broadcast a custom event to all connected message WebSocket clients
1125
1125
  * Used by tools via emitThreadEvent() to send user-defined events
1126
1126
  */
1127
+ emitThreadEvent(_threadId: string, type: string, data: unknown): void;
1127
1128
  private broadcastEvent;
1128
1129
  /**
1129
1130
  * WebSocket Hibernation API handler for incoming messages
package/dist/runtime.js CHANGED
@@ -12694,6 +12694,7 @@ var init_ThreadStateImpl = __esm({
12694
12694
  _executionState = null;
12695
12695
  _childrenCache = [];
12696
12696
  _terminatedCache = null;
12697
+ _pendingEventDeliveries = /* @__PURE__ */ new Set();
12697
12698
  constructor(flowState, threadInstance, metadata, runtimeContext = {}) {
12698
12699
  this._flowState = flowState;
12699
12700
  this._threadInstance = threadInstance;
@@ -13145,6 +13146,22 @@ var init_ThreadStateImpl = __esm({
13145
13146
  emit(event, data) {
13146
13147
  if (this._flowState?.emitEvent) {
13147
13148
  this._flowState.emitEvent(event, data);
13149
+ return;
13150
+ }
13151
+ if (this._threadInstance.emitThreadEvent) {
13152
+ const delivery = this._threadInstance.emitThreadEvent(this.threadId, event, data);
13153
+ if (delivery && typeof delivery.then === "function") {
13154
+ const pending = Promise.resolve(delivery).catch((error) => {
13155
+ console.error(`[ThreadState] Custom event "${event}" delivery failed:`, error);
13156
+ }).finally(() => this._pendingEventDeliveries.delete(pending));
13157
+ this._pendingEventDeliveries.add(pending);
13158
+ }
13159
+ }
13160
+ }
13161
+ /** Runtime-only drain used by thread endpoint wrappers before responding. */
13162
+ async flushPendingEventDeliveries() {
13163
+ while (this._pendingEventDeliveries.size > 0) {
13164
+ await Promise.all([...this._pendingEventDeliveries]);
13148
13165
  }
13149
13166
  }
13150
13167
  // ─────────────────────────────────────────────────────────────────────────
@@ -13915,7 +13932,9 @@ function createThreadEndpointHandler(handler) {
13915
13932
  }
13916
13933
  endpointParams[key === "_" ? "*" : key] = value;
13917
13934
  }
13918
- return await handler(req, threadState, endpointParams);
13935
+ const response = await handler(req, threadState, endpointParams);
13936
+ await threadState.flushPendingEventDeliveries();
13937
+ return response;
13919
13938
  } catch (error) {
13920
13939
  console.error(`Error in thread endpoint for ${threadId}:`, error);
13921
13940
  return Response.json(
@@ -17272,9 +17291,9 @@ var DurableThread = class _DurableThread extends DurableObject {
17272
17291
  * Each migration is run in order, starting from the current version + 1.
17273
17292
  */
17274
17293
  async runMigrations(fromVersion) {
17275
- for (const migration46 of migrations) {
17276
- if (migration46.version > fromVersion) {
17277
- await migration46.up(this.ctx.storage.sql);
17294
+ for (const migration47 of migrations) {
17295
+ if (migration47.version > fromVersion) {
17296
+ await migration47.up(this.ctx.storage.sql);
17278
17297
  }
17279
17298
  }
17280
17299
  }
@@ -20026,6 +20045,9 @@ ${resultContent}${attachmentSummary}`;
20026
20045
  * Broadcast a custom event to all connected message WebSocket clients
20027
20046
  * Used by tools via emitThreadEvent() to send user-defined events
20028
20047
  */
20048
+ emitThreadEvent(_threadId, type, data) {
20049
+ this.broadcastEvent(type, data);
20050
+ }
20029
20051
  broadcastEvent(type, data) {
20030
20052
  const payload = JSON.stringify({
20031
20053
  type: "event",
@@ -21976,9 +21998,119 @@ var migration45 = {
21976
21998
  }
21977
21999
  };
21978
22000
 
22001
+ // src/durable-objects/agentbuilder-migrations/0012_allow_api_instance_role.ts
22002
+ var migration46 = {
22003
+ version: 12,
22004
+ async up(sql) {
22005
+ sql.exec(`CREATE TABLE oauth_accounts_0012_backup AS SELECT * FROM oauth_accounts`);
22006
+ sql.exec(`CREATE TABLE api_keys_0012_backup AS SELECT * FROM api_keys`);
22007
+ sql.exec(`CREATE TABLE sessions_0012_backup AS SELECT * FROM sessions`);
22008
+ sql.exec(`DROP TABLE oauth_accounts`);
22009
+ sql.exec(`DROP TABLE api_keys`);
22010
+ sql.exec(`DROP TABLE sessions`);
22011
+ sql.exec(`ALTER TABLE users RENAME TO users_0012_old`);
22012
+ sql.exec(`
22013
+ CREATE TABLE users (
22014
+ id TEXT PRIMARY KEY NOT NULL,
22015
+ username TEXT UNIQUE NOT NULL,
22016
+ password_hash TEXT NOT NULL,
22017
+ role TEXT NOT NULL DEFAULT 'admin' CHECK (role IN ('admin')),
22018
+ created_at INTEGER DEFAULT (strftime('%s', 'now')),
22019
+ updated_at INTEGER DEFAULT (strftime('%s', 'now')),
22020
+ platform_user_id TEXT,
22021
+ email TEXT,
22022
+ display_name TEXT,
22023
+ avatar_url TEXT,
22024
+ instance_role TEXT NOT NULL DEFAULT 'admin' CHECK (instance_role IN ('admin', 'user', 'api')),
22025
+ source TEXT NOT NULL DEFAULT 'local' CHECK (source IN ('local', 'standard_agents')),
22026
+ replica_active INTEGER NOT NULL DEFAULT 1,
22027
+ replica_updated_at INTEGER,
22028
+ deleted_at INTEGER,
22029
+ permissions TEXT
22030
+ )
22031
+ `);
22032
+ sql.exec(`
22033
+ INSERT INTO users (
22034
+ id, username, password_hash, role, created_at, updated_at,
22035
+ platform_user_id, email, display_name, avatar_url, instance_role,
22036
+ source, replica_active, replica_updated_at, deleted_at, permissions
22037
+ )
22038
+ SELECT
22039
+ id, username, password_hash, role, created_at, updated_at,
22040
+ platform_user_id, email, display_name, avatar_url, instance_role,
22041
+ source, replica_active, replica_updated_at, deleted_at, permissions
22042
+ FROM users_0012_old
22043
+ `);
22044
+ sql.exec(`DROP TABLE users_0012_old`);
22045
+ sql.exec(`CREATE INDEX idx_users_username ON users(username)`);
22046
+ sql.exec(`CREATE INDEX idx_users_role ON users(role)`);
22047
+ sql.exec(`CREATE INDEX idx_users_platform_user_id ON users(platform_user_id)`);
22048
+ sql.exec(`CREATE INDEX idx_users_replica_active ON users(replica_active)`);
22049
+ sql.exec(`CREATE INDEX idx_users_instance_role ON users(instance_role)`);
22050
+ sql.exec(`
22051
+ CREATE TABLE oauth_accounts (
22052
+ id TEXT PRIMARY KEY NOT NULL,
22053
+ user_id TEXT NOT NULL,
22054
+ provider TEXT NOT NULL CHECK (provider IN ('github', 'google')),
22055
+ provider_user_id TEXT NOT NULL,
22056
+ provider_username TEXT,
22057
+ created_at INTEGER DEFAULT (strftime('%s', 'now')),
22058
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
22059
+ )
22060
+ `);
22061
+ sql.exec(`INSERT INTO oauth_accounts SELECT * FROM oauth_accounts_0012_backup`);
22062
+ sql.exec(`CREATE UNIQUE INDEX idx_oauth_accounts_provider ON oauth_accounts(provider, provider_user_id)`);
22063
+ sql.exec(`CREATE INDEX idx_oauth_accounts_user_id ON oauth_accounts(user_id)`);
22064
+ sql.exec(`
22065
+ CREATE TABLE api_keys (
22066
+ id TEXT PRIMARY KEY NOT NULL,
22067
+ name TEXT NOT NULL,
22068
+ key_hash TEXT NOT NULL,
22069
+ key_prefix TEXT NOT NULL,
22070
+ last_five TEXT NOT NULL,
22071
+ user_id TEXT NOT NULL,
22072
+ created_at INTEGER DEFAULT (strftime('%s', 'now')),
22073
+ last_used_at INTEGER,
22074
+ platform_key_id TEXT,
22075
+ scope TEXT,
22076
+ source TEXT NOT NULL DEFAULT 'local' CHECK (source IN ('local', 'standard_agents')),
22077
+ replica_active INTEGER NOT NULL DEFAULT 1,
22078
+ replica_updated_at INTEGER,
22079
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
22080
+ )
22081
+ `);
22082
+ sql.exec(`INSERT INTO api_keys SELECT * FROM api_keys_0012_backup`);
22083
+ sql.exec(`CREATE INDEX idx_api_keys_key_hash ON api_keys(key_hash)`);
22084
+ sql.exec(`CREATE INDEX idx_api_keys_user_id ON api_keys(user_id)`);
22085
+ sql.exec(`CREATE INDEX idx_api_keys_key_prefix ON api_keys(key_prefix)`);
22086
+ sql.exec(`CREATE INDEX idx_api_keys_platform_key_id ON api_keys(platform_key_id)`);
22087
+ sql.exec(`CREATE INDEX idx_api_keys_replica_active ON api_keys(replica_active)`);
22088
+ sql.exec(`
22089
+ CREATE TABLE sessions (
22090
+ id TEXT PRIMARY KEY NOT NULL,
22091
+ user_id TEXT NOT NULL,
22092
+ token_hash TEXT NOT NULL,
22093
+ expires_at INTEGER NOT NULL,
22094
+ created_at INTEGER DEFAULT (strftime('%s', 'now')),
22095
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
22096
+ )
22097
+ `);
22098
+ sql.exec(`INSERT INTO sessions SELECT * FROM sessions_0012_backup`);
22099
+ sql.exec(`CREATE INDEX idx_sessions_token_hash ON sessions(token_hash)`);
22100
+ sql.exec(`CREATE INDEX idx_sessions_user_id ON sessions(user_id)`);
22101
+ sql.exec(`CREATE INDEX idx_sessions_expires_at ON sessions(expires_at)`);
22102
+ sql.exec(`DROP TABLE oauth_accounts_0012_backup`);
22103
+ sql.exec(`DROP TABLE api_keys_0012_backup`);
22104
+ sql.exec(`DROP TABLE sessions_0012_backup`);
22105
+ sql.exec(`
22106
+ INSERT OR REPLACE INTO _metadata (key, value) VALUES ('schema_version', '12')
22107
+ `);
22108
+ }
22109
+ };
22110
+
21979
22111
  // src/durable-objects/agentbuilder-migrations/index.ts
21980
- var migrations2 = [migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42, migration43, migration44, migration45];
21981
- var LATEST_SCHEMA_VERSION2 = 11;
22112
+ var migrations2 = [migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42, migration43, migration44, migration45, migration46];
22113
+ var LATEST_SCHEMA_VERSION2 = 12;
21982
22114
 
21983
22115
  // src/utils/crypto.ts
21984
22116
  var CryptoUtil = class {
@@ -22740,9 +22872,9 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
22740
22872
  }
22741
22873
  }
22742
22874
  async runMigrations(fromVersion) {
22743
- for (const migration46 of migrations2) {
22744
- if (migration46.version > fromVersion) {
22745
- await migration46.up(this.ctx.storage.sql);
22875
+ for (const migration47 of migrations2) {
22876
+ if (migration47.version > fromVersion) {
22877
+ await migration47.up(this.ctx.storage.sql);
22746
22878
  }
22747
22879
  }
22748
22880
  }
@@ -24097,7 +24229,7 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
24097
24229
  return cursor.toArray().map((row) => ({
24098
24230
  id: row.id,
24099
24231
  username: row.username,
24100
- role: row.role === "user" ? "user" : "admin",
24232
+ role: row.role === "user" ? "user" : row.role === "api" ? "api" : "admin",
24101
24233
  platform_user_id: row.platform_user_id ?? null,
24102
24234
  email: row.email ?? null,
24103
24235
  display_name: row.display_name ?? null,