@uncensoredcode/openbridge 0.1.0

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.
Files changed (145) hide show
  1. package/README.md +117 -0
  2. package/bin/openbridge.js +10 -0
  3. package/package.json +85 -0
  4. package/packages/cli/dist/args.d.ts +30 -0
  5. package/packages/cli/dist/args.js +160 -0
  6. package/packages/cli/dist/cli.d.ts +2 -0
  7. package/packages/cli/dist/cli.js +9 -0
  8. package/packages/cli/dist/index.d.ts +26 -0
  9. package/packages/cli/dist/index.js +76 -0
  10. package/packages/runtime/dist/assistant-protocol.d.ts +34 -0
  11. package/packages/runtime/dist/assistant-protocol.js +121 -0
  12. package/packages/runtime/dist/execution/in-process.d.ts +14 -0
  13. package/packages/runtime/dist/execution/in-process.js +45 -0
  14. package/packages/runtime/dist/execution/types.d.ts +49 -0
  15. package/packages/runtime/dist/execution/types.js +20 -0
  16. package/packages/runtime/dist/index.d.ts +86 -0
  17. package/packages/runtime/dist/index.js +60 -0
  18. package/packages/runtime/dist/normalizers/index.d.ts +6 -0
  19. package/packages/runtime/dist/normalizers/index.js +12 -0
  20. package/packages/runtime/dist/normalizers/legacy-packet.d.ts +6 -0
  21. package/packages/runtime/dist/normalizers/legacy-packet.js +131 -0
  22. package/packages/runtime/dist/output-sanitizer.d.ts +23 -0
  23. package/packages/runtime/dist/output-sanitizer.js +78 -0
  24. package/packages/runtime/dist/packet-extractor.d.ts +17 -0
  25. package/packages/runtime/dist/packet-extractor.js +43 -0
  26. package/packages/runtime/dist/packet-normalizer.d.ts +21 -0
  27. package/packages/runtime/dist/packet-normalizer.js +47 -0
  28. package/packages/runtime/dist/prompt-compiler.d.ts +28 -0
  29. package/packages/runtime/dist/prompt-compiler.js +301 -0
  30. package/packages/runtime/dist/protocol.d.ts +44 -0
  31. package/packages/runtime/dist/protocol.js +165 -0
  32. package/packages/runtime/dist/provider-failure.d.ts +52 -0
  33. package/packages/runtime/dist/provider-failure.js +236 -0
  34. package/packages/runtime/dist/provider.d.ts +40 -0
  35. package/packages/runtime/dist/provider.js +1 -0
  36. package/packages/runtime/dist/runtime.d.ts +86 -0
  37. package/packages/runtime/dist/runtime.js +462 -0
  38. package/packages/runtime/dist/session-bound-provider.d.ts +52 -0
  39. package/packages/runtime/dist/session-bound-provider.js +366 -0
  40. package/packages/runtime/dist/tool-name-aliases.d.ts +5 -0
  41. package/packages/runtime/dist/tool-name-aliases.js +13 -0
  42. package/packages/runtime/dist/tools/bash.d.ts +9 -0
  43. package/packages/runtime/dist/tools/bash.js +157 -0
  44. package/packages/runtime/dist/tools/edit.d.ts +9 -0
  45. package/packages/runtime/dist/tools/edit.js +94 -0
  46. package/packages/runtime/dist/tools/index.d.ts +39 -0
  47. package/packages/runtime/dist/tools/index.js +27 -0
  48. package/packages/runtime/dist/tools/list-dir.d.ts +9 -0
  49. package/packages/runtime/dist/tools/list-dir.js +127 -0
  50. package/packages/runtime/dist/tools/read.d.ts +9 -0
  51. package/packages/runtime/dist/tools/read.js +56 -0
  52. package/packages/runtime/dist/tools/registry.d.ts +15 -0
  53. package/packages/runtime/dist/tools/registry.js +38 -0
  54. package/packages/runtime/dist/tools/runtime-path.d.ts +7 -0
  55. package/packages/runtime/dist/tools/runtime-path.js +22 -0
  56. package/packages/runtime/dist/tools/search-files.d.ts +9 -0
  57. package/packages/runtime/dist/tools/search-files.js +149 -0
  58. package/packages/runtime/dist/tools/text-file.d.ts +32 -0
  59. package/packages/runtime/dist/tools/text-file.js +101 -0
  60. package/packages/runtime/dist/tools/workspace-path.d.ts +17 -0
  61. package/packages/runtime/dist/tools/workspace-path.js +70 -0
  62. package/packages/runtime/dist/tools/write.d.ts +9 -0
  63. package/packages/runtime/dist/tools/write.js +59 -0
  64. package/packages/server/dist/bridge/bridge-model-catalog.d.ts +56 -0
  65. package/packages/server/dist/bridge/bridge-model-catalog.js +100 -0
  66. package/packages/server/dist/bridge/bridge-runtime-service.d.ts +61 -0
  67. package/packages/server/dist/bridge/bridge-runtime-service.js +1386 -0
  68. package/packages/server/dist/bridge/chat-completions/chat-completion-service.d.ts +127 -0
  69. package/packages/server/dist/bridge/chat-completions/chat-completion-service.js +1026 -0
  70. package/packages/server/dist/bridge/index.d.ts +335 -0
  71. package/packages/server/dist/bridge/index.js +45 -0
  72. package/packages/server/dist/bridge/live-provider-extraction-canary.d.ts +69 -0
  73. package/packages/server/dist/bridge/live-provider-extraction-canary.js +186 -0
  74. package/packages/server/dist/bridge/providers/generic-provider-transport.d.ts +53 -0
  75. package/packages/server/dist/bridge/providers/generic-provider-transport.js +973 -0
  76. package/packages/server/dist/bridge/providers/provider-session-resolver.d.ts +17 -0
  77. package/packages/server/dist/bridge/providers/provider-session-resolver.js +95 -0
  78. package/packages/server/dist/bridge/providers/provider-streams.d.ts +80 -0
  79. package/packages/server/dist/bridge/providers/provider-streams.js +844 -0
  80. package/packages/server/dist/bridge/providers/provider-transport-profile.d.ts +194 -0
  81. package/packages/server/dist/bridge/providers/provider-transport-profile.js +198 -0
  82. package/packages/server/dist/bridge/providers/web-provider-transport.d.ts +30 -0
  83. package/packages/server/dist/bridge/providers/web-provider-transport.js +151 -0
  84. package/packages/server/dist/bridge/state/file-bridge-state-store.d.ts +36 -0
  85. package/packages/server/dist/bridge/state/file-bridge-state-store.js +164 -0
  86. package/packages/server/dist/bridge/stores/local-session-package-store.d.ts +23 -0
  87. package/packages/server/dist/bridge/stores/local-session-package-store.js +548 -0
  88. package/packages/server/dist/bridge/stores/provider-store.d.ts +94 -0
  89. package/packages/server/dist/bridge/stores/provider-store.js +143 -0
  90. package/packages/server/dist/bridge/stores/session-backed-provider-store.d.ts +7 -0
  91. package/packages/server/dist/bridge/stores/session-backed-provider-store.js +26 -0
  92. package/packages/server/dist/bridge/stores/session-package-store.d.ts +286 -0
  93. package/packages/server/dist/bridge/stores/session-package-store.js +1527 -0
  94. package/packages/server/dist/bridge/stores/session-store.d.ts +120 -0
  95. package/packages/server/dist/bridge/stores/session-store.js +139 -0
  96. package/packages/server/dist/cli/index.d.ts +9 -0
  97. package/packages/server/dist/cli/index.js +6 -0
  98. package/packages/server/dist/cli/main.d.ts +2 -0
  99. package/packages/server/dist/cli/main.js +9 -0
  100. package/packages/server/dist/cli/run-bridge-server-cli.d.ts +54 -0
  101. package/packages/server/dist/cli/run-bridge-server-cli.js +371 -0
  102. package/packages/server/dist/client/bridge-api-client.d.ts +61 -0
  103. package/packages/server/dist/client/bridge-api-client.js +267 -0
  104. package/packages/server/dist/client/index.d.ts +11 -0
  105. package/packages/server/dist/client/index.js +11 -0
  106. package/packages/server/dist/config/bridge-server-config.d.ts +52 -0
  107. package/packages/server/dist/config/bridge-server-config.js +118 -0
  108. package/packages/server/dist/config/index.d.ts +20 -0
  109. package/packages/server/dist/config/index.js +8 -0
  110. package/packages/server/dist/http/bridge-api-route-context.d.ts +14 -0
  111. package/packages/server/dist/http/bridge-api-route-context.js +1 -0
  112. package/packages/server/dist/http/create-bridge-api-server.d.ts +72 -0
  113. package/packages/server/dist/http/create-bridge-api-server.js +225 -0
  114. package/packages/server/dist/http/index.d.ts +5 -0
  115. package/packages/server/dist/http/index.js +5 -0
  116. package/packages/server/dist/http/parse-request.d.ts +6 -0
  117. package/packages/server/dist/http/parse-request.js +27 -0
  118. package/packages/server/dist/http/register-bridge-api-routes.d.ts +7 -0
  119. package/packages/server/dist/http/register-bridge-api-routes.js +17 -0
  120. package/packages/server/dist/http/routes/admin-routes.d.ts +7 -0
  121. package/packages/server/dist/http/routes/admin-routes.js +135 -0
  122. package/packages/server/dist/http/routes/chat-completions-route.d.ts +7 -0
  123. package/packages/server/dist/http/routes/chat-completions-route.js +49 -0
  124. package/packages/server/dist/http/routes/health-routes.d.ts +6 -0
  125. package/packages/server/dist/http/routes/health-routes.js +7 -0
  126. package/packages/server/dist/http/routes/message-routes.d.ts +7 -0
  127. package/packages/server/dist/http/routes/message-routes.js +7 -0
  128. package/packages/server/dist/index.d.ts +85 -0
  129. package/packages/server/dist/index.js +28 -0
  130. package/packages/server/dist/security/bridge-auth.d.ts +9 -0
  131. package/packages/server/dist/security/bridge-auth.js +41 -0
  132. package/packages/server/dist/security/cors-policy.d.ts +5 -0
  133. package/packages/server/dist/security/cors-policy.js +34 -0
  134. package/packages/server/dist/security/index.d.ts +16 -0
  135. package/packages/server/dist/security/index.js +12 -0
  136. package/packages/server/dist/security/redact-sensitive-values.d.ts +19 -0
  137. package/packages/server/dist/security/redact-sensitive-values.js +67 -0
  138. package/packages/server/dist/shared/api-schema.d.ts +133 -0
  139. package/packages/server/dist/shared/api-schema.js +1 -0
  140. package/packages/server/dist/shared/bridge-api-error.d.ts +17 -0
  141. package/packages/server/dist/shared/bridge-api-error.js +19 -0
  142. package/packages/server/dist/shared/index.d.ts +7 -0
  143. package/packages/server/dist/shared/index.js +7 -0
  144. package/packages/server/dist/shared/output.d.ts +5 -0
  145. package/packages/server/dist/shared/output.js +14 -0
@@ -0,0 +1,14 @@
1
+ import type { ExecutionRequest, ExecutionResponse, RuntimeTool, ToolDefinition, ToolExecutor } from "./types.ts";
2
+ type InProcessToolExecutorOptions = {
3
+ tools?: RuntimeTool[];
4
+ };
5
+ declare class InProcessToolExecutor implements ToolExecutor {
6
+ #private;
7
+ constructor(options?: InProcessToolExecutorOptions);
8
+ getAvailableTools(): Promise<ToolDefinition[]>;
9
+ executeTool(request: ExecutionRequest): Promise<ExecutionResponse>;
10
+ }
11
+ export declare const inProcessModule: {
12
+ InProcessToolExecutor: typeof InProcessToolExecutor;
13
+ };
14
+ export type { InProcessToolExecutor, InProcessToolExecutorOptions };
@@ -0,0 +1,45 @@
1
+ import { executionTypesModule } from "./types.js";
2
+ const { ToolExecutionError, toolFailure } = executionTypesModule;
3
+ class InProcessToolExecutor {
4
+ #toolsByName;
5
+ constructor(options = {}) {
6
+ this.#toolsByName = new Map((options.tools ?? []).map((tool) => [tool.definition.name, tool]));
7
+ }
8
+ async getAvailableTools() {
9
+ return [...this.#toolsByName.values()].map((tool) => tool.definition);
10
+ }
11
+ async executeTool(request) {
12
+ return executeToolCall(this.#toolsByName, request.call);
13
+ }
14
+ }
15
+ async function executeToolCall(toolsByName, call) {
16
+ const tool = toolsByName.get(call.name);
17
+ if (!tool) {
18
+ return {
19
+ ok: false,
20
+ payload: toolFailure("tool_not_found", `Tool "${call.name}" is not registered.`)
21
+ };
22
+ }
23
+ try {
24
+ const payload = await tool.execute(call.args);
25
+ return {
26
+ ok: true,
27
+ payload
28
+ };
29
+ }
30
+ catch (error) {
31
+ if (error instanceof ToolExecutionError) {
32
+ return {
33
+ ok: false,
34
+ payload: toolFailure(error.code, error.message)
35
+ };
36
+ }
37
+ return {
38
+ ok: false,
39
+ payload: toolFailure("tool_execution_failed", error instanceof Error ? error.message : String(error))
40
+ };
41
+ }
42
+ }
43
+ export const inProcessModule = {
44
+ InProcessToolExecutor
45
+ };
@@ -0,0 +1,49 @@
1
+ import type { ToolCall } from "../protocol.ts";
2
+ type ToolSchema = {
3
+ type: "object";
4
+ properties: Record<string, {
5
+ type: "string" | "boolean";
6
+ description: string;
7
+ }>;
8
+ required: string[];
9
+ };
10
+ type ToolDefinition = {
11
+ name: string;
12
+ description: string;
13
+ inputSchema: ToolSchema;
14
+ };
15
+ type ToolFailurePayload = {
16
+ error: {
17
+ code: string;
18
+ message: string;
19
+ };
20
+ };
21
+ type ToolExecutionResult = {
22
+ ok: true;
23
+ payload: unknown;
24
+ } | {
25
+ ok: false;
26
+ payload: ToolFailurePayload;
27
+ };
28
+ type ExecutionRequest = {
29
+ call: ToolCall;
30
+ };
31
+ type ExecutionResponse = ToolExecutionResult;
32
+ interface ToolExecutor {
33
+ getAvailableTools(): Promise<ToolDefinition[]>;
34
+ executeTool(request: ExecutionRequest): Promise<ExecutionResponse>;
35
+ }
36
+ type RuntimeTool = {
37
+ definition: ToolDefinition;
38
+ execute(args: Record<string, unknown>): Promise<unknown>;
39
+ };
40
+ declare class ToolExecutionError extends Error {
41
+ readonly code: string;
42
+ constructor(code: string, message: string);
43
+ }
44
+ declare function toolFailure(code: string, message: string): ToolFailurePayload;
45
+ export declare const executionTypesModule: {
46
+ ToolExecutionError: typeof ToolExecutionError;
47
+ toolFailure: typeof toolFailure;
48
+ };
49
+ export type { ExecutionRequest, ExecutionResponse, RuntimeTool, ToolDefinition, ToolExecutionError, ToolExecutionResult, ToolExecutor, ToolFailurePayload, ToolSchema };
@@ -0,0 +1,20 @@
1
+ class ToolExecutionError extends Error {
2
+ code;
3
+ constructor(code, message) {
4
+ super(message);
5
+ this.name = "ToolExecutionError";
6
+ this.code = code;
7
+ }
8
+ }
9
+ function toolFailure(code, message) {
10
+ return {
11
+ error: {
12
+ code,
13
+ message
14
+ }
15
+ };
16
+ }
17
+ export const executionTypesModule = {
18
+ ToolExecutionError,
19
+ toolFailure
20
+ };
@@ -0,0 +1,86 @@
1
+ export declare const bridgeRuntime: {
2
+ AssistantProtocolError: typeof import("./assistant-protocol.ts").AssistantProtocolError;
3
+ createFinalResponse: (message: string) => string;
4
+ createToolResponse: (toolCall: import("./assistant-protocol.ts").AssistantToolCall) => string;
5
+ parseAndValidateAssistantResponse: (rawText: string, availableTools: import("./execution/types.ts").ToolDefinition[]) => import("./assistant-protocol.ts").AssistantFinalResponse | import("./assistant-protocol.ts").AssistantToolResponse;
6
+ parseAssistantResponse: (rawText: string) => import("./assistant-protocol.ts").AssistantResponse;
7
+ serializeAssistantResponse: (response: import("./assistant-protocol.ts").AssistantResponse) => string;
8
+ validateAssistantResponse: (response: import("./assistant-protocol.ts").AssistantResponse, availableTools: import("./execution/types.ts").ToolDefinition[]) => import("./assistant-protocol.ts").AssistantFinalResponse | import("./assistant-protocol.ts").AssistantToolResponse;
9
+ extractPacketCandidate: (rawText: string) => import("./packet-extractor.ts").PacketExtractionResult;
10
+ InProcessToolExecutor: typeof import("./execution/in-process.ts").InProcessToolExecutor;
11
+ ToolExecutionError: typeof import("./execution/types.ts").ToolExecutionError;
12
+ toolFailure: (code: string, message: string) => import("./execution/types.ts").ToolFailurePayload;
13
+ extractPacketMessage: (content: string) => string | null;
14
+ looksLikeInternalControlText: (content: string) => boolean;
15
+ sanitizeVisibleModelOutput: (content: string, options: {
16
+ packetMessageReason: string;
17
+ documentReason: string;
18
+ controlReason: string;
19
+ fallbackMessage: string;
20
+ documentFallbackMessage: string;
21
+ }) => import("./output-sanitizer.ts").VisibleModelOutputSanitizationResult;
22
+ normalizeProviderPacket: (_providerId: string, extractedCandidate: string) => import("./packet-normalizer.ts").PacketNormalizationResult;
23
+ compileProviderTurn: (input: import("./prompt-compiler.ts").CompileProviderTurnInput) => import("./prompt-compiler.ts").CompiledProviderTurn;
24
+ createBashTool: (options: {
25
+ runtimeRoot: string;
26
+ }) => import("./execution/types.ts").RuntimeTool;
27
+ createDefaultRuntimeTools: (runtimeRoot: string) => import("./execution/types.ts").RuntimeTool[];
28
+ createEditTool: (options: {
29
+ runtimeRoot: string;
30
+ }) => import("./execution/types.ts").RuntimeTool;
31
+ createListDirTool: (options: {
32
+ workspaceRoot: string;
33
+ }) => import("./execution/types.ts").RuntimeTool;
34
+ createReadTool: (options: {
35
+ runtimeRoot: string;
36
+ }) => import("./execution/types.ts").RuntimeTool;
37
+ createRuntimeTools: (input: {
38
+ profile?: import("./tools/registry.ts").RuntimeToolProfile;
39
+ runtimeRoot: string;
40
+ workspaceRoot?: string;
41
+ }) => import("./execution/types.ts").RuntimeTool[];
42
+ createSearchFilesTool: (options: {
43
+ workspaceRoot: string;
44
+ }) => import("./execution/types.ts").RuntimeTool;
45
+ createSecondaryRuntimeTools: (workspaceRoot: string) => import("./execution/types.ts").RuntimeTool[];
46
+ createWriteTool: (options: {
47
+ runtimeRoot: string;
48
+ }) => import("./execution/types.ts").RuntimeTool;
49
+ ensureRuntimeRoot: (runtimeRoot: string) => Promise<string>;
50
+ ensureWorkspaceRoot: (workspaceRoot: string) => Promise<string>;
51
+ MAX_FILE_READ_BYTES: number;
52
+ MAX_FILE_WRITE_BYTES: number;
53
+ resolveRuntimePath: (runtimeRoot: string, requestedPath: string) => Promise<string>;
54
+ resolveWorkspacePath: (input: {
55
+ workspaceRoot: string;
56
+ requestedPath: string;
57
+ kind: "read" | "write";
58
+ }) => Promise<import("./tools/workspace-path.ts").ResolvedWorkspacePath>;
59
+ normalizeProviderToolName: (name: string) => string;
60
+ createMessagePacket: (mode: Extract<import("./protocol.ts").PacketMode, "final" | "ask_user" | "fail">, message: string) => string;
61
+ createToolRequestPacket: (toolCall: import("./protocol.ts").ToolCall) => string;
62
+ parseZcPacket: (rawText: string) => import("./protocol.ts").ZcPacket;
63
+ serializeToolResult: (result: import("./protocol.ts").ToolResult) => string;
64
+ PacketProtocolError: typeof import("./protocol.ts").PacketProtocolError;
65
+ ProviderFailure: typeof import("./provider-failure.ts").ProviderFailure;
66
+ classifyProviderTransportError: (error: unknown) => import("./provider-failure.ts").ProviderFailure;
67
+ formatProviderFailureMessage: (error: import("./provider-failure.ts").ProviderFailure) => string;
68
+ isProviderFailure: (error: unknown) => error is import("./provider-failure.ts").ProviderFailure;
69
+ serializeProviderFailure: (error: import("./provider-failure.ts").ProviderFailure) => import("./provider-failure.ts").SerializedProviderFailure;
70
+ withProviderRecovery: (error: import("./provider-failure.ts").ProviderFailure, recovery: Partial<import("./provider-failure.ts").ProviderRecoveryState>, overrides?: Partial<Pick<import("./provider-failure.ts").ProviderFailure, "kind" | "displayMessage" | "retryable" | "sessionResetEligible">>) => import("./provider-failure.ts").ProviderFailure;
71
+ runBridgeRuntime: (input: import("./runtime.ts").RunRuntimeInput) => Promise<import("./runtime.ts").RuntimeOutcome>;
72
+ SessionBoundProviderAdapter: typeof import("./session-bound-provider.ts").SessionBoundProviderAdapter;
73
+ };
74
+ export type { AssistantFinalResponse, AssistantProtocolError, AssistantResponse, AssistantToolCall, AssistantToolResponse } from "./assistant-protocol.ts";
75
+ export type { InProcessToolExecutor } from "./execution/in-process.ts";
76
+ export type { ExecutionRequest, ExecutionResponse, RuntimeTool, ToolDefinition, ToolExecutionError, ToolExecutionResult, ToolExecutor, ToolFailurePayload, ToolSchema } from "./execution/types.ts";
77
+ export type { VisibleModelOutputSanitizationResult } from "./output-sanitizer.ts";
78
+ export type { PacketExtractionFailure, PacketExtractionResult, PacketExtractionSuccess } from "./packet-extractor.ts";
79
+ export type { PacketNormalizationFailure, PacketNormalizationFailureCode, PacketNormalizationResult, PacketNormalizationStrategy, PacketNormalizationSuccess } from "./packet-normalizer.ts";
80
+ export type { CompiledProviderMessage, CompiledProviderTurn, CompileProviderTurnInput } from "./prompt-compiler.ts";
81
+ export type { AskUserPacket, FailPacket, FinalPacket, PacketMode, PacketProtocolError, ToolCall, ToolRequestPacket, ToolResult, ZcPacket } from "./protocol.ts";
82
+ export type { BridgeSessionTurn, ConversationEntry, ConversationState, ProviderAdapter, ProviderTurnInput, RepairInvalidResponseInput } from "./provider.ts";
83
+ export type { ProviderFailure, ProviderFailureCode, ProviderFailureKind, ProviderRecoveryState, SerializedProviderFailure } from "./provider-failure.ts";
84
+ export type { RunRuntimeInput, RuntimeConfig, RuntimeEvent, RuntimeFailure, RuntimeOutcome, RuntimeTerminalMode } from "./runtime.ts";
85
+ export type { ProviderTransport, ProviderTransportRequest, ProviderTransportResponse, SessionBindingStore, SessionBoundProviderAdapter, SessionBoundProviderAdapterOptions, UpstreamConversationBinding } from "./session-bound-provider.ts";
86
+ export type { ResolvedWorkspacePath, RuntimeToolProfile } from "./tools/index.ts";
@@ -0,0 +1,60 @@
1
+ import { assistantProtocolModule } from "./assistant-protocol.js";
2
+ import { inProcessModule } from "./execution/in-process.js";
3
+ import { executionTypesModule } from "./execution/types.js";
4
+ import { outputSanitizerModule } from "./output-sanitizer.js";
5
+ import { packetExtractorModule } from "./packet-extractor.js";
6
+ import { packetNormalizerModule } from "./packet-normalizer.js";
7
+ import { promptCompilerModule } from "./prompt-compiler.js";
8
+ import { protocolModule } from "./protocol.js";
9
+ import { providerFailureModule } from "./provider-failure.js";
10
+ import { runtimeModule } from "./runtime.js";
11
+ import { sessionBoundProviderModule } from "./session-bound-provider.js";
12
+ import { toolNameAliasesModule } from "./tool-name-aliases.js";
13
+ import { toolsModule } from "./tools/index.js";
14
+ export const bridgeRuntime = {
15
+ AssistantProtocolError: assistantProtocolModule.AssistantProtocolError,
16
+ createFinalResponse: assistantProtocolModule.createFinalResponse,
17
+ createToolResponse: assistantProtocolModule.createToolResponse,
18
+ parseAndValidateAssistantResponse: assistantProtocolModule.parseAndValidateAssistantResponse,
19
+ parseAssistantResponse: assistantProtocolModule.parseAssistantResponse,
20
+ serializeAssistantResponse: assistantProtocolModule.serializeAssistantResponse,
21
+ validateAssistantResponse: assistantProtocolModule.validateAssistantResponse,
22
+ extractPacketCandidate: packetExtractorModule.extractPacketCandidate,
23
+ InProcessToolExecutor: inProcessModule.InProcessToolExecutor,
24
+ ToolExecutionError: executionTypesModule.ToolExecutionError,
25
+ toolFailure: executionTypesModule.toolFailure,
26
+ extractPacketMessage: outputSanitizerModule.extractPacketMessage,
27
+ looksLikeInternalControlText: outputSanitizerModule.looksLikeInternalControlText,
28
+ sanitizeVisibleModelOutput: outputSanitizerModule.sanitizeVisibleModelOutput,
29
+ normalizeProviderPacket: packetNormalizerModule.normalizeProviderPacket,
30
+ compileProviderTurn: promptCompilerModule.compileProviderTurn,
31
+ createBashTool: toolsModule.createBashTool,
32
+ createDefaultRuntimeTools: toolsModule.createDefaultRuntimeTools,
33
+ createEditTool: toolsModule.createEditTool,
34
+ createListDirTool: toolsModule.createListDirTool,
35
+ createReadTool: toolsModule.createReadTool,
36
+ createRuntimeTools: toolsModule.createRuntimeTools,
37
+ createSearchFilesTool: toolsModule.createSearchFilesTool,
38
+ createSecondaryRuntimeTools: toolsModule.createSecondaryRuntimeTools,
39
+ createWriteTool: toolsModule.createWriteTool,
40
+ ensureRuntimeRoot: toolsModule.ensureRuntimeRoot,
41
+ ensureWorkspaceRoot: toolsModule.ensureWorkspaceRoot,
42
+ MAX_FILE_READ_BYTES: toolsModule.MAX_FILE_READ_BYTES,
43
+ MAX_FILE_WRITE_BYTES: toolsModule.MAX_FILE_WRITE_BYTES,
44
+ resolveRuntimePath: toolsModule.resolveRuntimePath,
45
+ resolveWorkspacePath: toolsModule.resolveWorkspacePath,
46
+ normalizeProviderToolName: toolNameAliasesModule.normalizeProviderToolName,
47
+ createMessagePacket: protocolModule.createMessagePacket,
48
+ createToolRequestPacket: protocolModule.createToolRequestPacket,
49
+ parseZcPacket: protocolModule.parseZcPacket,
50
+ serializeToolResult: protocolModule.serializeToolResult,
51
+ PacketProtocolError: protocolModule.PacketProtocolError,
52
+ ProviderFailure: providerFailureModule.ProviderFailure,
53
+ classifyProviderTransportError: providerFailureModule.classifyProviderTransportError,
54
+ formatProviderFailureMessage: providerFailureModule.formatProviderFailureMessage,
55
+ isProviderFailure: providerFailureModule.isProviderFailure,
56
+ serializeProviderFailure: providerFailureModule.serializeProviderFailure,
57
+ withProviderRecovery: providerFailureModule.withProviderRecovery,
58
+ runBridgeRuntime: runtimeModule.runBridgeRuntime,
59
+ SessionBoundProviderAdapter: sessionBoundProviderModule.SessionBoundProviderAdapter
60
+ };
@@ -0,0 +1,6 @@
1
+ import type { PacketNormalizationResult } from "../packet-normalizer.ts";
2
+ declare function normalizeGenericLegacyPacket(candidate: string): PacketNormalizationResult | null;
3
+ export declare const normalizersModule: {
4
+ normalizeGenericLegacyPacket: typeof normalizeGenericLegacyPacket;
5
+ };
6
+ export {};
@@ -0,0 +1,12 @@
1
+ import { legacyPacketModule } from "./legacy-packet.js";
2
+ const { normalizeLegacyPacket } = legacyPacketModule;
3
+ function normalizeGenericLegacyPacket(candidate) {
4
+ const trimmed = candidate.trim();
5
+ if (!trimmed.startsWith("<packet")) {
6
+ return null;
7
+ }
8
+ return normalizeLegacyPacket(trimmed);
9
+ }
10
+ export const normalizersModule = {
11
+ normalizeGenericLegacyPacket
12
+ };
@@ -0,0 +1,6 @@
1
+ import type { PacketNormalizationResult } from "../packet-normalizer.ts";
2
+ declare function normalizeLegacyPacket(candidate: string): PacketNormalizationResult;
3
+ export declare const legacyPacketModule: {
4
+ normalizeLegacyPacket: typeof normalizeLegacyPacket;
5
+ };
6
+ export {};
@@ -0,0 +1,131 @@
1
+ import { protocolModule } from "../protocol.js";
2
+ const { createMessagePacket, createToolRequestPacket } = protocolModule;
3
+ function normalizeLegacyPacket(candidate) {
4
+ const rootMatch = candidate.trim().match(/^<packet\b([^>]*)>([\s\S]*)<\/packet>$/);
5
+ if (!rootMatch) {
6
+ return fail("invalid_provider_packet", 'Legacy packet normalization expects a single root <packet mode="..."> element.', []);
7
+ }
8
+ const attributes = rootMatch[1] ?? "";
9
+ const body = rootMatch[2] ?? "";
10
+ const modeMatch = attributes.match(/\bmode="([^"]+)"/);
11
+ if (!modeMatch) {
12
+ return fail("invalid_provider_packet", 'Legacy packet is missing required mode="..." attribute.', []);
13
+ }
14
+ const mode = parseMode(modeMatch[1] ?? "");
15
+ if (!mode) {
16
+ return fail("invalid_provider_packet", `Legacy packet mode "${(modeMatch[1] ?? "").trim() || "(empty)"}" is not supported.`, []);
17
+ }
18
+ if (mode === "tool_request") {
19
+ const toolNode = extractSingleTag(body, "tool_call");
20
+ if (!toolNode.ok) {
21
+ return toolNode;
22
+ }
23
+ let parsed;
24
+ try {
25
+ parsed = JSON.parse(toolNode.inner.trim());
26
+ }
27
+ catch {
28
+ return fail("invalid_provider_packet", "Legacy tool_call body must contain valid JSON.", [
29
+ 'Expected an object with string "name" and object "args" fields.'
30
+ ]);
31
+ }
32
+ if (!isRecord(parsed)) {
33
+ return fail("invalid_provider_packet", "Legacy tool_call JSON must decode to an object.", []);
34
+ }
35
+ const name = typeof parsed.name === "string" ? parsed.name.trim() : "";
36
+ if (!name) {
37
+ return fail("invalid_provider_packet", 'Legacy tool_call JSON requires a non-empty "name" field.', []);
38
+ }
39
+ if (!isRecord(parsed.args)) {
40
+ return fail("invalid_provider_packet", 'Legacy tool_call JSON requires an object "args" field.', []);
41
+ }
42
+ const toolCall = {
43
+ id: typeof parsed.id === "string" && parsed.id.trim() ? parsed.id.trim() : "call_1",
44
+ name,
45
+ args: parsed.args
46
+ };
47
+ return {
48
+ ok: true,
49
+ strategy: "legacy_packet_v1",
50
+ canonicalPacket: createToolRequestPacket(toolCall),
51
+ notes: [
52
+ `Normalized legacy tool_request for tool "${name}".`,
53
+ `Synthesized tool call id "${toolCall.id}".`
54
+ ]
55
+ };
56
+ }
57
+ const messageNode = extractSingleTag(body, "message");
58
+ if (!messageNode.ok) {
59
+ return messageNode;
60
+ }
61
+ const message = parseMessage(messageNode.inner);
62
+ if (!message.ok) {
63
+ return message;
64
+ }
65
+ return {
66
+ ok: true,
67
+ strategy: "legacy_packet_v1",
68
+ canonicalPacket: createMessagePacket(mode, message.value),
69
+ notes: [`Normalized legacy ${mode} packet into canonical zc_packet form.`]
70
+ };
71
+ }
72
+ function parseMode(input) {
73
+ switch (input.trim()) {
74
+ case "final":
75
+ case "tool_request":
76
+ case "ask_user":
77
+ case "fail":
78
+ return input.trim();
79
+ default:
80
+ return null;
81
+ }
82
+ }
83
+ function extractSingleTag(source, tagName) {
84
+ const expression = new RegExp(`<${tagName}>([\\s\\S]*?)<\\/${tagName}>`, "g");
85
+ const matches = [...source.matchAll(expression)];
86
+ if (matches.length !== 1) {
87
+ return fail("invalid_provider_packet", `Legacy ${tagName === "tool_call" ? "tool_request" : "message"} packet must contain exactly one <${tagName}> element.`, []);
88
+ }
89
+ const match = matches[0];
90
+ const index = match.index ?? 0;
91
+ const fullMatch = match[0];
92
+ const remainder = `${source.slice(0, index)}${source.slice(index + fullMatch.length)}`;
93
+ if (remainder.trim().length > 0) {
94
+ return fail("invalid_provider_packet", `Legacy <${tagName}> packet contained unexpected content outside <${tagName}>.`, []);
95
+ }
96
+ return {
97
+ ok: true,
98
+ inner: match[1] ?? ""
99
+ };
100
+ }
101
+ function parseMessage(raw) {
102
+ const trimmed = raw.trim();
103
+ if (trimmed.startsWith("<![CDATA[") && trimmed.endsWith("]]>")) {
104
+ return {
105
+ ok: true,
106
+ value: trimmed.slice("<![CDATA[".length, -"]]>".length).trim()
107
+ };
108
+ }
109
+ if (trimmed.includes("<")) {
110
+ return fail("invalid_provider_packet", "Legacy message packets must contain plain text or a single CDATA section.", []);
111
+ }
112
+ return {
113
+ ok: true,
114
+ value: trimmed
115
+ };
116
+ }
117
+ function fail(code, message, notes) {
118
+ return {
119
+ ok: false,
120
+ strategy: "legacy_packet_v1",
121
+ code,
122
+ message,
123
+ notes
124
+ };
125
+ }
126
+ function isRecord(value) {
127
+ return typeof value === "object" && value !== null && !Array.isArray(value);
128
+ }
129
+ export const legacyPacketModule = {
130
+ normalizeLegacyPacket
131
+ };
@@ -0,0 +1,23 @@
1
+ type VisibleModelOutputSanitizationResult = {
2
+ content: string;
3
+ sanitized: false;
4
+ } | {
5
+ content: string;
6
+ sanitized: true;
7
+ reason: string;
8
+ };
9
+ declare function sanitizeVisibleModelOutput(content: string, options: {
10
+ packetMessageReason: string;
11
+ documentReason: string;
12
+ controlReason: string;
13
+ fallbackMessage: string;
14
+ documentFallbackMessage: string;
15
+ }): VisibleModelOutputSanitizationResult;
16
+ declare function extractPacketMessage(content: string): string | null;
17
+ declare function looksLikeInternalControlText(content: string): boolean;
18
+ export declare const outputSanitizerModule: {
19
+ sanitizeVisibleModelOutput: typeof sanitizeVisibleModelOutput;
20
+ extractPacketMessage: typeof extractPacketMessage;
21
+ looksLikeInternalControlText: typeof looksLikeInternalControlText;
22
+ };
23
+ export type { VisibleModelOutputSanitizationResult };
@@ -0,0 +1,78 @@
1
+ function sanitizeVisibleModelOutput(content, options) {
2
+ const trimmed = content.trim();
3
+ if (!trimmed) {
4
+ return {
5
+ content,
6
+ sanitized: false
7
+ };
8
+ }
9
+ if (/^<(?:final|tool|zc_packet|packet)\b/i.test(trimmed)) {
10
+ const extractedMessage = extractPacketMessage(trimmed);
11
+ if (extractedMessage) {
12
+ return {
13
+ content: extractedMessage,
14
+ sanitized: true,
15
+ reason: options.packetMessageReason
16
+ };
17
+ }
18
+ return {
19
+ content: options.fallbackMessage,
20
+ sanitized: true,
21
+ reason: "packet_reply_suppressed"
22
+ };
23
+ }
24
+ if (/\[DOCUMENT:[^\]]+\]/i.test(trimmed)) {
25
+ return {
26
+ content: options.documentFallbackMessage,
27
+ sanitized: true,
28
+ reason: options.documentReason
29
+ };
30
+ }
31
+ if (looksLikeInternalControlText(trimmed)) {
32
+ return {
33
+ content: options.fallbackMessage,
34
+ sanitized: true,
35
+ reason: options.controlReason
36
+ };
37
+ }
38
+ return {
39
+ content,
40
+ sanitized: false
41
+ };
42
+ }
43
+ function extractPacketMessage(content) {
44
+ const finalMatch = content.match(/<final>([\s\S]*?)<\/final>/i);
45
+ if (finalMatch) {
46
+ const finalMessage = (finalMatch[1] ?? "").trim();
47
+ return finalMessage || null;
48
+ }
49
+ const messageMatch = content.match(/<message>([\s\S]*?)<\/message>/i);
50
+ if (!messageMatch) {
51
+ return null;
52
+ }
53
+ const rawMessage = (messageMatch[1] ?? "").trim();
54
+ if (!rawMessage) {
55
+ return null;
56
+ }
57
+ const cdataMatch = rawMessage.match(/^<!\[CDATA\[([\s\S]*?)\]\]>$/i);
58
+ const value = (cdataMatch?.[1] ?? rawMessage).trim();
59
+ return value || null;
60
+ }
61
+ function looksLikeInternalControlText(content) {
62
+ const normalized = content.toLowerCase();
63
+ return (normalized.includes("use <final>...</final>") ||
64
+ normalized.includes('use <tool>{"name":"tool_name","arguments":{...}}</tool>') ||
65
+ normalized.includes("respond with exactly one block and nothing else") ||
66
+ normalized.includes("protocol error.") ||
67
+ normalized.includes("return exactly one zc_packet") ||
68
+ normalized.includes("respond with exactly one xml packet") ||
69
+ normalized.includes("continue the same task using the tool result below") ||
70
+ normalized.includes("do not wrap xml in explanations") ||
71
+ normalized.includes("your previous reply was invalid and was discarded") ||
72
+ normalized.includes("available tools:"));
73
+ }
74
+ export const outputSanitizerModule = {
75
+ sanitizeVisibleModelOutput,
76
+ extractPacketMessage,
77
+ looksLikeInternalControlText
78
+ };
@@ -0,0 +1,17 @@
1
+ type PacketExtractionSuccess = {
2
+ ok: true;
3
+ format: "zc_packet" | "provider_packet";
4
+ packetText: string;
5
+ };
6
+ type PacketExtractionFailure = {
7
+ ok: false;
8
+ code: "no_packet_found" | "multiple_packets_found";
9
+ message: string;
10
+ candidates: string[];
11
+ };
12
+ type PacketExtractionResult = PacketExtractionSuccess | PacketExtractionFailure;
13
+ declare function extractPacketCandidate(rawText: string): PacketExtractionResult;
14
+ export declare const packetExtractorModule: {
15
+ extractPacketCandidate: typeof extractPacketCandidate;
16
+ };
17
+ export type { PacketExtractionFailure, PacketExtractionResult, PacketExtractionSuccess };
@@ -0,0 +1,43 @@
1
+ const CANDIDATE_PATTERNS = [
2
+ {
3
+ format: "zc_packet",
4
+ pattern: /<zc_packet version="1">[\s\S]*?<\/zc_packet>/g
5
+ },
6
+ {
7
+ format: "provider_packet",
8
+ pattern: /<packet\b[^>]*\bmode="(?:final|tool_request|ask_user|fail)"[^>]*>[\s\S]*?<\/packet>/g
9
+ }
10
+ ];
11
+ function extractPacketCandidate(rawText) {
12
+ const candidates = CANDIDATE_PATTERNS.flatMap(({ format, pattern }) => [...rawText.matchAll(pattern)]
13
+ .map((match) => ({
14
+ format,
15
+ packetText: (match[0] ?? "").trim(),
16
+ index: match.index ?? 0
17
+ }))
18
+ .filter((match) => match.packetText)).sort((left, right) => left.index - right.index);
19
+ if (candidates.length === 1) {
20
+ return {
21
+ ok: true,
22
+ format: candidates[0].format,
23
+ packetText: candidates[0].packetText
24
+ };
25
+ }
26
+ if (candidates.length > 1) {
27
+ return {
28
+ ok: false,
29
+ code: "multiple_packets_found",
30
+ message: `Found ${candidates.length} packet candidates in provider output.`,
31
+ candidates: candidates.map((candidate) => candidate.packetText)
32
+ };
33
+ }
34
+ return {
35
+ ok: false,
36
+ code: "no_packet_found",
37
+ message: "Provider output did not contain a recognized packet block.",
38
+ candidates: []
39
+ };
40
+ }
41
+ export const packetExtractorModule = {
42
+ extractPacketCandidate
43
+ };
@@ -0,0 +1,21 @@
1
+ type PacketNormalizationStrategy = "canonical_passthrough" | "canonical_repaired_tool_call_close_tag" | "legacy_packet_v1";
2
+ type PacketNormalizationFailureCode = "unsupported_provider_packet" | "invalid_provider_packet";
3
+ type PacketNormalizationSuccess = {
4
+ ok: true;
5
+ strategy: PacketNormalizationStrategy;
6
+ canonicalPacket: string;
7
+ notes: string[];
8
+ };
9
+ type PacketNormalizationFailure = {
10
+ ok: false;
11
+ strategy: PacketNormalizationStrategy | "none";
12
+ code: PacketNormalizationFailureCode;
13
+ message: string;
14
+ notes: string[];
15
+ };
16
+ type PacketNormalizationResult = PacketNormalizationSuccess | PacketNormalizationFailure;
17
+ declare function normalizeProviderPacket(_providerId: string, extractedCandidate: string): PacketNormalizationResult;
18
+ export declare const packetNormalizerModule: {
19
+ normalizeProviderPacket: typeof normalizeProviderPacket;
20
+ };
21
+ export type { PacketNormalizationFailure, PacketNormalizationFailureCode, PacketNormalizationResult, PacketNormalizationStrategy, PacketNormalizationSuccess };