showrunner-agent-staging 0.5.138-staging.2221 → 0.5.138-staging.2223
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/README.md +1 -1
- package/dist/src/adapter-runner.d.ts +12 -0
- package/dist/src/adapter-runner.js +13 -0
- package/dist/src/adapter.d.ts +13 -1
- package/dist/src/adapters/claude/claude-background-tasks.js +5 -5
- package/dist/src/adapters/codex/codex-run-processes.d.ts +12 -1
- package/dist/src/adapters/codex/codex-run-processes.js +35 -9
- package/dist/src/agent-tools.d.ts +2 -2
- package/dist/src/client.d.ts +1 -1
- package/dist/src/client.js +2 -2
- package/dist/src/cloud/cloud-server.js +1 -0
- package/dist/src/cloud/cloud-tool-server.d.ts +8 -4
- package/dist/src/cloud/cloud-tool-server.js +103 -51
- package/dist/src/file-limits.d.ts +1 -0
- package/dist/src/file-limits.js +2 -0
- package/dist/src/file-tools.d.ts +38 -0
- package/dist/src/file-tools.js +135 -26
- package/dist/src/protocol.d.ts +20 -0
- package/dist/src/protocol.js +5 -0
- package/dist/src/render-tools.d.ts +1 -1
- package/dist/src/render-tools.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ The connector resolves its login-shell environment once before loading its adapt
|
|
|
84
84
|
Codex and Claude expose `upload_file` through the same connector tool registry. For files already
|
|
85
85
|
on disk, pass `localPath`, `fileName`, and `mimeType`; for small text output, pass `content` instead.
|
|
86
86
|
Paths resolve against the connector's `--cwd`. Directories, empty files, and oversized files are refused.
|
|
87
|
-
The connector size limit is `maxConnectorFileBytes` in `src/
|
|
87
|
+
The connector size limit is `maxConnectorFileBytes` in `src/file-limits.ts`, matching the API ceiling
|
|
88
88
|
`AgentFileTransferService.MaxFileBytes` in the .NET adapter. File types follow the human upload policy: any type is accepted, and the API derives the stored
|
|
89
89
|
MIME type from the real filename using `EnhancedMimeTypes.GetMimeType`.
|
|
90
90
|
|
|
@@ -201,6 +201,18 @@ export declare class InvocationAdapterClient implements AdapterClient {
|
|
|
201
201
|
attemptCount: number;
|
|
202
202
|
}>;
|
|
203
203
|
createFileDownloadLink(assetId: string): ReturnType<ExternalAgentClient["createFileDownloadLink"]>;
|
|
204
|
+
createFileUploadLink(input: {
|
|
205
|
+
fileName: string;
|
|
206
|
+
mimeType: string;
|
|
207
|
+
byteLength: number;
|
|
208
|
+
folderId?: string | null;
|
|
209
|
+
folderName?: string;
|
|
210
|
+
versionOfAssetId?: string;
|
|
211
|
+
versionNote?: string;
|
|
212
|
+
}): ReturnType<ExternalAgentClient["createFileUploadLink"]>;
|
|
213
|
+
completeFileUpload(assetId: string, input: {
|
|
214
|
+
uploadGrantId: string;
|
|
215
|
+
}): ReturnType<ExternalAgentClient["completeFileUpload"]>;
|
|
204
216
|
readVideoFrame(assetId: string, time: number, signal: AbortSignal): Promise<Uint8Array>;
|
|
205
217
|
sendReaction(messageId: string, emoji: string): Promise<void>;
|
|
206
218
|
readNote(noteId: string): Promise<Note>;
|
|
@@ -1156,6 +1156,19 @@ export class InvocationAdapterClient {
|
|
|
1156
1156
|
commandId: this.#next("file.download_link.create"),
|
|
1157
1157
|
});
|
|
1158
1158
|
}
|
|
1159
|
+
createFileUploadLink(input) {
|
|
1160
|
+
return this.#client.createFileUploadLink(this.#event.invocation.id, {
|
|
1161
|
+
commandId: commandId(this.#commandNamespace, `file.upload_link.create:${++this.#sequence}:${randomUUID()}`),
|
|
1162
|
+
...input,
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
completeFileUpload(assetId, input) {
|
|
1166
|
+
this.#sequence += 1;
|
|
1167
|
+
return this.#client.completeFileUpload(this.#event.invocation.id, assetId, {
|
|
1168
|
+
commandId: commandId(this.#commandNamespace, `file.upload.complete:${input.uploadGrantId}`),
|
|
1169
|
+
...input,
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1159
1172
|
async readVideoFrame(assetId, time, signal) {
|
|
1160
1173
|
return this.#client.readVideoFrame(this.#event.invocation.id, assetId, time, signal);
|
|
1161
1174
|
}
|
package/dist/src/adapter.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { AgentTranscriptItem, AgentTranscriptTimingsItem } from "@showrunne
|
|
|
11
11
|
import type { CreateSurfacePieceRequest } from "@showrunner/agent-contracts/agent-write-piece-dtos";
|
|
12
12
|
import { type FileUploadInput } from "./client.js";
|
|
13
13
|
import type { ContextNoteSearch, ContextChats, ContextRootContents, ContextAgents, ContextAccessSummary, ContextFileSearch, ContextTodos, ContextNotes, ContextFolders, ContextFolderContents, VersionStackPage } from "./protocol.js";
|
|
14
|
-
import type { ActivityOutcome, ActivityType, AgentAvailability, AgentEvent, AgentInputResponse, ApprovalDecision, ApprovalRiskLevel, CommandResponse, ContextAsset, ContextPage, FileDownloadLink, OutputMessagePiece, QuestionSelectionType } from "./protocol.js";
|
|
14
|
+
import type { ActivityOutcome, ActivityType, AgentAvailability, AgentEvent, AgentInputResponse, ApprovalDecision, ApprovalRiskLevel, CommandResponse, ContextAsset, ContextPage, FileDownloadLink, FileUploadLink, OutputMessagePiece, QuestionSelectionType } from "./protocol.js";
|
|
15
15
|
import type { Note, TextAttachment } from "./protocol.js";
|
|
16
16
|
import type { PlanUsageReport } from "./plan-usage.js";
|
|
17
17
|
import { type RunScope, type RunScopeReach } from "./run-folders.js";
|
|
@@ -267,6 +267,18 @@ export interface AdapterClient {
|
|
|
267
267
|
getRender(jobId: string, waitSeconds: number, signal?: AbortSignal): Promise<MediaOperationJob>;
|
|
268
268
|
cancelRender(jobId: string, signal?: AbortSignal): Promise<MediaOperationJob>;
|
|
269
269
|
createFileDownloadLink(assetId: string): Promise<FileDownloadLink>;
|
|
270
|
+
createFileUploadLink(input: {
|
|
271
|
+
fileName: string;
|
|
272
|
+
mimeType: string;
|
|
273
|
+
byteLength: number;
|
|
274
|
+
folderId?: string | null;
|
|
275
|
+
folderName?: string;
|
|
276
|
+
versionOfAssetId?: string;
|
|
277
|
+
versionNote?: string;
|
|
278
|
+
}): Promise<FileUploadLink>;
|
|
279
|
+
completeFileUpload(assetId: string, input: {
|
|
280
|
+
uploadGrantId: string;
|
|
281
|
+
}): Promise<CommandResponse>;
|
|
270
282
|
readVideoFrame(assetId: string, time: number, signal: AbortSignal): Promise<Uint8Array>;
|
|
271
283
|
sendReaction?(messageId: string, emoji: string): Promise<void>;
|
|
272
284
|
readNote(noteId: string): Promise<Note>;
|
|
@@ -78,11 +78,11 @@ export function claudeBackgroundWorkEnvironment(environment) {
|
|
|
78
78
|
CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1",
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
export const claudeBackgroundWorkGuidance = "For a command that may take more than a minute, such as a build, a full test run
|
|
82
|
-
"run it with run_in_background and end your turn with a short note on what is running;
|
|
83
|
-
"your live card, not in the chat. You are woken when it finishes, so post the result then
|
|
84
|
-
"or polling.
|
|
85
|
-
"
|
|
81
|
+
export const claudeBackgroundWorkGuidance = "For a command that may take more than a minute, such as a build, a full test run, a screen recording, a " +
|
|
82
|
+
"render or a server, run it with run_in_background and end your turn with a short note on what is running; " +
|
|
83
|
+
"the note shows on your live card, not in the chat. You are woken when it finishes, so post the result then " +
|
|
84
|
+
"instead of sleeping or polling. Work you detach with nohup, setsid, disown or a trailing & isn't tracked: it " +
|
|
85
|
+
"doesn't keep your card up, can't be stopped from it, and nothing wakes you when it ends. " +
|
|
86
86
|
"Stop a server or job you started by stopping its background task, never with pkill -f or killall: " +
|
|
87
87
|
"a name or pattern also stops the owner's own programs that match it. " +
|
|
88
88
|
"For anything to do later or on a repeat, such as checking again in 20 minutes or every morning, " +
|
|
@@ -27,9 +27,20 @@ export declare function processesStartedBetween(before: readonly EnvironmentProc
|
|
|
27
27
|
* Each exact pid/start-time identity gets SIGTERM, then SIGKILL after `graceMilliseconds`.
|
|
28
28
|
* Returns the commands it stopped.
|
|
29
29
|
*/
|
|
30
|
-
export declare function stopCodexThreadProcesses(owned: readonly OwnedProcess[], options?: Partial<ProcessTable>
|
|
30
|
+
export declare function stopCodexThreadProcesses(owned: readonly OwnedProcess[], options?: Partial<ProcessTable> & {
|
|
31
|
+
clock?: {
|
|
32
|
+
now: () => number;
|
|
33
|
+
sleep: (milliseconds: number) => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<{
|
|
31
36
|
stopped: string[];
|
|
32
37
|
remaining: OwnedProcess[];
|
|
33
38
|
}>;
|
|
34
39
|
/** This user's processes with their environments: `ps -E` on macOS, /proc on Linux. */
|
|
35
40
|
export declare function listProcessEnvironments(): Promise<EnvironmentProcess[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Joins `ps -E` output with a `ps` listing of the same processes without environments, by pid and
|
|
43
|
+
* start time. The two listings are taken separately, so a process only the first one saw is kept, named
|
|
44
|
+
* by its pid.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseMacProcessListings(withEnvironment: string, withoutEnvironment: string): EnvironmentProcess[];
|
|
@@ -23,6 +23,7 @@ export function processesStartedBetween(before, after) {
|
|
|
23
23
|
* Returns the commands it stopped.
|
|
24
24
|
*/
|
|
25
25
|
export async function stopCodexThreadProcesses(owned, options = {}) {
|
|
26
|
+
const clock = options.clock ?? { now: () => Date.now(), sleep: (milliseconds) => new Promise(resolve => setTimeout(resolve, milliseconds)) };
|
|
26
27
|
const kill = options.kill ?? ((pid, signal) => { process.kill(pid, signal); });
|
|
27
28
|
const identities = new Set(owned.map(candidate => `${candidate.pid}:${candidate.startTime}`));
|
|
28
29
|
const started = (await (options.list ?? listProcessEnvironments)())
|
|
@@ -41,15 +42,22 @@ export async function stopCodexThreadProcesses(owned, options = {}) {
|
|
|
41
42
|
signal(target, "SIGTERM");
|
|
42
43
|
const graceMilliseconds = options.graceMilliseconds ?? 2_000;
|
|
43
44
|
if (graceMilliseconds > 0)
|
|
44
|
-
await
|
|
45
|
+
await clock.sleep(graceMilliseconds);
|
|
45
46
|
const remaining = (await (options.list ?? listProcessEnvironments)())
|
|
46
47
|
.filter(candidate => identities.has(`${candidate.pid}:${candidate.startTime}`));
|
|
47
48
|
for (const target of remaining)
|
|
48
49
|
signal(target, "SIGKILL");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// A killed process can still be listed until its parent reaps it, so survivors are counted once that
|
|
51
|
+
// has had the grace period to happen.
|
|
52
|
+
const deadline = clock.now() + graceMilliseconds;
|
|
53
|
+
for (;;) {
|
|
54
|
+
const surviving = (await (options.list ?? listProcessEnvironments)())
|
|
55
|
+
.filter(candidate => identities.has(`${candidate.pid}:${candidate.startTime}`))
|
|
56
|
+
.map(({ pid, startTime, command }) => ({ pid, startTime, command }));
|
|
57
|
+
if (surviving.length === 0 || clock.now() >= deadline)
|
|
58
|
+
return { stopped: started.map(target => target.command), remaining: surviving };
|
|
59
|
+
await clock.sleep(50);
|
|
60
|
+
}
|
|
53
61
|
}
|
|
54
62
|
/** This user's processes with their environments: `ps -E` on macOS, /proc on Linux. */
|
|
55
63
|
export async function listProcessEnvironments() {
|
|
@@ -57,13 +65,31 @@ export async function listProcessEnvironments() {
|
|
|
57
65
|
return listLinuxProcessEnvironments();
|
|
58
66
|
if (process.platform !== "darwin" || process.getuid === undefined)
|
|
59
67
|
return [];
|
|
60
|
-
const
|
|
61
|
-
|
|
68
|
+
const user = String(process.getuid());
|
|
69
|
+
// `ps -E` prints the environment after the command line, on the same line, so the command line
|
|
70
|
+
// itself comes from a listing without it: a command's name never carries a secret from its environment.
|
|
71
|
+
const [withEnvironment, withoutEnvironment] = await Promise.all([
|
|
72
|
+
run("ps", ["-E", "-ww", "-U", user, "-o", "pid=,pgid=,lstart=,command="]),
|
|
73
|
+
run("ps", ["-ww", "-U", user, "-o", "pid=,lstart=,command="]),
|
|
74
|
+
]);
|
|
75
|
+
return parseMacProcessListings(withEnvironment, withoutEnvironment);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Joins `ps -E` output with a `ps` listing of the same processes without environments, by pid and
|
|
79
|
+
* start time. The two listings are taken separately, so a process only the first one saw is kept, named
|
|
80
|
+
* by its pid.
|
|
81
|
+
*/
|
|
82
|
+
export function parseMacProcessListings(withEnvironment, withoutEnvironment) {
|
|
83
|
+
const commands = new Map(withoutEnvironment.split("\n").flatMap((line) => {
|
|
84
|
+
const match = /^\s*(\d+)\s+(.{24})\s+(.*)$/u.exec(line);
|
|
85
|
+
return match === null ? [] : [[`${match[1]}:${match[2]}`, match[3] ?? ""]];
|
|
86
|
+
}));
|
|
87
|
+
return withEnvironment.split("\n").flatMap((line) => {
|
|
62
88
|
const match = /^\s*(\d+)\s+(\d+)\s+(.{24})\s+(.*)$/u.exec(line);
|
|
63
89
|
if (match === null)
|
|
64
90
|
return [];
|
|
65
|
-
|
|
66
|
-
return [{ pid: Number(match[1]), pgid: Number(match[2]), startTime: match[3] ?? "", command:
|
|
91
|
+
const command = commands.get(`${match[1]}:${match[3]}`) ?? `process ${match[1]}`;
|
|
92
|
+
return [{ pid: Number(match[1]), pgid: Number(match[2]), startTime: match[3] ?? "", command: command.slice(0, 200), environment: match[4] ?? "" }];
|
|
67
93
|
});
|
|
68
94
|
}
|
|
69
95
|
async function listLinuxProcessEnvironments() {
|
|
@@ -186,8 +186,8 @@ export declare const agentToolSchemas: {
|
|
|
186
186
|
final: "final";
|
|
187
187
|
}>>;
|
|
188
188
|
delivery: z.ZodOptional<z.ZodObject<{
|
|
189
|
-
folderId: z.ZodOptional<z.ZodString>;
|
|
190
189
|
versionOfAssetId: z.ZodOptional<z.ZodString>;
|
|
190
|
+
folderId: z.ZodOptional<z.ZodString>;
|
|
191
191
|
versionNote: z.ZodOptional<z.ZodString>;
|
|
192
192
|
}, z.core.$strip>>;
|
|
193
193
|
idempotencyKey: z.ZodString;
|
|
@@ -694,8 +694,8 @@ export declare const agentToolDefinitions: {
|
|
|
694
694
|
final: "final";
|
|
695
695
|
}>>;
|
|
696
696
|
delivery: z.ZodOptional<z.ZodObject<{
|
|
697
|
-
folderId: z.ZodOptional<z.ZodString>;
|
|
698
697
|
versionOfAssetId: z.ZodOptional<z.ZodString>;
|
|
698
|
+
folderId: z.ZodOptional<z.ZodString>;
|
|
699
699
|
versionNote: z.ZodOptional<z.ZodString>;
|
|
700
700
|
}, z.core.$strip>>;
|
|
701
701
|
idempotencyKey: z.ZodString;
|
package/dist/src/client.d.ts
CHANGED
|
@@ -102,7 +102,6 @@ export interface ExternalAgentClientOptions {
|
|
|
102
102
|
cloudSetupState?: AdapterStateStore;
|
|
103
103
|
cloudSetup?: (request: CloudSetupRequested, signal: AbortSignal) => Promise<boolean>;
|
|
104
104
|
}
|
|
105
|
-
export declare const maxConnectorFileBytes: number;
|
|
106
105
|
/** Consecutive heartbeat failures tolerated before forcing the connection closed to engage reconnect. */
|
|
107
106
|
export declare const heartbeatFailureThreshold = 3;
|
|
108
107
|
/**
|
|
@@ -176,6 +175,7 @@ declare const cloudIdentitySchema: z.ZodObject<{
|
|
|
176
175
|
cloudConnectionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
177
176
|
displayName: z.ZodString;
|
|
178
177
|
canRequestSignIn: z.ZodDefault<z.ZodBoolean>;
|
|
178
|
+
usesInlineFileUpload: z.ZodDefault<z.ZodBoolean>;
|
|
179
179
|
}, z.core.$strip>;
|
|
180
180
|
export type CloudIdentity = z.infer<typeof cloudIdentitySchema>;
|
|
181
181
|
export declare class ExternalAgentClient {
|
package/dist/src/client.js
CHANGED
|
@@ -13,6 +13,7 @@ import { sleepWakeMonitor } from "./wake-monitor.js";
|
|
|
13
13
|
import { freeStorageBytes } from "./free-storage.js";
|
|
14
14
|
import { resolveAdapterRuntimeOptions } from "./adapter.js";
|
|
15
15
|
import { accountCommandSchema } from "./accounts/account-protocol.js";
|
|
16
|
+
import { maxConnectorFileBytes } from "./file-limits.js";
|
|
16
17
|
import { agentEventSchema, cloudInputResponseSchema, commandResponseSchema, contextPageSchema, contextAssetSchema, fileDownloadLinkSchema, fileUploadLinkSchema, noteCommandResponseSchema, noteUpdateConflictSchema, connectorOperationResultSchema, pairRequestSchema, pairResponseSchema, protocolVersion, refreshResponseSchema, registerConnectorResultSchema, serverEventTypes, } from "./protocol.js";
|
|
17
18
|
const appResultSchema = z.object({
|
|
18
19
|
app: z.string(),
|
|
@@ -69,8 +70,6 @@ const externalItemReadResultSchema = z.object({
|
|
|
69
70
|
content: z.string().max(131_072),
|
|
70
71
|
isError: z.boolean(),
|
|
71
72
|
});
|
|
72
|
-
// AgentFileTransferService.MaxFileBytes is the server upload ceiling: one presigned S3 PUT.
|
|
73
|
-
export const maxConnectorFileBytes = 5 * 1024 * 1024 * 1024;
|
|
74
73
|
/** Consecutive heartbeat failures tolerated before forcing the connection closed to engage reconnect. */
|
|
75
74
|
export const heartbeatFailureThreshold = 3;
|
|
76
75
|
/** Bounds a provider CLI's model probe so an unresponsive CLI delays connect rather than blocking it. */
|
|
@@ -306,6 +305,7 @@ const cloudIdentitySchema = z.object({
|
|
|
306
305
|
cloudConnectionId: z.string().uuid().nullish(),
|
|
307
306
|
displayName: z.string().min(1),
|
|
308
307
|
canRequestSignIn: z.boolean().default(false),
|
|
308
|
+
usesInlineFileUpload: z.boolean().default(false),
|
|
309
309
|
});
|
|
310
310
|
export class ExternalAgentClient {
|
|
311
311
|
#installationId;
|
|
@@ -516,6 +516,7 @@ export function createCloudServer(options) {
|
|
|
516
516
|
authenticate,
|
|
517
517
|
resolveTurn,
|
|
518
518
|
canRequestSignIn: (principal) => principal.identity.canRequestSignIn,
|
|
519
|
+
usesInlineFileUpload: (principal) => principal.identity.usesInlineFileUpload,
|
|
519
520
|
answerWaitMilliseconds: options.answerWaitMilliseconds,
|
|
520
521
|
logger,
|
|
521
522
|
redact: (principal, text) => text.replaceAll(principal.token, "[REDACTED]"),
|
|
@@ -2,6 +2,7 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import type { AdapterLogger, AgentInvocationContext } from "../adapter.js";
|
|
4
4
|
import { type AgentToolName } from "../agent-tools.js";
|
|
5
|
+
import { type CloudUploadToolName } from "../file-tools.js";
|
|
5
6
|
/**
|
|
6
7
|
* The argument every turn-bound cloud tool call carries: the turn id from the wake-up that started
|
|
7
8
|
* the agent's run. A cloud agent may be woken by several chats at once, and nothing else in a call
|
|
@@ -83,6 +84,8 @@ export type CloudToolServerOptions<Principal> = {
|
|
|
83
84
|
answerTestTurn?(principal: Principal, turnId: string): Promise<boolean>;
|
|
84
85
|
/** Whether this agent is offered request_sign_in: only a Grok Bot the server says may raise its card. */
|
|
85
86
|
canRequestSignIn?(principal: Principal): boolean;
|
|
87
|
+
/** Whether this agent must keep the inline upload fallback because signed PUT support is unproven. */
|
|
88
|
+
usesInlineFileUpload?(principal: Principal): boolean;
|
|
86
89
|
/** The host's existing logger receives static diagnostics for unexpected HTTP failures. */
|
|
87
90
|
logger?: AdapterLogger;
|
|
88
91
|
maxRequestBytes?: number;
|
|
@@ -96,12 +99,13 @@ type JsonObjectSchema = {
|
|
|
96
99
|
properties?: Record<string, Record<string, unknown>>;
|
|
97
100
|
required?: string[];
|
|
98
101
|
};
|
|
99
|
-
|
|
100
|
-
export declare const cloudToolDefinitions: {
|
|
102
|
+
type CloudToolDefinition = {
|
|
101
103
|
name: string;
|
|
102
104
|
description: string;
|
|
103
105
|
inputSchema: JsonObjectSchema;
|
|
104
|
-
}
|
|
106
|
+
};
|
|
107
|
+
declare const acknowledgeNoReplyName = "acknowledge_no_reply_needed";
|
|
108
|
+
export declare const cloudToolDefinitions: CloudToolDefinition[];
|
|
105
109
|
/** Told on every wake: the run has everything the agent's own app chat has, so work never moves there. */
|
|
106
110
|
export declare const appChatRule: string;
|
|
107
111
|
export declare const getChatUpdatesTool: {
|
|
@@ -152,7 +156,7 @@ export declare function createMcpRequestHandler<Principal>(options: McpRequestHa
|
|
|
152
156
|
declare const askQuestionName = "ask_question";
|
|
153
157
|
declare const getChatUpdatesName = "get_chat_updates";
|
|
154
158
|
type ProactiveToolName = "send_messages" | typeof getChatUpdatesName;
|
|
155
|
-
type TurnCloudToolName = AgentToolName | typeof askQuestionName | typeof acknowledgeNoReplyName;
|
|
159
|
+
type TurnCloudToolName = AgentToolName | CloudUploadToolName | typeof askQuestionName | typeof acknowledgeNoReplyName;
|
|
156
160
|
type CloudToolName = TurnCloudToolName | typeof getChatUpdatesName;
|
|
157
161
|
/** A call runs only a tool this agent was listed; any other name is unknown, even a shared tool's. */
|
|
158
162
|
export declare function cloudToolName(value: string, listed: readonly {
|
|
@@ -6,13 +6,13 @@ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprot
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { MessagePurposeType } from "../protocol.js";
|
|
8
8
|
import { messageToolSchemas } from "../message-tools.js";
|
|
9
|
-
import { approvalDeclinedMessage, declinedEffectKey, inputRequestLifetimeSeconds, providerResourceId, questionExpiredMessage } from "../adapter.js";
|
|
9
|
+
import { approvalDeclinedMessage, approvalExpiredMessage, approvalRefusalMessage, declinedEffectKey, inputRequestLifetimeSeconds, providerResourceId, questionExpiredMessage } from "../adapter.js";
|
|
10
10
|
import { callAgentTool } from "../agent-tool-call.js";
|
|
11
11
|
import { peopleMessagingRule } from "../email-tools.js";
|
|
12
12
|
import { askingRule, coreGuidance, grokSignInRule, guidanceForTools } from "../output-vocabulary.js";
|
|
13
|
-
import { agentToolDefinitions, agentToolName, capabilityForAgentTool, executeAgentTool, signInResult } from "../agent-tools.js";
|
|
13
|
+
import { agentToolDefinitions, agentToolName, authorizeAgentToolApproval, capabilityForAgentTool, executeAgentTool, signInResult } from "../agent-tools.js";
|
|
14
14
|
import { ExternalAgentError } from "../client.js";
|
|
15
|
-
import { createFileDownloadLinkResult, fileDownloadLinkTool, fileToolEffect, fileUploadOrganizationGuidance, uploadMimeTypeGuidance, } from "../file-tools.js";
|
|
15
|
+
import { cloudUploadToolDefinitions, createFileDownloadLinkResult, executeCloudUploadTool, fileDownloadLinkTool, fileToolEffect, fileUploadOrganizationGuidance, finishUploadSchema, startUploadSchema, uploadMimeTypeGuidance, } from "../file-tools.js";
|
|
16
16
|
import { isTransientFailure } from "../handler.js";
|
|
17
17
|
import { showrunnerToolActivity } from "../tool-activity.js";
|
|
18
18
|
import { redactKnownSecrets } from "../known-secrets.js";
|
|
@@ -27,33 +27,26 @@ export const cloudTurnArgument = "turn";
|
|
|
27
27
|
const maxInlineUploadBytes = 512 * 1024 * 1024;
|
|
28
28
|
const defaultMaxRequestBytes = Math.ceil(maxInlineUploadBytes / 3) * 4 + 1024 * 1024;
|
|
29
29
|
const turnSchema = z.string().uuid();
|
|
30
|
-
const
|
|
30
|
+
const inlineUploadDescription = "Upload a file you produced or that someone in the chat asked for into this Showrunner stream, optionally into a folder. "
|
|
31
31
|
+ "Send its bytes in content: text as is, and binary files (images, PDFs, .xlsx spreadsheets, MP4 video) "
|
|
32
32
|
+ "base64-encoded with encoding \"base64\". "
|
|
33
33
|
+ "It becomes a real workspace asset the owner can open, move, and mark up. "
|
|
34
34
|
+ "Prefer this over dumping a long document, diff, CSV, or log into your reply. "
|
|
35
35
|
+ fileUploadOrganizationGuidance + " "
|
|
36
36
|
+ uploadMimeTypeGuidance;
|
|
37
|
-
const cloudUploadMimeTypeDescription = uploadMimeTypeGuidance;
|
|
38
37
|
/**
|
|
39
38
|
* The shared Showrunner tools. All ask for their turn except send_messages, which also serves an
|
|
40
39
|
* agent's own scheduled run. Where a shared description points at the agent's own disk, a cloud
|
|
41
40
|
* agent reads what this server accepts.
|
|
42
41
|
*/
|
|
43
|
-
const adaptedCloudToolDefinitions = agentToolDefinitions.
|
|
42
|
+
const adaptedCloudToolDefinitions = agentToolDefinitions.flatMap((tool) => {
|
|
43
|
+
if (tool.name === "upload_file")
|
|
44
|
+
return cloudUploadToolDefinitions.map((upload) => withTurnArgument({ ...upload, inputSchema: upload.inputSchema }));
|
|
44
45
|
const schema = tool.inputSchema;
|
|
45
46
|
const properties = { ...schema.properties };
|
|
46
47
|
const required = [...(schema.required ?? [])];
|
|
47
48
|
let description = tool.description;
|
|
48
|
-
if (tool.name === "
|
|
49
|
-
delete properties.localPath;
|
|
50
|
-
if (!required.includes("content"))
|
|
51
|
-
required.push("content");
|
|
52
|
-
properties.mimeType = { ...properties.mimeType, description: cloudUploadMimeTypeDescription };
|
|
53
|
-
properties.content = { ...properties.content, description: "The file's bytes. Plain text unless encoding is base64." };
|
|
54
|
-
description = cloudUploadDescription;
|
|
55
|
-
}
|
|
56
|
-
else if (tool.name === "download_file") {
|
|
49
|
+
if (tool.name === "download_file") {
|
|
57
50
|
description = "Get a short-lived link to a Showrunner file — a video, recording, image, PDF, or any other attachment — "
|
|
58
51
|
+ "and fetch it with your own tools to see what it contains. Cite the file back with its assetId as an "
|
|
59
52
|
+ "asset_reference piece, never the link.";
|
|
@@ -77,28 +70,51 @@ const adaptedCloudToolDefinitions = agentToolDefinitions.map((tool) => {
|
|
|
77
70
|
}
|
|
78
71
|
const adapted = { ...tool, description, inputSchema: { ...tool.inputSchema, properties, required } };
|
|
79
72
|
if (tool.name !== "send_messages")
|
|
80
|
-
return withTurnArgument(adapted);
|
|
81
|
-
return {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
73
|
+
return [withTurnArgument(adapted)];
|
|
74
|
+
return [{
|
|
75
|
+
...adapted,
|
|
76
|
+
description: `${description} For your own scheduled run, set scheduledRun to true and omit turn. Choose exactly one destination from get_chat_updates: set streamId only when an available chat has the same topic, or, when canStartNewChat is true, omit streamId and set newChatTitle to start a new chat with a short topic title. If you pass neither, the send fails; it never picks the most recent chat. Shared chats require a Showrunner scheduled task and its turn. A shared Claude connection must include agentInstallationId.`,
|
|
77
|
+
inputSchema: {
|
|
78
|
+
...adapted.inputSchema,
|
|
79
|
+
properties: {
|
|
80
|
+
[cloudTurnArgument]: {
|
|
81
|
+
type: "string",
|
|
82
|
+
format: "uuid",
|
|
83
|
+
description: "The turn id from a Showrunner wake-up. Omit only for your own scheduled run.",
|
|
84
|
+
},
|
|
85
|
+
...properties,
|
|
86
|
+
scheduledRun: { type: "boolean", const: true, description: "Set true only for your own scheduled run without a Showrunner turn. A wake reply must supply turn instead." },
|
|
87
|
+
streamId: { type: "string", format: "uuid", description: "For a turnless scheduled run, an existing private destination from get_chat_updates.availableChats. Use it only when that chat has the same topic. Omit only when starting a new chat with newChatTitle." },
|
|
88
|
+
newChatTitle: { type: "string", minLength: 1, maxLength: 60, description: "A short topic title for a new chat. Use only when get_chat_updates returned canStartNewChat true and no available chat has the same topic; omit when streamId names an existing chat." },
|
|
89
|
+
agentInstallationId: { type: "string", format: "uuid", description: "Required on a shared Claude connection: the authorized agent sending the message." },
|
|
91
90
|
},
|
|
92
|
-
|
|
93
|
-
scheduledRun: { type: "boolean", const: true, description: "Set true only for your own scheduled run without a Showrunner turn. A wake reply must supply turn instead." },
|
|
94
|
-
streamId: { type: "string", format: "uuid", description: "For a turnless scheduled run, an existing private destination from get_chat_updates.availableChats. Use it only when that chat has the same topic. Omit only when starting a new chat with newChatTitle." },
|
|
95
|
-
newChatTitle: { type: "string", minLength: 1, maxLength: 60, description: "A short topic title for a new chat. Use only when get_chat_updates returned canStartNewChat true and no available chat has the same topic; omit when streamId names an existing chat." },
|
|
96
|
-
agentInstallationId: { type: "string", format: "uuid", description: "Required on a shared Claude connection: the authorized agent sending the message." },
|
|
91
|
+
required,
|
|
97
92
|
},
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
};
|
|
93
|
+
}];
|
|
101
94
|
});
|
|
95
|
+
const inlineUploadToolDefinition = (() => {
|
|
96
|
+
const tool = agentToolDefinitions.find((candidate) => candidate.name === "upload_file");
|
|
97
|
+
if (tool === undefined)
|
|
98
|
+
throw new Error("upload_file tool is missing");
|
|
99
|
+
const schema = tool.inputSchema;
|
|
100
|
+
const properties = { ...schema.properties };
|
|
101
|
+
delete properties.localPath;
|
|
102
|
+
properties.mimeType = { ...properties.mimeType, description: uploadMimeTypeGuidance };
|
|
103
|
+
properties.content = { ...properties.content, description: "The file's bytes. Plain text unless encoding is base64." };
|
|
104
|
+
return withTurnArgument({
|
|
105
|
+
...tool,
|
|
106
|
+
description: inlineUploadDescription,
|
|
107
|
+
inputSchema: {
|
|
108
|
+
...schema,
|
|
109
|
+
properties,
|
|
110
|
+
required: [...new Set([...(schema.required ?? []), "content"])].filter((key) => key !== "localPath"),
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
})();
|
|
114
|
+
const linkAwareInlineUploadToolDefinition = {
|
|
115
|
+
...inlineUploadToolDefinition,
|
|
116
|
+
description: `${inlineUploadToolDefinition.description} For a file on disk, use start_upload instead.`,
|
|
117
|
+
};
|
|
102
118
|
const acknowledgeNoReplyName = "acknowledge_no_reply_needed";
|
|
103
119
|
const acknowledgeNoReplySchema = z.object({ messageId: z.string().uuid() });
|
|
104
120
|
export const cloudToolDefinitions = [
|
|
@@ -213,8 +229,12 @@ export function createCloudToolHandler(options) {
|
|
|
213
229
|
maxRequestBytes: options.maxRequestBytes ?? defaultMaxRequestBytes,
|
|
214
230
|
createServer: (principal, disconnected) => {
|
|
215
231
|
const setupTools = options.setupTools ?? [];
|
|
232
|
+
const sharedWithoutLinkUploads = cloudToolDefinitions.filter((tool) => tool.name !== startUploadName && tool.name !== finishUploadName);
|
|
233
|
+
const uploadTools = options.usesInlineFileUpload?.(principal) === true
|
|
234
|
+
? [...sharedWithoutLinkUploads, inlineUploadToolDefinition]
|
|
235
|
+
: [...cloudToolDefinitions, linkAwareInlineUploadToolDefinition];
|
|
216
236
|
const tools = [
|
|
217
|
-
...
|
|
237
|
+
...uploadTools,
|
|
218
238
|
...(options.canRequestSignIn?.(principal) === true ? [grokSignInToolDefinition] : []),
|
|
219
239
|
askQuestionTool,
|
|
220
240
|
getChatUpdatesTool,
|
|
@@ -352,12 +372,15 @@ export function createMcpRequestHandler(options) {
|
|
|
352
372
|
}
|
|
353
373
|
const askQuestionName = "ask_question";
|
|
354
374
|
const getChatUpdatesName = "get_chat_updates";
|
|
375
|
+
const startUploadName = "start_upload";
|
|
376
|
+
const finishUploadName = "finish_upload";
|
|
355
377
|
/** A call runs only a tool this agent was listed; any other name is unknown, even a shared tool's. */
|
|
356
378
|
export function cloudToolName(value, listed) {
|
|
357
379
|
const name = value.includes("__") ? value.slice(value.lastIndexOf("__") + 2) : value;
|
|
358
380
|
if (!listed.some((tool) => tool.name === name))
|
|
359
381
|
return undefined;
|
|
360
|
-
if (name === askQuestionName || name === getChatUpdatesName || name === acknowledgeNoReplyName
|
|
382
|
+
if (name === askQuestionName || name === getChatUpdatesName || name === acknowledgeNoReplyName ||
|
|
383
|
+
name === startUploadName || name === finishUploadName)
|
|
361
384
|
return name;
|
|
362
385
|
return agentToolName(value);
|
|
363
386
|
}
|
|
@@ -393,7 +416,8 @@ async function callCloudTool(options, principal, listed, requestedName, input, s
|
|
|
393
416
|
return failure({ error: "unknown_turn", message: "That turn has ended or isn't yours. Wait for the next Showrunner wake-up." });
|
|
394
417
|
}
|
|
395
418
|
const { turn, held } = resolved;
|
|
396
|
-
const refusal = cloudRefusal(name, toolInput)
|
|
419
|
+
const refusal = cloudRefusal(name, toolInput, listed.some((tool) => tool.name === startUploadName) &&
|
|
420
|
+
listed.some((tool) => tool.name === finishUploadName));
|
|
397
421
|
if (refusal !== undefined) {
|
|
398
422
|
return failure(refusal);
|
|
399
423
|
}
|
|
@@ -639,9 +663,13 @@ function startCall(turn, name, input, running, key, downloadReceipt) {
|
|
|
639
663
|
};
|
|
640
664
|
const result = currentCall.run(entry, async () => {
|
|
641
665
|
turn.signal.throwIfAborted();
|
|
642
|
-
const step = name === askQuestionName
|
|
643
|
-
|
|
644
|
-
|
|
666
|
+
const step = name === askQuestionName
|
|
667
|
+
? { label: "Asking a question", type: "waiting" }
|
|
668
|
+
: name === startUploadName || name === finishUploadName
|
|
669
|
+
? { label: "Uploading a file", type: "tool" }
|
|
670
|
+
: name === acknowledgeNoReplyName
|
|
671
|
+
? { label: "Finishing without a reply", type: "default" }
|
|
672
|
+
: showrunnerToolActivity(name);
|
|
645
673
|
if (step.type !== "default" && step.type !== "waiting")
|
|
646
674
|
turn.context.client.reply.clearSettled();
|
|
647
675
|
// From the turn, the tool and its input: the same call repeated after a restart is the same step.
|
|
@@ -664,15 +692,17 @@ function startCall(turn, name, input, running, key, downloadReceipt) {
|
|
|
664
692
|
try {
|
|
665
693
|
const done = name === askQuestionName
|
|
666
694
|
? await askQuestion(turn, input)
|
|
667
|
-
: name ===
|
|
668
|
-
?
|
|
669
|
-
:
|
|
670
|
-
?
|
|
671
|
-
:
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
695
|
+
: name === startUploadName || name === finishUploadName
|
|
696
|
+
? await callCloudUploadTool(turn, name, input, activityId)
|
|
697
|
+
: name === acknowledgeNoReplyName
|
|
698
|
+
? acknowledgeNoReply(turn, input)
|
|
699
|
+
: downloadReceipt === undefined
|
|
700
|
+
? await callAgentTool(turn.context, turn.agentName, name, input, undefined, turn.signal, activityId, name === "request_sign_in" ? grokSignInExecutor(input) : cloudExecutor)
|
|
701
|
+
: turn.context.declinedHostToolEffects?.has(declinedEffectKey({
|
|
702
|
+
capability: capabilityForAgentTool("download_file"), toolName: "download_file", effectSummary: fileToolEffect("download_file", input),
|
|
703
|
+
})) === true
|
|
704
|
+
? { success: false, text: JSON.stringify({ error: "not_authorized", message: approvalDeclinedMessage }) }
|
|
705
|
+
: await createFileDownloadLinkResult(turn.context, input.assetId);
|
|
676
706
|
downloadSucceeded = name === "download_file" && done.success;
|
|
677
707
|
outcome = done.success ? "completed" : "failed";
|
|
678
708
|
return { content: [{ type: "text", text: done.text }], isError: !done.success };
|
|
@@ -772,6 +802,26 @@ async function askQuestion(turn, input) {
|
|
|
772
802
|
return { success: false, text: JSON.stringify({ error: error.code, message: error.message }) };
|
|
773
803
|
}
|
|
774
804
|
}
|
|
805
|
+
async function callCloudUploadTool(turn, name, untrusted, activityId) {
|
|
806
|
+
const parsed = (name === startUploadName ? startUploadSchema : finishUploadSchema).safeParse(untrusted);
|
|
807
|
+
if (!parsed.success) {
|
|
808
|
+
return { success: false, text: JSON.stringify({ error: "invalid_input", details: parsed.error.issues }) };
|
|
809
|
+
}
|
|
810
|
+
if (name === startUploadName) {
|
|
811
|
+
return executeCloudUploadTool(turn.context, name, parsed.data, turn.signal);
|
|
812
|
+
}
|
|
813
|
+
const authorization = await authorizeAgentToolApproval(turn.context, turn.agentName, "upload_file", parsed.data, undefined, turn.signal, activityId);
|
|
814
|
+
if (authorization.outcome === "expired") {
|
|
815
|
+
return { success: false, text: JSON.stringify({ error: "approval_expired", message: approvalExpiredMessage }) };
|
|
816
|
+
}
|
|
817
|
+
if (authorization.invalidInput !== undefined) {
|
|
818
|
+
return { success: false, text: JSON.stringify({ error: "invalid_input", message: authorization.invalidInput }) };
|
|
819
|
+
}
|
|
820
|
+
if (!authorization.allowed || turn.signal.aborted) {
|
|
821
|
+
return { success: false, text: JSON.stringify({ error: "not_authorized", message: approvalRefusalMessage(authorization.outcome) }) };
|
|
822
|
+
}
|
|
823
|
+
return executeCloudUploadTool(turn.context, name, parsed.data, turn.signal);
|
|
824
|
+
}
|
|
775
825
|
/** The shared tool call keeps only site; the page Grok named comes from its own validated input. */
|
|
776
826
|
function grokSignInExecutor(input) {
|
|
777
827
|
const { site, page_url: pageUrl } = grokSignInSchema.parse(input);
|
|
@@ -790,7 +840,7 @@ function stableJson(value) {
|
|
|
790
840
|
}
|
|
791
841
|
return JSON.stringify(value);
|
|
792
842
|
}
|
|
793
|
-
function cloudRefusal(name, input) {
|
|
843
|
+
function cloudRefusal(name, input, supportsLinkUpload) {
|
|
794
844
|
if (name === "request_sign_in") {
|
|
795
845
|
const parsed = grokSignInSchema.safeParse(input);
|
|
796
846
|
if (!parsed.success)
|
|
@@ -814,7 +864,9 @@ function cloudRefusal(name, input) {
|
|
|
814
864
|
if (name === "upload_file" && input.localPath !== undefined) {
|
|
815
865
|
return {
|
|
816
866
|
error: "local_path_unavailable",
|
|
817
|
-
message:
|
|
867
|
+
message: supportsLinkUpload
|
|
868
|
+
? "Showrunner can't reach that path through upload_file. Call start_upload with the file's name, MIME type, and byte length; PUT the file directly to its returned url with its returned headers, then call finish_upload. Shell-escape every substituted path, url, header name, and header value."
|
|
869
|
+
: "Showrunner can't reach files on your computer. Send the file's bytes in content instead (base64 for binary files).",
|
|
818
870
|
};
|
|
819
871
|
}
|
|
820
872
|
return undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const maxConnectorFileBytes: number;
|
package/dist/src/file-tools.d.ts
CHANGED
|
@@ -2,6 +2,40 @@ import { z } from "zod";
|
|
|
2
2
|
import type { AgentInvocationContext, HostToolCapability } from "./adapter.js";
|
|
3
3
|
export declare const fileUploadOrganizationGuidance: string;
|
|
4
4
|
export declare const uploadMimeTypeGuidance: string;
|
|
5
|
+
export declare const startUploadSchema: z.ZodObject<{
|
|
6
|
+
fileName: z.ZodString;
|
|
7
|
+
mimeType: z.ZodString;
|
|
8
|
+
byteLength: z.ZodNumber;
|
|
9
|
+
folderId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
10
|
+
folderName: z.ZodOptional<z.ZodString>;
|
|
11
|
+
versionOfAssetId: z.ZodOptional<z.ZodString>;
|
|
12
|
+
versionNote: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
export declare const finishUploadSchema: z.ZodObject<{
|
|
15
|
+
assetId: z.ZodString;
|
|
16
|
+
uploadId: z.ZodString;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
export type CloudUploadToolName = "start_upload" | "finish_upload";
|
|
19
|
+
export declare const cloudUploadToolDefinitions: readonly [{
|
|
20
|
+
readonly name: "start_upload";
|
|
21
|
+
readonly description: string;
|
|
22
|
+
readonly inputSchema: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
23
|
+
fileName: z.ZodString;
|
|
24
|
+
mimeType: z.ZodString;
|
|
25
|
+
byteLength: z.ZodNumber;
|
|
26
|
+
folderId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
27
|
+
folderName: z.ZodOptional<z.ZodString>;
|
|
28
|
+
versionOfAssetId: z.ZodOptional<z.ZodString>;
|
|
29
|
+
versionNote: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "finish_upload";
|
|
33
|
+
readonly description: string;
|
|
34
|
+
readonly inputSchema: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
35
|
+
assetId: z.ZodString;
|
|
36
|
+
uploadId: z.ZodString;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
}];
|
|
5
39
|
/**
|
|
6
40
|
* Where download_file saves files: the connector's own cache, not the agent's working directory.
|
|
7
41
|
* Teammate downloads use the process sandbox root instead, alongside their outputs.
|
|
@@ -49,6 +83,10 @@ export declare function executeFileTool(context: AgentInvocationContext, name: F
|
|
|
49
83
|
success: boolean;
|
|
50
84
|
text: string;
|
|
51
85
|
}>;
|
|
86
|
+
export declare function executeCloudUploadTool(context: AgentInvocationContext, name: CloudUploadToolName, input: z.infer<typeof startUploadSchema> | z.infer<typeof finishUploadSchema>, signal: AbortSignal): Promise<{
|
|
87
|
+
success: boolean;
|
|
88
|
+
text: string;
|
|
89
|
+
}>;
|
|
52
90
|
/**
|
|
53
91
|
* download_file for an agent whose computer this process can't write to: a short-lived link to the
|
|
54
92
|
* same bytes, on the same grant. Whoever holds the link can fetch the file until it expires.
|
package/dist/src/file-tools.js
CHANGED
|
@@ -9,7 +9,8 @@ import { pipeline } from "node:stream/promises";
|
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { invocationRunScope } from "./adapter.js";
|
|
11
11
|
import { pathLeavesRunScope } from "./run-folders.js";
|
|
12
|
-
import { ExternalAgentError
|
|
12
|
+
import { ExternalAgentError } from "./client.js";
|
|
13
|
+
import { maxConnectorFileBytes } from "./file-limits.js";
|
|
13
14
|
import { toolFailure, toolSuccess } from "./pieces.js";
|
|
14
15
|
import { createVideoThumbnail, isVideoUpload } from "./video-thumbnail.js";
|
|
15
16
|
import { findGreyBand, greyBandMessage } from "./video-frame-check.js";
|
|
@@ -18,13 +19,53 @@ export const fileUploadOrganizationGuidance = "Independent concepts or alternati
|
|
|
18
19
|
+ "Omit versionOfAssetId for each alternative. Only an explicit edit of a particular source (for example, 'variation 2 brighter'), "
|
|
19
20
|
+ "a new cut or a re-record stacks as a version: set versionOfAssetId to that source's assetId. "
|
|
20
21
|
+ "When re-sending a changed version of a file, link or note already in this chat, add it as a new version of it, without being asked: "
|
|
21
|
-
+ "set versionOfAssetId to that file's or link's assetId
|
|
22
|
+
+ "set versionOfAssetId to that file's or link's assetId, or create_note's versionOf. "
|
|
22
23
|
+ "Showrunner never stacks a file on its own, and a matching name or a reused local output path never "
|
|
23
24
|
+ "proves that two files are the same artifact. "
|
|
24
25
|
+ "Prefer the source's folder or one the person named. Use list_folders to find it and pass folderId; "
|
|
25
26
|
+ "otherwise pass the same folderName for every asset in the set. A version stays in the source's folder unless you name another.";
|
|
26
27
|
export const uploadMimeTypeGuidance = "MIME type of the upload. Any file type supported by human uploads is accepted. "
|
|
27
28
|
+ "Keep the file's real name and extension; Showrunner determines the stored MIME type from fileName.";
|
|
29
|
+
export const startUploadSchema = z.object({
|
|
30
|
+
fileName: z.string().trim().min(1).max(255)
|
|
31
|
+
.refine((value) => !value.includes("/") && !value.includes("\\"), "fileName must not contain path separators."),
|
|
32
|
+
mimeType: z.string().min(1).describe(uploadMimeTypeGuidance),
|
|
33
|
+
byteLength: z.number().int().min(1).max(maxConnectorFileBytes),
|
|
34
|
+
folderId: uuidSchema.nullable().optional()
|
|
35
|
+
.describe("Optional existing folder in this chat. Supply folderId or folderName, not both."),
|
|
36
|
+
folderName: z.string().trim().min(1).max(255).optional()
|
|
37
|
+
.describe("Existing or new folder name in this chat. Supply folderId or folderName, not both."),
|
|
38
|
+
versionOfAssetId: uuidSchema.optional().describe("assetId or file reference ID of the explicit source being edited, cut or re-recorded. "
|
|
39
|
+
+ "Omit for independent concepts and alternatives, even when they reuse a local output path."),
|
|
40
|
+
versionNote: z.string().trim().min(1).optional(),
|
|
41
|
+
}).superRefine((input, context) => {
|
|
42
|
+
if (input.folderName !== undefined && input.folderId != null) {
|
|
43
|
+
context.addIssue({ code: "custom", message: "Supply folderId or folderName, not both." });
|
|
44
|
+
}
|
|
45
|
+
if (input.versionNote !== undefined && input.versionOfAssetId === undefined) {
|
|
46
|
+
context.addIssue({ code: "custom", message: "versionNote applies only with versionOfAssetId." });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
export const finishUploadSchema = z.object({
|
|
50
|
+
assetId: uuidSchema.describe("The assetId returned by start_upload."),
|
|
51
|
+
uploadId: uuidSchema.describe("The uploadId returned by start_upload after the PUT has succeeded."),
|
|
52
|
+
});
|
|
53
|
+
export const cloudUploadToolDefinitions = [{
|
|
54
|
+
name: "start_upload",
|
|
55
|
+
description: `Create an upload link for a file on your disk, up to ${maxConnectorFileBytes / 1024 / 1024 / 1024} GB, in this Showrunner chat. `
|
|
56
|
+
+ "Use curl or an equivalent client to PUT the file to the returned url with every returned header. "
|
|
57
|
+
+ "When building a shell command, shell-escape the local path, url, header names, and header values separately; "
|
|
58
|
+
+ "never substitute them into a prequoted command template. Upload the file and call finish_upload "
|
|
59
|
+
+ "with the returned finish arguments before expiresAt, currently 5 minutes after start_upload. The bytes go directly to the existing "
|
|
60
|
+
+ "Showrunner upload service and never enter the tool call. If curl fails and the file is small, send its bytes with upload_file content instead. "
|
|
61
|
+
+ fileUploadOrganizationGuidance,
|
|
62
|
+
inputSchema: z.toJSONSchema(startUploadSchema),
|
|
63
|
+
}, {
|
|
64
|
+
name: "finish_upload",
|
|
65
|
+
description: "Finish a start_upload after its curl PUT succeeds. Pass the finish object returned by start_upload. "
|
|
66
|
+
+ "This validates the uploaded bytes and creates the Showrunner asset.",
|
|
67
|
+
inputSchema: z.toJSONSchema(finishUploadSchema),
|
|
68
|
+
}];
|
|
28
69
|
/**
|
|
29
70
|
* Where download_file saves files: the connector's own cache, not the agent's working directory.
|
|
30
71
|
* Teammate downloads use the process sandbox root instead, alongside their outputs.
|
|
@@ -344,19 +385,15 @@ async function uploadFile(context, untrusted, workspaceRoot, signal) {
|
|
|
344
385
|
...(!version || input.versionOfAssetId === undefined ? {} : { versionOfAssetId: input.versionOfAssetId }),
|
|
345
386
|
...(!version || input.versionNote === undefined ? {} : { versionNote: input.versionNote }),
|
|
346
387
|
});
|
|
347
|
-
let
|
|
348
|
-
|
|
349
|
-
try {
|
|
350
|
-
uploaded = await upload(true);
|
|
351
|
-
}
|
|
352
|
-
catch (error) {
|
|
388
|
+
let savedSeparately = false;
|
|
389
|
+
const uploaded = await upload(true).catch((error) => {
|
|
353
390
|
// An earlier file this run can't stack on (gone, or not readable here) mustn't lose the new one:
|
|
354
391
|
// it goes up as a file of its own, and the agent is told so.
|
|
355
392
|
if (input.versionOfAssetId === undefined || !(error instanceof ExternalAgentError) || error.statusCode !== 404)
|
|
356
393
|
throw error;
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
394
|
+
savedSeparately = true;
|
|
395
|
+
return upload(false);
|
|
396
|
+
});
|
|
360
397
|
if ("filePath" in source)
|
|
361
398
|
await context.changedFiles?.uploadedFile(source.filePath);
|
|
362
399
|
if (identity !== undefined) {
|
|
@@ -364,25 +401,14 @@ async function uploadFile(context, untrusted, workspaceRoot, signal) {
|
|
|
364
401
|
if (runUploads.size > 256)
|
|
365
402
|
runUploads.delete(runUploads.keys().next().value ?? "");
|
|
366
403
|
}
|
|
367
|
-
|
|
368
|
-
const owed = context.completionRequirements?.uploaded(uploaded.assetId, uploaded.folderId, stacked ? input.versionOfAssetId : undefined);
|
|
369
|
-
// One card per thing the person looks at: a version shows its earlier versions, and a folder its files.
|
|
370
|
-
const cite = stacked
|
|
371
|
-
? "place only this assetId as an asset_reference piece inline where you discuss the file; it shows the earlier version too, so don't also place that one."
|
|
372
|
-
: owed === "folder"
|
|
373
|
-
? "this run has now filed several files in this folder: reference it once with this folderId as a folder_reference piece inline in your reply, not a pill per file."
|
|
374
|
-
: "place this assetId as an asset_reference piece inline where you discuss the file.";
|
|
375
|
-
return toolSuccess({
|
|
404
|
+
return completedUploadResult(context, {
|
|
376
405
|
assetId: uploaded.assetId,
|
|
377
|
-
|
|
406
|
+
folderId: uploaded.folderId,
|
|
378
407
|
fileName: input.fileName,
|
|
379
408
|
mimeType: input.mimeType,
|
|
380
409
|
byteLength,
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
? "It went up as a file of its own: it couldn't be added as a new version of that earlier file here. " +
|
|
384
|
-
`Say so in one plain line, and ${cite}`
|
|
385
|
-
: cite.charAt(0).toUpperCase() + cite.slice(1),
|
|
410
|
+
versionOfAssetId: uploaded.command.versionOfAssetId ?? undefined,
|
|
411
|
+
savedSeparately,
|
|
386
412
|
});
|
|
387
413
|
}
|
|
388
414
|
catch (error) {
|
|
@@ -402,6 +428,89 @@ async function uploadFile(context, untrusted, workspaceRoot, signal) {
|
|
|
402
428
|
await closeFile?.();
|
|
403
429
|
}
|
|
404
430
|
}
|
|
431
|
+
export async function executeCloudUploadTool(context, name, input, signal) {
|
|
432
|
+
try {
|
|
433
|
+
signal.throwIfAborted();
|
|
434
|
+
if (name === "start_upload") {
|
|
435
|
+
const started = startUploadSchema.parse(input);
|
|
436
|
+
const create = (version) => context.client.createFileUploadLink({
|
|
437
|
+
...started,
|
|
438
|
+
folderId: started.folderId ?? null,
|
|
439
|
+
...(!version ? { versionOfAssetId: undefined, versionNote: undefined } : {}),
|
|
440
|
+
});
|
|
441
|
+
const linked = await create(true).then((link) => ({ link, fellBack: false })).catch(async (error) => {
|
|
442
|
+
if (started.versionOfAssetId === undefined || !(error instanceof ExternalAgentError) || error.statusCode !== 404)
|
|
443
|
+
throw error;
|
|
444
|
+
return { link: await create(false), fellBack: true };
|
|
445
|
+
});
|
|
446
|
+
const { link, fellBack } = linked;
|
|
447
|
+
const finish = {
|
|
448
|
+
assetId: link.assetId,
|
|
449
|
+
uploadId: link.uploadGrantId,
|
|
450
|
+
};
|
|
451
|
+
return toolSuccess({
|
|
452
|
+
assetId: link.assetId,
|
|
453
|
+
uploadId: link.uploadGrantId,
|
|
454
|
+
url: link.url,
|
|
455
|
+
headers: link.headers,
|
|
456
|
+
expiresAt: link.expiresAt,
|
|
457
|
+
finish,
|
|
458
|
+
...(fellBack ? {
|
|
459
|
+
addedAsVersion: false,
|
|
460
|
+
hint: "The earlier file isn't available here, so this upload will be saved as a separate file. After finish_upload succeeds, tell the person in one plain line.",
|
|
461
|
+
} : {}),
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const finished = finishUploadSchema.parse(input);
|
|
465
|
+
const completion = await context.client.completeFileUpload(finished.assetId, {
|
|
466
|
+
uploadGrantId: finished.uploadId,
|
|
467
|
+
});
|
|
468
|
+
if (completion.resourceId !== finished.assetId || completion.fileName == null || completion.fileName.length === 0 ||
|
|
469
|
+
completion.mimeType == null || completion.mimeType.length === 0 || completion.byteLength == null ||
|
|
470
|
+
completion.byteLength < 1 || completion.byteLength > maxConnectorFileBytes) {
|
|
471
|
+
return toolFailure({ error: "upload_invalid", message: "The completed upload did not match this file. Start the upload again." });
|
|
472
|
+
}
|
|
473
|
+
return completedUploadResult(context, {
|
|
474
|
+
assetId: completion.resourceId,
|
|
475
|
+
folderId: completion.folderId,
|
|
476
|
+
fileName: completion.fileName,
|
|
477
|
+
mimeType: completion.mimeType,
|
|
478
|
+
byteLength: completion.byteLength,
|
|
479
|
+
versionOfAssetId: completion.versionOfAssetId ?? undefined,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
if (signal.aborted)
|
|
484
|
+
return toolFailure({ error: "upload_cancelled", message: "The upload was cancelled." });
|
|
485
|
+
if (error instanceof ExternalAgentError)
|
|
486
|
+
return toolFailure({ error: error.code, message: error.message });
|
|
487
|
+
if (error instanceof z.ZodError)
|
|
488
|
+
return toolFailure({ error: "invalid_input", issues: error.issues });
|
|
489
|
+
return toolFailure({ error: "file_tool_failed", message: "Couldn't upload the file. Try again." });
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function completedUploadResult(context, upload) {
|
|
493
|
+
const stacked = upload.versionOfAssetId !== undefined;
|
|
494
|
+
const savedSeparately = upload.savedSeparately === true;
|
|
495
|
+
const owed = context.completionRequirements?.uploaded(upload.assetId, upload.folderId, stacked ? upload.versionOfAssetId : undefined);
|
|
496
|
+
const cite = stacked
|
|
497
|
+
? "place only this assetId as an asset_reference piece inline where you discuss the file; it shows the earlier version too, so don't also place that one."
|
|
498
|
+
: owed === "folder"
|
|
499
|
+
? "this run has now filed several files in this folder: reference it once with this folderId as a folder_reference piece inline in your reply, not a pill per file."
|
|
500
|
+
: "place this assetId as an asset_reference piece inline where you discuss the file.";
|
|
501
|
+
return toolSuccess({
|
|
502
|
+
assetId: upload.assetId,
|
|
503
|
+
...(upload.folderId == null ? {} : { folderId: upload.folderId }),
|
|
504
|
+
fileName: upload.fileName,
|
|
505
|
+
mimeType: upload.mimeType,
|
|
506
|
+
byteLength: upload.byteLength,
|
|
507
|
+
...(savedSeparately ? { addedAsVersion: false } : {}),
|
|
508
|
+
hint: savedSeparately
|
|
509
|
+
? "It went up as a file of its own: it couldn't be added as a new version of that earlier file here. "
|
|
510
|
+
+ `Say so in one plain line, and ${cite}`
|
|
511
|
+
: cite.charAt(0).toUpperCase() + cite.slice(1),
|
|
512
|
+
});
|
|
513
|
+
}
|
|
405
514
|
async function openUploadFile(localPath, workspaceRoot, context, signal) {
|
|
406
515
|
const runType = context.trust.runType;
|
|
407
516
|
if (workspaceRoot === undefined) {
|
package/dist/src/protocol.d.ts
CHANGED
|
@@ -377,6 +377,11 @@ export declare const commandResponseSchema: z.ZodObject<{
|
|
|
377
377
|
}>>>;
|
|
378
378
|
correctivePrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
379
379
|
approvalQuestionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
380
|
+
versionOfAssetId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
381
|
+
folderId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
382
|
+
fileName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
383
|
+
mimeType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
384
|
+
byteLength: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
380
385
|
lastWorkAt: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
381
386
|
taskSchedules: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
382
387
|
todoId: z.ZodString;
|
|
@@ -419,6 +424,11 @@ export declare const noteCommandResponseSchema: z.ZodObject<{
|
|
|
419
424
|
}>>>;
|
|
420
425
|
correctivePrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
421
426
|
approvalQuestionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
427
|
+
versionOfAssetId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
428
|
+
folderId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
429
|
+
fileName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
430
|
+
mimeType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
431
|
+
byteLength: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
422
432
|
lastWorkAt: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
423
433
|
taskSchedules: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
424
434
|
todoId: z.ZodString;
|
|
@@ -573,6 +583,11 @@ export declare const fileDownloadLinkSchema: z.ZodObject<{
|
|
|
573
583
|
}>>>;
|
|
574
584
|
correctivePrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
575
585
|
approvalQuestionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
586
|
+
versionOfAssetId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
587
|
+
folderId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
588
|
+
fileName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
589
|
+
mimeType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
590
|
+
byteLength: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
576
591
|
lastWorkAt: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
577
592
|
taskSchedules: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
578
593
|
todoId: z.ZodString;
|
|
@@ -607,6 +622,11 @@ export declare const fileUploadLinkSchema: z.ZodObject<{
|
|
|
607
622
|
}>>>;
|
|
608
623
|
correctivePrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
609
624
|
approvalQuestionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
625
|
+
versionOfAssetId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
626
|
+
folderId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
627
|
+
fileName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
628
|
+
mimeType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
629
|
+
byteLength: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
610
630
|
lastWorkAt: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
611
631
|
taskSchedules: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
612
632
|
todoId: z.ZodString;
|
package/dist/src/protocol.js
CHANGED
|
@@ -257,6 +257,11 @@ export const commandResponseSchema = z.object({
|
|
|
257
257
|
executionResult: z.enum(["success", "partial", "failed"]).nullable().optional(),
|
|
258
258
|
correctivePrompt: z.string().nullable().optional(),
|
|
259
259
|
approvalQuestionId: uuid.nullable().optional(),
|
|
260
|
+
versionOfAssetId: uuid.nullable().optional(),
|
|
261
|
+
folderId: uuid.nullable().optional(),
|
|
262
|
+
fileName: z.string().nullable().optional(),
|
|
263
|
+
mimeType: z.string().nullable().optional(),
|
|
264
|
+
byteLength: z.number().int().nullable().optional(),
|
|
260
265
|
// The run's latest work time as the server orders messages against work (ticks, quoted past 2^53).
|
|
261
266
|
// Null before the run's first work.
|
|
262
267
|
lastWorkAt: z.union([z.string().regex(/^\d+$/u), z.number().int()]).nullable(),
|
|
@@ -16,8 +16,8 @@ export declare const renderToolSchemas: {
|
|
|
16
16
|
final: "final";
|
|
17
17
|
}>>;
|
|
18
18
|
delivery: z.ZodOptional<z.ZodObject<{
|
|
19
|
-
folderId: z.ZodOptional<z.ZodString>;
|
|
20
19
|
versionOfAssetId: z.ZodOptional<z.ZodString>;
|
|
20
|
+
folderId: z.ZodOptional<z.ZodString>;
|
|
21
21
|
versionNote: z.ZodOptional<z.ZodString>;
|
|
22
22
|
}, z.core.$strip>>;
|
|
23
23
|
idempotencyKey: z.ZodString;
|
package/dist/src/render-tools.js
CHANGED
|
@@ -60,7 +60,7 @@ export function renderRequest(untrusted) {
|
|
|
60
60
|
}
|
|
61
61
|
export function renderToolDescription(name) {
|
|
62
62
|
if (name === "render_video")
|
|
63
|
-
return "Queue a server-side video render on Showrunner; no rendering runs on this machine. Upload local files
|
|
63
|
+
return "Queue a server-side video render on Showrunner; no rendering runs on this machine. Upload local files first, then use their assetIds in the recipe. Fresh uploads must finish processing before rendering. If the error says 'Source asset must finish uploading before it can be rendered', retry render_video after processing finishes. Preview first, then render final with delivery.versionOfAssetId set to the preview's outputAssetId so both land in one version stack. Results land in this chat (or delivery.folderId) automatically; cite the completed outputAssetId with an asset_reference. Use get_render to await completion before describing an output as ready.";
|
|
64
64
|
if (name === "get_render")
|
|
65
65
|
return "Read a Showrunner render's status, progress, outputAssetId and error. Set waitSeconds up to 50 to wait in one call for completion, failure or cancellation.";
|
|
66
66
|
return "Cancel a queued or running Showrunner render in this chat.";
|