@standardagents/builder 0.11.3 → 0.11.4
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/index.d.ts +20 -1
- package/dist/index.js +41 -3
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +10 -2
- package/dist/plugin.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1044,6 +1044,25 @@ type BuilderThreadEndpointHandler = ThreadEndpointHandler;
|
|
|
1044
1044
|
* ```
|
|
1045
1045
|
*/
|
|
1046
1046
|
declare function defineController<Env extends ThreadEnv = ThreadEnv>(controller: BuilderController<Env>): BuilderController<Env>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Runtime implementation for defineThreadEndpoint.
|
|
1049
|
+
*
|
|
1050
|
+
* This wraps the spec's defineThreadEndpoint to provide the actual
|
|
1051
|
+
* thread lookup and ThreadState creation at runtime.
|
|
1052
|
+
*
|
|
1053
|
+
* @param handler - Function that receives the request and ThreadState
|
|
1054
|
+
* @returns A Controller that can be used with the router
|
|
1055
|
+
*
|
|
1056
|
+
* @example
|
|
1057
|
+
* // agentbuilder/api/threads/[id]/status.get.ts
|
|
1058
|
+
* import { defineThreadEndpoint } from '@standardagents/spec';
|
|
1059
|
+
*
|
|
1060
|
+
* export default defineThreadEndpoint(async (req, state) => {
|
|
1061
|
+
* const { messages } = await state.getMessages({ limit: 1 });
|
|
1062
|
+
* return Response.json({ status: "ok", messageCount: messages.length });
|
|
1063
|
+
* });
|
|
1064
|
+
*/
|
|
1065
|
+
declare function createThreadEndpointHandler<Env extends ThreadEnv = ThreadEnv>(handler: ThreadEndpointHandler): BuilderController<Env>;
|
|
1047
1066
|
|
|
1048
1067
|
/**
|
|
1049
1068
|
* Authentication middleware for protecting API routes
|
|
@@ -3623,4 +3642,4 @@ type ProviderImagePart = ImagePart;
|
|
|
3623
3642
|
/** @public Alias for FilePart */
|
|
3624
3643
|
type ProviderFilePart = FilePart;
|
|
3625
3644
|
|
|
3626
|
-
export { type Agent, type AgentBuilderEnv, type AgentDefinition, type AttachmentRef, type AuthContext, type AuthUser, type BroadcastOptions, type BuilderThreadEndpointHandler, type BuilderController as Controller, type BuilderControllerContext as ControllerContext, DurableAgentBuilder, DurableThread, type Env, type FileRecord, type FileStats, type FlowResult, type FlowState, FlowStateSdk, type FlowStateWithSdk, GitHubApiError, GitHubClient, type GitHubCommitResult, type GitHubConfig, type GitHubFileChange, type GrepResult, type ImageContentPart, type ImageContextConfig, type ImageMetadata, type InjectMessageOptions$1 as InjectMessageOptions, type Provider as LLMProviderInterface, type LLMResponse, type Message, type MessageContent, type ModelDefinition, type MultimodalContent, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptPart, type Provider$1 as Provider, type ProviderContentPart, type ProviderFilePart, type ProviderImagePart, type ProviderTextPart, type RequestContext, type SideConfig, type StorageBackend, type SubpromptConfig, type TelemetryEvent, type TextContentPart, type ThreadEndpointContext, type ThreadEnv, type ThreadInstance, type ThreadMetadata, type ThreadRegistryEntry, type ToolCall, type ToolConfig, type ToolResult, type UpdateThreadParams, type User, authenticate, buildImageDescription, cat, defineController, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getThumbnail, getUnsummarizedImageAttachments, grep, hasImageAttachments, head, injectMessage, linkFile, mkdir, optimizeImageContext, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };
|
|
3645
|
+
export { type Agent, type AgentBuilderEnv, type AgentDefinition, type AttachmentRef, type AuthContext, type AuthUser, type BroadcastOptions, type BuilderThreadEndpointHandler, type BuilderController as Controller, type BuilderControllerContext as ControllerContext, DurableAgentBuilder, DurableThread, type Env, type FileRecord, type FileStats, type FlowResult, type FlowState, FlowStateSdk, type FlowStateWithSdk, GitHubApiError, GitHubClient, type GitHubCommitResult, type GitHubConfig, type GitHubFileChange, type GrepResult, type ImageContentPart, type ImageContextConfig, type ImageMetadata, type InjectMessageOptions$1 as InjectMessageOptions, type Provider as LLMProviderInterface, type LLMResponse, type Message, type MessageContent, type ModelDefinition, type MultimodalContent, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptPart, type Provider$1 as Provider, type ProviderContentPart, type ProviderFilePart, type ProviderImagePart, type ProviderTextPart, type RequestContext, type SideConfig, type StorageBackend, type SubpromptConfig, type TelemetryEvent, type TextContentPart, type ThreadEndpointContext, type ThreadEnv, type ThreadInstance, type ThreadMetadata, type ThreadRegistryEntry, type ToolCall, type ToolConfig, type ToolResult, type UpdateThreadParams, type User, authenticate, buildImageDescription, cat, createThreadEndpointHandler, defineController, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getThumbnail, getUnsummarizedImageAttachments, grep, hasImageAttachments, head, injectMessage, linkFile, mkdir, optimizeImageContext, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };
|
package/dist/index.js
CHANGED
|
@@ -9963,7 +9963,8 @@ import { hooks } from "virtual:@standardagents-hooks";
|
|
|
9963
9963
|
import { models, modelNames } from "virtual:@standardagents-models";
|
|
9964
9964
|
import { prompts, promptNames } from "virtual:@standardagents-prompts";
|
|
9965
9965
|
import { agents, agentNames } from "virtual:@standardagents-agents";
|
|
9966
|
-
import { requireAuth } from "@standardagents/builder/runtime";
|
|
9966
|
+
import { requireAuth, createThreadEndpointHandler } from "@standardagents/builder/runtime";
|
|
9967
|
+
import { isThreadEndpoint } from "@standardagents/spec";
|
|
9967
9968
|
|
|
9968
9969
|
const MOUNT_POINT = "${mountPoint}";
|
|
9969
9970
|
|
|
@@ -10096,7 +10097,14 @@ ${threadRouteCode}
|
|
|
10096
10097
|
authContext = authResult;
|
|
10097
10098
|
}
|
|
10098
10099
|
|
|
10099
|
-
|
|
10100
|
+
let controller = await routeMatch.data();
|
|
10101
|
+
|
|
10102
|
+
// Check if this is a thread endpoint (marked by defineThreadEndpoint)
|
|
10103
|
+
// If so, wrap it with createThreadEndpointHandler to provide ThreadState
|
|
10104
|
+
if (isThreadEndpoint(controller)) {
|
|
10105
|
+
controller = createThreadEndpointHandler(controller.__handler);
|
|
10106
|
+
}
|
|
10107
|
+
|
|
10100
10108
|
const context = {
|
|
10101
10109
|
req: request,
|
|
10102
10110
|
params: routeMatch.params || {},
|
|
@@ -11249,6 +11257,36 @@ init_ThreadStateImpl();
|
|
|
11249
11257
|
function defineController(controller) {
|
|
11250
11258
|
return controller;
|
|
11251
11259
|
}
|
|
11260
|
+
function createThreadEndpointHandler(handler) {
|
|
11261
|
+
return (async ({ req, params, env }) => {
|
|
11262
|
+
const threadId = params.id;
|
|
11263
|
+
if (!threadId) {
|
|
11264
|
+
return Response.json({ error: "Thread ID required" }, { status: 400 });
|
|
11265
|
+
}
|
|
11266
|
+
try {
|
|
11267
|
+
const agentBuilderId = env.AGENT_BUILDER.idFromName("singleton");
|
|
11268
|
+
const agentBuilder = env.AGENT_BUILDER.get(agentBuilderId);
|
|
11269
|
+
const metadata = await agentBuilder.getThread(threadId);
|
|
11270
|
+
if (!metadata) {
|
|
11271
|
+
return Response.json(
|
|
11272
|
+
{ error: `Thread not found: ${threadId}` },
|
|
11273
|
+
{ status: 404 }
|
|
11274
|
+
);
|
|
11275
|
+
}
|
|
11276
|
+
const durableId = env.AGENT_BUILDER_THREAD.idFromName(threadId);
|
|
11277
|
+
const stub = env.AGENT_BUILDER_THREAD.get(durableId);
|
|
11278
|
+
const instance = stub;
|
|
11279
|
+
const threadState = ThreadStateImpl.fromThreadInstance(instance, metadata);
|
|
11280
|
+
return await handler(req, threadState);
|
|
11281
|
+
} catch (error) {
|
|
11282
|
+
console.error(`Error in thread endpoint for ${threadId}:`, error);
|
|
11283
|
+
return Response.json(
|
|
11284
|
+
{ error: error.message || "Internal server error" },
|
|
11285
|
+
{ status: 500 }
|
|
11286
|
+
);
|
|
11287
|
+
}
|
|
11288
|
+
});
|
|
11289
|
+
}
|
|
11252
11290
|
|
|
11253
11291
|
// src/utils/auth.ts
|
|
11254
11292
|
async function hashToken(token) {
|
|
@@ -16098,6 +16136,6 @@ var GitHubApiError = class extends Error {
|
|
|
16098
16136
|
// src/index.ts
|
|
16099
16137
|
init_types2();
|
|
16100
16138
|
|
|
16101
|
-
export { DurableAgentBuilder, DurableThread, FlowStateSdk, GitHubApiError, GitHubClient, agentbuilder, authenticate, buildImageDescription, cat, defineController, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getThumbnail, getUnsummarizedImageAttachments, grep, hasImageAttachments, head, injectMessage, linkFile, mkdir, optimizeImageContext, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };
|
|
16139
|
+
export { DurableAgentBuilder, DurableThread, FlowStateSdk, GitHubApiError, GitHubClient, agentbuilder, authenticate, buildImageDescription, cat, createThreadEndpointHandler, defineController, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getThumbnail, getUnsummarizedImageAttachments, grep, hasImageAttachments, head, injectMessage, linkFile, mkdir, optimizeImageContext, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };
|
|
16102
16140
|
//# sourceMappingURL=index.js.map
|
|
16103
16141
|
//# sourceMappingURL=index.js.map
|