@botiverse/raft-daemon 0.65.0 → 0.66.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.
- package/dist/{chunk-53ZFBLI4.js → chunk-EX73HXGE.js} +959 -120
- package/dist/cli/index.js +2185 -525
- package/dist/core.js +1 -1
- package/dist/{dist-OGRAMTIO.js → dist-PCKZII47.js} +2154 -516
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -16,20 +16,21 @@ import path4 from "path";
|
|
|
16
16
|
import fs2 from "fs";
|
|
17
17
|
import path5 from "path";
|
|
18
18
|
import { randomUUID } from "crypto";
|
|
19
|
+
import { basename } from "path";
|
|
20
|
+
import { existsSync, readFileSync as readFileSync2, statSync } from "fs";
|
|
19
21
|
import fs3 from "fs";
|
|
20
22
|
import os2 from "os";
|
|
21
23
|
import path6 from "path";
|
|
22
24
|
import fs4 from "fs";
|
|
23
25
|
import os3 from "os";
|
|
24
26
|
import path7 from "path";
|
|
25
|
-
import { existsSync, statSync, readFileSync as
|
|
26
|
-
import { basename } from "path";
|
|
27
|
-
import { writeFileSync } from "fs";
|
|
27
|
+
import { existsSync as existsSync2, statSync as statSync2, readFileSync as readFileSync3 } from "fs";
|
|
28
28
|
import { basename as basename2 } from "path";
|
|
29
|
-
import {
|
|
29
|
+
import { writeFileSync } from "fs";
|
|
30
30
|
import fs5 from "fs";
|
|
31
31
|
import os4 from "os";
|
|
32
32
|
import path8 from "path";
|
|
33
|
+
import fs6 from "fs";
|
|
33
34
|
var require2 = __raftCreateRequire(import.meta.url);
|
|
34
35
|
var __create = Object.create;
|
|
35
36
|
var __defProp = Object.defineProperty;
|
|
@@ -1013,7 +1014,7 @@ var require_command = __commonJS({
|
|
|
1013
1014
|
var EventEmitter = __require("events").EventEmitter;
|
|
1014
1015
|
var childProcess = __require("child_process");
|
|
1015
1016
|
var path9 = __require("path");
|
|
1016
|
-
var
|
|
1017
|
+
var fs7 = __require("fs");
|
|
1017
1018
|
var process3 = __require("process");
|
|
1018
1019
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1019
1020
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -1946,10 +1947,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1946
1947
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1947
1948
|
function findFile(baseDir, baseName) {
|
|
1948
1949
|
const localBin = path9.resolve(baseDir, baseName);
|
|
1949
|
-
if (
|
|
1950
|
+
if (fs7.existsSync(localBin)) return localBin;
|
|
1950
1951
|
if (sourceExt.includes(path9.extname(baseName))) return void 0;
|
|
1951
1952
|
const foundExt = sourceExt.find(
|
|
1952
|
-
(ext) =>
|
|
1953
|
+
(ext) => fs7.existsSync(`${localBin}${ext}`)
|
|
1953
1954
|
);
|
|
1954
1955
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
1955
1956
|
return void 0;
|
|
@@ -1961,7 +1962,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1961
1962
|
if (this._scriptPath) {
|
|
1962
1963
|
let resolvedScriptPath;
|
|
1963
1964
|
try {
|
|
1964
|
-
resolvedScriptPath =
|
|
1965
|
+
resolvedScriptPath = fs7.realpathSync(this._scriptPath);
|
|
1965
1966
|
} catch (err) {
|
|
1966
1967
|
resolvedScriptPath = this._scriptPath;
|
|
1967
1968
|
}
|
|
@@ -15439,7 +15440,7 @@ var require_mock_utils = __commonJS({
|
|
|
15439
15440
|
}
|
|
15440
15441
|
return normalizedQp;
|
|
15441
15442
|
}
|
|
15442
|
-
function
|
|
15443
|
+
function safeUrl2(path9) {
|
|
15443
15444
|
if (typeof path9 !== "string") {
|
|
15444
15445
|
return path9;
|
|
15445
15446
|
}
|
|
@@ -15475,10 +15476,10 @@ var require_mock_utils = __commonJS({
|
|
|
15475
15476
|
}
|
|
15476
15477
|
function getMockDispatch(mockDispatches, key) {
|
|
15477
15478
|
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
|
|
15478
|
-
const resolvedPath = typeof basePath === "string" ?
|
|
15479
|
+
const resolvedPath = typeof basePath === "string" ? safeUrl2(basePath) : basePath;
|
|
15479
15480
|
const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
|
|
15480
15481
|
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path9, ignoreTrailingSlash }) => {
|
|
15481
|
-
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(
|
|
15482
|
+
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl2(path9)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl2(path9), resolvedPath);
|
|
15482
15483
|
});
|
|
15483
15484
|
if (matchedMockDispatches.length === 0) {
|
|
15484
15485
|
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
|
|
@@ -42354,6 +42355,21 @@ var agentApiHistoryQuerySchema = passthroughObject({
|
|
|
42354
42355
|
around: optionalStringSchema,
|
|
42355
42356
|
limit: optionalStringSchema
|
|
42356
42357
|
});
|
|
42358
|
+
var agentApiKnowledgeGetQuerySchema = passthroughObject({
|
|
42359
|
+
topic: external_exports.string().trim().min(1),
|
|
42360
|
+
reason: optionalStringSchema,
|
|
42361
|
+
turn_id: optionalStringSchema,
|
|
42362
|
+
trace_id: optionalStringSchema
|
|
42363
|
+
});
|
|
42364
|
+
var agentApiKnowledgeGetResponseSchema = passthroughObject({
|
|
42365
|
+
ok: external_exports.literal(true),
|
|
42366
|
+
docId: external_exports.string(),
|
|
42367
|
+
topicOrPath: external_exports.string(),
|
|
42368
|
+
docVersion: external_exports.string(),
|
|
42369
|
+
docState: external_exports.string(),
|
|
42370
|
+
contentType: external_exports.string(),
|
|
42371
|
+
content: external_exports.string()
|
|
42372
|
+
});
|
|
42357
42373
|
var agentApiMessageSearchQuerySchema = passthroughObject({
|
|
42358
42374
|
q: optionalStringSchema,
|
|
42359
42375
|
channel: optionalStringSchema,
|
|
@@ -42391,6 +42407,58 @@ var agentApiMessageReactionBodySchema = passthroughObject({
|
|
|
42391
42407
|
var agentApiChannelMembershipParamsSchema = passthroughObject({
|
|
42392
42408
|
channelId: external_exports.string().trim().min(1).transform(asChannelId)
|
|
42393
42409
|
});
|
|
42410
|
+
var agentApiAttachmentDownloadParamsSchema = passthroughObject({
|
|
42411
|
+
attachmentId: external_exports.string().trim().min(1)
|
|
42412
|
+
});
|
|
42413
|
+
var agentApiAttachmentCommentsParamsSchema = passthroughObject({
|
|
42414
|
+
attachmentId: external_exports.string().trim().min(1)
|
|
42415
|
+
});
|
|
42416
|
+
var agentApiAttachmentCommentsQuerySchema = passthroughObject({
|
|
42417
|
+
limit: optionalStringSchema
|
|
42418
|
+
});
|
|
42419
|
+
var agentApiAttachmentCommentAnchorSchema = passthroughObject({
|
|
42420
|
+
type: external_exports.string().trim().min(1),
|
|
42421
|
+
data: external_exports.record(external_exports.string(), external_exports.unknown())
|
|
42422
|
+
});
|
|
42423
|
+
var agentApiAttachmentCommentReactionSchema = passthroughObject({
|
|
42424
|
+
emoji: external_exports.string().trim().min(1),
|
|
42425
|
+
reactorType: external_exports.string().trim().min(1),
|
|
42426
|
+
reactorId: external_exports.string().trim().min(1),
|
|
42427
|
+
createdAt: external_exports.string().datetime()
|
|
42428
|
+
});
|
|
42429
|
+
var agentApiAttachmentCommentResolvedBySchema = passthroughObject({
|
|
42430
|
+
reactorId: external_exports.string().trim().min(1),
|
|
42431
|
+
reactorType: external_exports.string().trim().min(1)
|
|
42432
|
+
});
|
|
42433
|
+
var agentApiAttachmentCommentSchema = passthroughObject({
|
|
42434
|
+
id: external_exports.string().trim().min(1),
|
|
42435
|
+
channelId: external_exports.string().trim().min(1).optional(),
|
|
42436
|
+
senderId: external_exports.string().trim().min(1),
|
|
42437
|
+
senderType: external_exports.enum(["user", "agent"]),
|
|
42438
|
+
senderName: external_exports.string().trim().min(1),
|
|
42439
|
+
senderAvatarUrl: nullableStringSchema.optional(),
|
|
42440
|
+
senderGravatarHash: nullableStringSchema.optional(),
|
|
42441
|
+
content: external_exports.string(),
|
|
42442
|
+
createdAt: external_exports.string().datetime(),
|
|
42443
|
+
reactions: external_exports.array(agentApiAttachmentCommentReactionSchema),
|
|
42444
|
+
anchor: agentApiAttachmentCommentAnchorSchema.nullable(),
|
|
42445
|
+
resolved: external_exports.boolean().optional(),
|
|
42446
|
+
resolvedBy: agentApiAttachmentCommentResolvedBySchema.nullable().optional(),
|
|
42447
|
+
resolvedAt: external_exports.string().datetime().nullable().optional()
|
|
42448
|
+
});
|
|
42449
|
+
var agentApiAttachmentCommentsResponseSchema = passthroughObject({
|
|
42450
|
+
comments: external_exports.array(agentApiAttachmentCommentSchema),
|
|
42451
|
+
threadChannelId: nullableStringSchema.optional(),
|
|
42452
|
+
viewer: passthroughObject({
|
|
42453
|
+
canComment: external_exports.boolean(),
|
|
42454
|
+
reason: external_exports.string().optional(),
|
|
42455
|
+
canResolve: external_exports.boolean(),
|
|
42456
|
+
resolveAction: passthroughObject({
|
|
42457
|
+
type: external_exports.string().trim().min(1),
|
|
42458
|
+
emoji: external_exports.string().trim().min(1)
|
|
42459
|
+
}).optional()
|
|
42460
|
+
}).optional()
|
|
42461
|
+
});
|
|
42394
42462
|
var agentApiChannelMembersQuerySchema = passthroughObject({
|
|
42395
42463
|
channel: external_exports.string().trim().min(1)
|
|
42396
42464
|
});
|
|
@@ -42545,6 +42613,9 @@ var agentApiIntegrationAppPrepareBodySchema = passthroughObject({
|
|
|
42545
42613
|
unsafeDemoUrlOverride: optionalBooleanSchema,
|
|
42546
42614
|
draftHint: optionalStringSchema
|
|
42547
42615
|
});
|
|
42616
|
+
var agentApiIntegrationAppRotateSecretBodySchema = passthroughObject({
|
|
42617
|
+
clientKey: external_exports.string().trim().min(1)
|
|
42618
|
+
});
|
|
42548
42619
|
var agentApiActionPrepareBodySchema = passthroughObject({
|
|
42549
42620
|
target: external_exports.string().trim().min(1),
|
|
42550
42621
|
action: actionCardActionSchema
|
|
@@ -42552,6 +42623,9 @@ var agentApiActionPrepareBodySchema = passthroughObject({
|
|
|
42552
42623
|
var agentApiServerInfoResponseSchema = passthroughObject({
|
|
42553
42624
|
runtimeContext: passthroughObject({
|
|
42554
42625
|
agentId: external_exports.string(),
|
|
42626
|
+
runtime: external_exports.string().optional(),
|
|
42627
|
+
model: external_exports.string().optional(),
|
|
42628
|
+
reasoningEffort: reasoningEffortSchema.nullable().optional(),
|
|
42555
42629
|
serverId: external_exports.string(),
|
|
42556
42630
|
machineId: external_exports.string().nullable().optional(),
|
|
42557
42631
|
machineName: external_exports.string().nullable().optional(),
|
|
@@ -42568,10 +42642,12 @@ var agentApiServerInfoResponseSchema = passthroughObject({
|
|
|
42568
42642
|
joined: external_exports.boolean()
|
|
42569
42643
|
})),
|
|
42570
42644
|
agents: external_exports.array(passthroughObject({
|
|
42571
|
-
name: external_exports.string()
|
|
42645
|
+
name: external_exports.string(),
|
|
42646
|
+
role: external_exports.enum(["owner", "admin", "member"]).nullable().optional()
|
|
42572
42647
|
})),
|
|
42573
42648
|
humans: external_exports.array(passthroughObject({
|
|
42574
|
-
name: external_exports.string()
|
|
42649
|
+
name: external_exports.string(),
|
|
42650
|
+
role: external_exports.enum(["owner", "admin", "member"]).nullable().optional()
|
|
42575
42651
|
}))
|
|
42576
42652
|
});
|
|
42577
42653
|
var agentApiMentionActionsPendingQuerySchema = passthroughObject({
|
|
@@ -42646,6 +42722,12 @@ var agentApiIntegrationAppPrepareResponseSchema = passthroughObject({
|
|
|
42646
42722
|
integrationUpdateAppRegistrationOperationSchema
|
|
42647
42723
|
])
|
|
42648
42724
|
});
|
|
42725
|
+
var agentApiIntegrationAppRotateSecretResponseSchema = passthroughObject({
|
|
42726
|
+
clientId: external_exports.string(),
|
|
42727
|
+
clientKey: external_exports.string(),
|
|
42728
|
+
clientName: external_exports.string(),
|
|
42729
|
+
clientSecret: external_exports.string()
|
|
42730
|
+
});
|
|
42649
42731
|
var agentApiAttachmentEnvelopeSchema = passthroughObject({
|
|
42650
42732
|
id: external_exports.string(),
|
|
42651
42733
|
filename: external_exports.string()
|
|
@@ -42781,6 +42863,21 @@ var agentApiChannelMembersResponseSchema = passthroughObject({
|
|
|
42781
42863
|
role: optionalStringSchema
|
|
42782
42864
|
}))
|
|
42783
42865
|
});
|
|
42866
|
+
var agentApiChannelMuteResponseSchema = passthroughObject({
|
|
42867
|
+
activityMuted: optionalBooleanSchema,
|
|
42868
|
+
muteFromSeq: nullableNumberSchema.optional(),
|
|
42869
|
+
attention: passthroughObject({
|
|
42870
|
+
state: optionalStringSchema,
|
|
42871
|
+
ordinaryActivity: optionalStringSchema,
|
|
42872
|
+
unmuteCommand: optionalStringSchema,
|
|
42873
|
+
unmuteApi: optionalStringSchema,
|
|
42874
|
+
muteCommand: optionalStringSchema,
|
|
42875
|
+
muteApi: optionalStringSchema,
|
|
42876
|
+
stillArrives: optionalStringArraySchema,
|
|
42877
|
+
threadBoundary: optionalStringSchema,
|
|
42878
|
+
catchUp: optionalStringSchema
|
|
42879
|
+
}).optional()
|
|
42880
|
+
});
|
|
42784
42881
|
var agentApiTaskClaimResultSchema = passthroughObject({
|
|
42785
42882
|
taskNumber: external_exports.number().int().positive().optional(),
|
|
42786
42883
|
messageId: optionalStringSchema,
|
|
@@ -42893,6 +42990,16 @@ var agentApiContract = {
|
|
|
42893
42990
|
request: { query: agentApiHistoryQuerySchema },
|
|
42894
42991
|
response: { body: agentApiHistoryResponseSchema }
|
|
42895
42992
|
}),
|
|
42993
|
+
knowledgeGet: route({
|
|
42994
|
+
key: "knowledgeGet",
|
|
42995
|
+
method: "GET",
|
|
42996
|
+
path: "/knowledge",
|
|
42997
|
+
client: { resource: "knowledge", method: "get" },
|
|
42998
|
+
capability: "knowledge",
|
|
42999
|
+
description: "Fetch a Slock Manual for Agents topic from the current server.",
|
|
43000
|
+
request: { query: agentApiKnowledgeGetQuerySchema },
|
|
43001
|
+
response: { body: agentApiKnowledgeGetResponseSchema }
|
|
43002
|
+
}),
|
|
42896
43003
|
messageSend: route({
|
|
42897
43004
|
key: "messageSend",
|
|
42898
43005
|
method: "POST",
|
|
@@ -42963,6 +43070,26 @@ var agentApiContract = {
|
|
|
42963
43070
|
request: { params: agentApiChannelMembershipParamsSchema },
|
|
42964
43071
|
response: { body: agentApiOkResponseSchema }
|
|
42965
43072
|
}),
|
|
43073
|
+
channelMute: route({
|
|
43074
|
+
key: "channelMute",
|
|
43075
|
+
method: "POST",
|
|
43076
|
+
path: "/channels/:channelId/mute",
|
|
43077
|
+
client: { resource: "channels", method: "mute" },
|
|
43078
|
+
capability: "channels",
|
|
43079
|
+
description: "Mute ordinary activity delivery for a visible regular channel as the bound agent credential.",
|
|
43080
|
+
request: { params: agentApiChannelMembershipParamsSchema },
|
|
43081
|
+
response: { body: agentApiChannelMuteResponseSchema }
|
|
43082
|
+
}),
|
|
43083
|
+
channelUnmute: route({
|
|
43084
|
+
key: "channelUnmute",
|
|
43085
|
+
method: "POST",
|
|
43086
|
+
path: "/channels/:channelId/unmute",
|
|
43087
|
+
client: { resource: "channels", method: "unmute" },
|
|
43088
|
+
capability: "channels",
|
|
43089
|
+
description: "Unmute ordinary activity delivery for a visible regular channel as the bound agent credential.",
|
|
43090
|
+
request: { params: agentApiChannelMembershipParamsSchema },
|
|
43091
|
+
response: { body: agentApiChannelMuteResponseSchema }
|
|
43092
|
+
}),
|
|
42966
43093
|
channelMembers: route({
|
|
42967
43094
|
key: "channelMembers",
|
|
42968
43095
|
method: "GET",
|
|
@@ -43153,6 +43280,16 @@ var agentApiContract = {
|
|
|
43153
43280
|
request: { body: agentApiProfileUpdateBodySchema },
|
|
43154
43281
|
response: { body: agentApiProfileViewSchema }
|
|
43155
43282
|
}),
|
|
43283
|
+
profileAvatarUpdate: route({
|
|
43284
|
+
key: "profileAvatarUpdate",
|
|
43285
|
+
method: "POST",
|
|
43286
|
+
path: "/profile/avatar",
|
|
43287
|
+
client: { resource: "profile", method: "updateAvatar" },
|
|
43288
|
+
capability: "server",
|
|
43289
|
+
description: "Update the bound agent profile avatar using multipart form data.",
|
|
43290
|
+
request: {},
|
|
43291
|
+
response: { body: agentApiProfileViewSchema }
|
|
43292
|
+
}),
|
|
43156
43293
|
integrationList: route({
|
|
43157
43294
|
key: "integrationList",
|
|
43158
43295
|
method: "GET",
|
|
@@ -43183,6 +43320,22 @@ var agentApiContract = {
|
|
|
43183
43320
|
request: { body: agentApiIntegrationAppPrepareBodySchema },
|
|
43184
43321
|
response: { body: agentApiIntegrationAppPrepareResponseSchema }
|
|
43185
43322
|
}),
|
|
43323
|
+
integrationAppRotateSecret: route({
|
|
43324
|
+
key: "integrationAppRotateSecret",
|
|
43325
|
+
method: "POST",
|
|
43326
|
+
path: "/integrations/app/rotate-secret",
|
|
43327
|
+
client: { resource: "integrations", method: "rotateAppSecret" },
|
|
43328
|
+
// Mirrors integrationAppPrepare's "read" capability: the AgentApiCapability
|
|
43329
|
+
// enum has no generic "mutation"/"integrations" scope, and the sibling
|
|
43330
|
+
// integration app routes (prepare/login) all gate on "read". Owner-scope is
|
|
43331
|
+
// enforced server-side in rotateClientSecretForAgent's WHERE clause (and the
|
|
43332
|
+
// bound agent credential), so the capability tier is not the security
|
|
43333
|
+
// boundary here. Keep parity with integrationAppPrepare.
|
|
43334
|
+
capability: "read",
|
|
43335
|
+
description: "Regenerate the one-time client secret for a server-local integration app the calling agent owns; invalidates the previous secret.",
|
|
43336
|
+
request: { body: agentApiIntegrationAppRotateSecretBodySchema },
|
|
43337
|
+
response: { body: agentApiIntegrationAppRotateSecretResponseSchema }
|
|
43338
|
+
}),
|
|
43186
43339
|
actionPrepare: route({
|
|
43187
43340
|
key: "actionPrepare",
|
|
43188
43341
|
method: "POST",
|
|
@@ -43202,13 +43355,43 @@ var agentApiContract = {
|
|
|
43202
43355
|
description: "Upload a multipart attachment as the bound agent credential.",
|
|
43203
43356
|
request: {},
|
|
43204
43357
|
response: { body: agentApiAttachmentUploadResponseSchema }
|
|
43358
|
+
}),
|
|
43359
|
+
attachmentDownload: route({
|
|
43360
|
+
key: "attachmentDownload",
|
|
43361
|
+
method: "GET",
|
|
43362
|
+
path: "/attachments/:attachmentId",
|
|
43363
|
+
client: { resource: "attachments", method: "download" },
|
|
43364
|
+
capability: "read",
|
|
43365
|
+
description: "Download attachment bytes visible to the bound agent credential.",
|
|
43366
|
+
request: { params: agentApiAttachmentDownloadParamsSchema },
|
|
43367
|
+
response: { kind: "binary" }
|
|
43368
|
+
}),
|
|
43369
|
+
attachmentCommentsList: route({
|
|
43370
|
+
key: "attachmentCommentsList",
|
|
43371
|
+
method: "GET",
|
|
43372
|
+
path: "/attachments/:attachmentId/comments",
|
|
43373
|
+
client: { resource: "attachments", method: "comments" },
|
|
43374
|
+
capability: "read",
|
|
43375
|
+
description: "List comments scoped to an attachment visible to the bound agent credential.",
|
|
43376
|
+
request: { params: agentApiAttachmentCommentsParamsSchema, query: agentApiAttachmentCommentsQuerySchema },
|
|
43377
|
+
response: { body: agentApiAttachmentCommentsResponseSchema }
|
|
43205
43378
|
})
|
|
43206
43379
|
};
|
|
43207
|
-
function
|
|
43208
|
-
return
|
|
43380
|
+
function getAgentApiResponseKind(response) {
|
|
43381
|
+
return "kind" in response ? response.kind ?? "json" : "json";
|
|
43209
43382
|
}
|
|
43210
43383
|
function parseAgentApiResponse(key, value) {
|
|
43211
|
-
|
|
43384
|
+
const response = agentApiContract[key].response;
|
|
43385
|
+
if (getAgentApiResponseKind(response) === "binary") {
|
|
43386
|
+
if (!(value instanceof Uint8Array)) {
|
|
43387
|
+
throw new TypeError(`Agent API ${key} response did not contain binary bytes`);
|
|
43388
|
+
}
|
|
43389
|
+
return value;
|
|
43390
|
+
}
|
|
43391
|
+
if (!("body" in response)) {
|
|
43392
|
+
throw new TypeError(`Agent API ${key} response contract is missing a JSON body schema`);
|
|
43393
|
+
}
|
|
43394
|
+
return response.body.parse(value);
|
|
43212
43395
|
}
|
|
43213
43396
|
init_esm_shims();
|
|
43214
43397
|
function failure(routeKey, reason, message, details = {}) {
|
|
@@ -43221,17 +43404,17 @@ function failure(routeKey, reason, message, details = {}) {
|
|
|
43221
43404
|
};
|
|
43222
43405
|
}
|
|
43223
43406
|
function encodePathParams(routeKey, params) {
|
|
43224
|
-
const
|
|
43407
|
+
const route3 = agentApiContract[routeKey];
|
|
43225
43408
|
let parsed;
|
|
43226
43409
|
try {
|
|
43227
|
-
parsed = "params" in
|
|
43410
|
+
parsed = "params" in route3.request ? route3.request.params.parse(params ?? {}) : {};
|
|
43228
43411
|
} catch (cause) {
|
|
43229
|
-
return failure(routeKey, "request_contract_mismatch", `Agent API ${
|
|
43412
|
+
return failure(routeKey, "request_contract_mismatch", `Agent API ${route3.key} path params did not match the shared contract`, { cause });
|
|
43230
43413
|
}
|
|
43231
|
-
return
|
|
43414
|
+
return route3.path.replace(/:([A-Za-z][A-Za-z0-9_]*)/g, (_match, key) => {
|
|
43232
43415
|
const value = parsed[key];
|
|
43233
43416
|
if (value === void 0 || value === null) {
|
|
43234
|
-
throw new MissingPathParamError(
|
|
43417
|
+
throw new MissingPathParamError(route3.key, key);
|
|
43235
43418
|
}
|
|
43236
43419
|
return encodeURIComponent(String(value));
|
|
43237
43420
|
});
|
|
@@ -43245,12 +43428,12 @@ var MissingPathParamError = class extends Error {
|
|
|
43245
43428
|
};
|
|
43246
43429
|
function encodeQuery(routeKey, query) {
|
|
43247
43430
|
if (query === void 0) return void 0;
|
|
43248
|
-
const
|
|
43431
|
+
const route3 = agentApiContract[routeKey];
|
|
43249
43432
|
let parsed;
|
|
43250
43433
|
try {
|
|
43251
|
-
parsed = "query" in
|
|
43434
|
+
parsed = "query" in route3.request ? route3.request.query.parse(query) : {};
|
|
43252
43435
|
} catch (cause) {
|
|
43253
|
-
return failure(routeKey, "request_contract_mismatch", `Agent API ${
|
|
43436
|
+
return failure(routeKey, "request_contract_mismatch", `Agent API ${route3.key} query did not match the shared contract`, { cause });
|
|
43254
43437
|
}
|
|
43255
43438
|
const params = new URLSearchParams();
|
|
43256
43439
|
for (const [key, value] of Object.entries(parsed)) {
|
|
@@ -43265,11 +43448,11 @@ function encodeQuery(routeKey, query) {
|
|
|
43265
43448
|
}
|
|
43266
43449
|
function parseBody(routeKey, body) {
|
|
43267
43450
|
if (body === void 0) return void 0;
|
|
43268
|
-
const
|
|
43451
|
+
const route3 = agentApiContract[routeKey];
|
|
43269
43452
|
try {
|
|
43270
|
-
return "body" in
|
|
43453
|
+
return "body" in route3.request ? route3.request.body.parse(body) : void 0;
|
|
43271
43454
|
} catch (cause) {
|
|
43272
|
-
return failure(routeKey, "request_contract_mismatch", `Agent API ${
|
|
43455
|
+
return failure(routeKey, "request_contract_mismatch", `Agent API ${route3.key} body did not match the shared contract`, { cause });
|
|
43273
43456
|
}
|
|
43274
43457
|
}
|
|
43275
43458
|
function isAgentApiRawFailure(value) {
|
|
@@ -43295,7 +43478,7 @@ function buildAgentApiRawRoutePath(routeKey, options = {}) {
|
|
|
43295
43478
|
return `${options.pathPrefix ?? AGENT_API_BASE_PATH}${path9}${suffix}`;
|
|
43296
43479
|
}
|
|
43297
43480
|
async function requestAgentApiRawRoute(transport, routeKey, options = {}) {
|
|
43298
|
-
const
|
|
43481
|
+
const route3 = agentApiContract[routeKey];
|
|
43299
43482
|
const path9 = buildAgentApiRawRoutePath(routeKey, options);
|
|
43300
43483
|
if (typeof path9 !== "string") return path9;
|
|
43301
43484
|
const body = parseBody(routeKey, options.body);
|
|
@@ -43304,12 +43487,12 @@ async function requestAgentApiRawRoute(transport, routeKey, options = {}) {
|
|
|
43304
43487
|
try {
|
|
43305
43488
|
response = await transport.request({
|
|
43306
43489
|
routeKey,
|
|
43307
|
-
method:
|
|
43490
|
+
method: route3.method,
|
|
43308
43491
|
path: path9,
|
|
43309
43492
|
body
|
|
43310
43493
|
});
|
|
43311
43494
|
} catch (cause) {
|
|
43312
|
-
return failure(routeKey, "transport_error", `Agent API ${
|
|
43495
|
+
return failure(routeKey, "transport_error", `Agent API ${route3.key} transport request failed`, { cause });
|
|
43313
43496
|
}
|
|
43314
43497
|
if (!response.ok) {
|
|
43315
43498
|
return failure(routeKey, "http_error", response.error ?? `HTTP ${response.status}`, {
|
|
@@ -43319,8 +43502,22 @@ async function requestAgentApiRawRoute(transport, routeKey, options = {}) {
|
|
|
43319
43502
|
response: response.data
|
|
43320
43503
|
});
|
|
43321
43504
|
}
|
|
43505
|
+
if (getAgentApiResponseKind(route3.response) === "binary") {
|
|
43506
|
+
if (!(response.data instanceof Uint8Array)) {
|
|
43507
|
+
return failure(routeKey, "response_contract_mismatch", `Agent API ${route3.key} response did not contain binary bytes`, {
|
|
43508
|
+
status: response.status,
|
|
43509
|
+
response: response.data
|
|
43510
|
+
});
|
|
43511
|
+
}
|
|
43512
|
+
return {
|
|
43513
|
+
ok: true,
|
|
43514
|
+
routeKey,
|
|
43515
|
+
status: response.status,
|
|
43516
|
+
data: response.data
|
|
43517
|
+
};
|
|
43518
|
+
}
|
|
43322
43519
|
if (response.data === null) {
|
|
43323
|
-
return failure(routeKey, "empty_response", `Agent API ${
|
|
43520
|
+
return failure(routeKey, "empty_response", `Agent API ${route3.key} returned an empty response body`, {
|
|
43324
43521
|
status: response.status
|
|
43325
43522
|
});
|
|
43326
43523
|
}
|
|
@@ -43332,7 +43529,7 @@ async function requestAgentApiRawRoute(transport, routeKey, options = {}) {
|
|
|
43332
43529
|
data: parseAgentApiResponse(routeKey, response.data)
|
|
43333
43530
|
};
|
|
43334
43531
|
} catch (cause) {
|
|
43335
|
-
return failure(routeKey, "response_contract_mismatch", `Agent API ${
|
|
43532
|
+
return failure(routeKey, "response_contract_mismatch", `Agent API ${route3.key} response did not match the shared contract`, {
|
|
43336
43533
|
status: response.status,
|
|
43337
43534
|
cause,
|
|
43338
43535
|
response: response.data
|
|
@@ -43340,16 +43537,16 @@ async function requestAgentApiRawRoute(transport, routeKey, options = {}) {
|
|
|
43340
43537
|
}
|
|
43341
43538
|
}
|
|
43342
43539
|
function requestOptionsFromMethodArgs(routeKey, pathPrefix, args) {
|
|
43343
|
-
const
|
|
43540
|
+
const route3 = agentApiContract[routeKey];
|
|
43344
43541
|
let index = 0;
|
|
43345
43542
|
const requestOptions = { pathPrefix };
|
|
43346
|
-
if ("params" in
|
|
43543
|
+
if ("params" in route3.request) {
|
|
43347
43544
|
requestOptions.params = args[index++];
|
|
43348
43545
|
}
|
|
43349
|
-
if ("query" in
|
|
43546
|
+
if ("query" in route3.request) {
|
|
43350
43547
|
requestOptions.query = args[index++];
|
|
43351
43548
|
}
|
|
43352
|
-
if ("body" in
|
|
43549
|
+
if ("body" in route3.request) {
|
|
43353
43550
|
requestOptions.body = args[index++];
|
|
43354
43551
|
}
|
|
43355
43552
|
return requestOptions;
|
|
@@ -43357,9 +43554,9 @@ function requestOptionsFromMethodArgs(routeKey, pathPrefix, args) {
|
|
|
43357
43554
|
function createAgentApiRawClient(transport, options = {}) {
|
|
43358
43555
|
const pathPrefix = options.pathPrefix ?? AGENT_API_BASE_PATH;
|
|
43359
43556
|
const client = {};
|
|
43360
|
-
for (const
|
|
43361
|
-
const routeKey =
|
|
43362
|
-
const { resource, method } =
|
|
43557
|
+
for (const route3 of Object.values(agentApiContract)) {
|
|
43558
|
+
const routeKey = route3.key;
|
|
43559
|
+
const { resource, method } = route3.client;
|
|
43363
43560
|
const resourceClient = client[resource] ??= {};
|
|
43364
43561
|
resourceClient[method] = (...args) => requestAgentApiRawRoute(
|
|
43365
43562
|
transport,
|
|
@@ -43380,7 +43577,10 @@ async function authHeadersForRequest(auth, request) {
|
|
|
43380
43577
|
if (!auth) return void 0;
|
|
43381
43578
|
return typeof auth === "function" ? auth(request) : auth;
|
|
43382
43579
|
}
|
|
43383
|
-
async function parseFetchResponse(response) {
|
|
43580
|
+
async function parseFetchResponse(response, responseKind) {
|
|
43581
|
+
if (response.ok && responseKind === "binary") {
|
|
43582
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
43583
|
+
}
|
|
43384
43584
|
const text = await response.text();
|
|
43385
43585
|
if (!text.trim()) return null;
|
|
43386
43586
|
try {
|
|
@@ -43416,8 +43616,9 @@ function createAgentApiFetchTransport(options) {
|
|
|
43416
43616
|
request: async (input) => {
|
|
43417
43617
|
await options.throttle?.beforeRequest?.(input);
|
|
43418
43618
|
const authHeaders = await authHeadersForRequest(options.auth, input);
|
|
43619
|
+
const responseKind = getAgentApiResponseKind(agentApiContract[input.routeKey].response);
|
|
43419
43620
|
const headers = mergeHeaders(
|
|
43420
|
-
{ accept: "application/json" },
|
|
43621
|
+
{ accept: responseKind === "binary" ? "*/*" : "application/json" },
|
|
43421
43622
|
input.body === void 0 ? void 0 : { "content-type": "application/json" },
|
|
43422
43623
|
options.headers,
|
|
43423
43624
|
authHeaders
|
|
@@ -43431,7 +43632,7 @@ function createAgentApiFetchTransport(options) {
|
|
|
43431
43632
|
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
43432
43633
|
try {
|
|
43433
43634
|
const response = await fetchImpl(`${baseUrl}${input.path}`, init);
|
|
43434
|
-
return transportResponseFromFetch(response, await parseFetchResponse(response));
|
|
43635
|
+
return transportResponseFromFetch(response, await parseFetchResponse(response, responseKind));
|
|
43435
43636
|
} catch (cause) {
|
|
43436
43637
|
lastError = cause;
|
|
43437
43638
|
if (attempt === maxAttempts) throw cause;
|
|
@@ -43441,33 +43642,33 @@ function createAgentApiFetchTransport(options) {
|
|
|
43441
43642
|
}
|
|
43442
43643
|
};
|
|
43443
43644
|
}
|
|
43444
|
-
function errorFromRawFailure(
|
|
43445
|
-
if (
|
|
43645
|
+
function errorFromRawFailure(failure3) {
|
|
43646
|
+
if (failure3.reason === "transport_error") {
|
|
43446
43647
|
return {
|
|
43447
43648
|
kind: "transport",
|
|
43448
|
-
reason:
|
|
43449
|
-
message:
|
|
43450
|
-
cause:
|
|
43649
|
+
reason: failure3.reason,
|
|
43650
|
+
message: failure3.message,
|
|
43651
|
+
cause: failure3.cause
|
|
43451
43652
|
};
|
|
43452
43653
|
}
|
|
43453
|
-
if (
|
|
43654
|
+
if (failure3.reason === "http_error") {
|
|
43454
43655
|
return {
|
|
43455
43656
|
kind: "http",
|
|
43456
|
-
reason:
|
|
43457
|
-
message:
|
|
43458
|
-
status:
|
|
43459
|
-
errorCode:
|
|
43460
|
-
suggestedNextAction:
|
|
43461
|
-
response:
|
|
43657
|
+
reason: failure3.reason,
|
|
43658
|
+
message: failure3.message,
|
|
43659
|
+
status: failure3.status ?? 0,
|
|
43660
|
+
errorCode: failure3.errorCode,
|
|
43661
|
+
suggestedNextAction: failure3.suggestedNextAction,
|
|
43662
|
+
response: failure3.response
|
|
43462
43663
|
};
|
|
43463
43664
|
}
|
|
43464
43665
|
return {
|
|
43465
43666
|
kind: "validation",
|
|
43466
|
-
reason:
|
|
43467
|
-
message:
|
|
43468
|
-
status:
|
|
43469
|
-
cause:
|
|
43470
|
-
response:
|
|
43667
|
+
reason: failure3.reason,
|
|
43668
|
+
message: failure3.message,
|
|
43669
|
+
status: failure3.status,
|
|
43670
|
+
cause: failure3.cause,
|
|
43671
|
+
response: failure3.response
|
|
43471
43672
|
};
|
|
43472
43673
|
}
|
|
43473
43674
|
function agentApiClientResultFromRaw(result2) {
|
|
@@ -43515,6 +43716,369 @@ function createAgentApiClient(transportOrOptions, maybeOptions = {}) {
|
|
|
43515
43716
|
};
|
|
43516
43717
|
}
|
|
43517
43718
|
init_esm_shims();
|
|
43719
|
+
var DAEMON_API_BASE_PATH = "/internal/agent-api";
|
|
43720
|
+
var optionalStringSchema2 = external_exports.string().trim().optional();
|
|
43721
|
+
var optionalNonNegativeIntSchema = external_exports.number().int().nonnegative().optional();
|
|
43722
|
+
var optionalQueryIntSchema = external_exports.union([external_exports.number().int().nonnegative(), external_exports.string().trim().min(1)]).optional();
|
|
43723
|
+
var nullableNumberSchema2 = external_exports.number().finite().nullable();
|
|
43724
|
+
var passthroughObject2 = (shape) => external_exports.object(shape).passthrough();
|
|
43725
|
+
var daemonApiInboxFlagSchema = external_exports.enum(["mention", "thread", "dm", "task"]);
|
|
43726
|
+
var daemonApiInboxTargetRowSchema = passthroughObject2({
|
|
43727
|
+
target: external_exports.string().trim().min(1),
|
|
43728
|
+
channelId: optionalStringSchema2,
|
|
43729
|
+
channelType: optionalStringSchema2,
|
|
43730
|
+
pendingCount: external_exports.number().int().nonnegative(),
|
|
43731
|
+
firstPendingMsgId: optionalStringSchema2,
|
|
43732
|
+
firstPendingSeq: optionalNonNegativeIntSchema,
|
|
43733
|
+
latestMsgId: optionalStringSchema2,
|
|
43734
|
+
latestSeq: optionalNonNegativeIntSchema,
|
|
43735
|
+
latestSenderName: optionalStringSchema2,
|
|
43736
|
+
latestSenderType: external_exports.enum(["human", "agent", "system"]).optional(),
|
|
43737
|
+
flags: external_exports.array(daemonApiInboxFlagSchema)
|
|
43738
|
+
});
|
|
43739
|
+
var daemonApiInboxCheckResponseSchema = passthroughObject2({
|
|
43740
|
+
rows: external_exports.array(daemonApiInboxTargetRowSchema).optional()
|
|
43741
|
+
});
|
|
43742
|
+
var daemonApiWakeHintsQuerySchema = passthroughObject2({
|
|
43743
|
+
since: external_exports.union([external_exports.literal("latest"), external_exports.number().int().nonnegative(), external_exports.string().trim().min(1)]).optional(),
|
|
43744
|
+
limit: optionalQueryIntSchema
|
|
43745
|
+
});
|
|
43746
|
+
var daemonApiWakeHintSchema = passthroughObject2({
|
|
43747
|
+
hintId: optionalStringSchema2,
|
|
43748
|
+
hint_id: optionalStringSchema2,
|
|
43749
|
+
eventId: optionalStringSchema2,
|
|
43750
|
+
event_id: optionalStringSchema2,
|
|
43751
|
+
messageId: external_exports.string().nullable().optional(),
|
|
43752
|
+
message_id: external_exports.string().nullable().optional(),
|
|
43753
|
+
seq: optionalNonNegativeIntSchema,
|
|
43754
|
+
id: optionalStringSchema2,
|
|
43755
|
+
target: optionalStringSchema2,
|
|
43756
|
+
targetType: optionalStringSchema2,
|
|
43757
|
+
target_type: optionalStringSchema2,
|
|
43758
|
+
reason: optionalStringSchema2,
|
|
43759
|
+
wake_reason: optionalStringSchema2,
|
|
43760
|
+
createdAt: optionalStringSchema2,
|
|
43761
|
+
created_at: optionalStringSchema2
|
|
43762
|
+
});
|
|
43763
|
+
var daemonApiWakeHintsFetchResponseSchema = passthroughObject2({
|
|
43764
|
+
hints: external_exports.array(daemonApiWakeHintSchema).optional(),
|
|
43765
|
+
wake_hints: external_exports.array(daemonApiWakeHintSchema).optional(),
|
|
43766
|
+
last_seen_hint_seq: nullableNumberSchema2.optional(),
|
|
43767
|
+
last_hint_seq: nullableNumberSchema2.optional(),
|
|
43768
|
+
has_more: external_exports.boolean().optional()
|
|
43769
|
+
});
|
|
43770
|
+
var daemonApiActivityEventSchema = passthroughObject2({
|
|
43771
|
+
schema: optionalStringSchema2
|
|
43772
|
+
});
|
|
43773
|
+
var daemonApiActivityForwardBodySchema = passthroughObject2({
|
|
43774
|
+
schema: external_exports.literal("raft-agent-activity-ingest.v1"),
|
|
43775
|
+
coreSessionId: optionalStringSchema2,
|
|
43776
|
+
adapterInstance: optionalStringSchema2,
|
|
43777
|
+
events: external_exports.array(daemonApiActivityEventSchema),
|
|
43778
|
+
dropped: optionalNonNegativeIntSchema
|
|
43779
|
+
});
|
|
43780
|
+
var daemonApiActivityForwardResponseSchema = passthroughObject2({
|
|
43781
|
+
ok: external_exports.literal(true).optional(),
|
|
43782
|
+
acceptedCount: external_exports.number().int().nonnegative().optional(),
|
|
43783
|
+
rejectedCount: external_exports.number().int().nonnegative().optional(),
|
|
43784
|
+
droppedCount: external_exports.number().int().nonnegative().optional()
|
|
43785
|
+
});
|
|
43786
|
+
function route2(input) {
|
|
43787
|
+
return {
|
|
43788
|
+
...input,
|
|
43789
|
+
fullPath: `${DAEMON_API_BASE_PATH}${input.path}`
|
|
43790
|
+
};
|
|
43791
|
+
}
|
|
43792
|
+
var daemonApiContract = {
|
|
43793
|
+
inboxCheck: route2({
|
|
43794
|
+
key: "inboxCheck",
|
|
43795
|
+
method: "GET",
|
|
43796
|
+
path: "/inbox",
|
|
43797
|
+
client: { resource: "inbox", method: "check" },
|
|
43798
|
+
description: "Read the managed-runner daemon inbox snapshot without draining message content.",
|
|
43799
|
+
request: {},
|
|
43800
|
+
response: { body: daemonApiInboxCheckResponseSchema }
|
|
43801
|
+
}),
|
|
43802
|
+
wakeHintsFetch: route2({
|
|
43803
|
+
key: "wakeHintsFetch",
|
|
43804
|
+
method: "GET",
|
|
43805
|
+
path: "/wake-hints",
|
|
43806
|
+
client: { resource: "wakeHints", method: "fetch" },
|
|
43807
|
+
description: "Peek content-free wake hints without advancing delivery cursors.",
|
|
43808
|
+
request: { query: daemonApiWakeHintsQuerySchema },
|
|
43809
|
+
response: { body: daemonApiWakeHintsFetchResponseSchema }
|
|
43810
|
+
}),
|
|
43811
|
+
activityForward: route2({
|
|
43812
|
+
key: "activityForward",
|
|
43813
|
+
method: "POST",
|
|
43814
|
+
path: "/activity",
|
|
43815
|
+
client: { resource: "activity", method: "forward" },
|
|
43816
|
+
description: "Forward plugin-observed activity from a local bridge to the daemon/server activity ingest path.",
|
|
43817
|
+
request: { body: daemonApiActivityForwardBodySchema },
|
|
43818
|
+
response: { body: daemonApiActivityForwardResponseSchema }
|
|
43819
|
+
})
|
|
43820
|
+
};
|
|
43821
|
+
function parseDaemonApiResponse(routeKey, data) {
|
|
43822
|
+
return daemonApiContract[routeKey].response.body.parse(data);
|
|
43823
|
+
}
|
|
43824
|
+
init_esm_shims();
|
|
43825
|
+
function failure2(routeKey, reason, message, details = {}) {
|
|
43826
|
+
return {
|
|
43827
|
+
ok: false,
|
|
43828
|
+
...routeKey ? { routeKey } : {},
|
|
43829
|
+
reason,
|
|
43830
|
+
message,
|
|
43831
|
+
...details
|
|
43832
|
+
};
|
|
43833
|
+
}
|
|
43834
|
+
function encodeQuery2(routeKey, query) {
|
|
43835
|
+
if (query === void 0) return void 0;
|
|
43836
|
+
const route3 = daemonApiContract[routeKey];
|
|
43837
|
+
let parsed;
|
|
43838
|
+
try {
|
|
43839
|
+
parsed = "query" in route3.request ? route3.request.query.parse(query) : {};
|
|
43840
|
+
} catch (cause) {
|
|
43841
|
+
return failure2(routeKey, "request_contract_mismatch", `Daemon API ${route3.key} query did not match the shared contract`, { cause });
|
|
43842
|
+
}
|
|
43843
|
+
const params = new URLSearchParams();
|
|
43844
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
43845
|
+
if (value === void 0 || value === null) continue;
|
|
43846
|
+
if (Array.isArray(value)) {
|
|
43847
|
+
for (const item of value) params.append(key, String(item));
|
|
43848
|
+
continue;
|
|
43849
|
+
}
|
|
43850
|
+
params.set(key, String(value));
|
|
43851
|
+
}
|
|
43852
|
+
return params;
|
|
43853
|
+
}
|
|
43854
|
+
function parseBody2(routeKey, body) {
|
|
43855
|
+
if (body === void 0) return void 0;
|
|
43856
|
+
const route3 = daemonApiContract[routeKey];
|
|
43857
|
+
try {
|
|
43858
|
+
return "body" in route3.request ? route3.request.body.parse(body) : void 0;
|
|
43859
|
+
} catch (cause) {
|
|
43860
|
+
return failure2(routeKey, "request_contract_mismatch", `Daemon API ${route3.key} body did not match the shared contract`, { cause });
|
|
43861
|
+
}
|
|
43862
|
+
}
|
|
43863
|
+
function isDaemonApiRawFailure(value) {
|
|
43864
|
+
return Boolean(
|
|
43865
|
+
value && typeof value === "object" && value.ok === false && typeof value.reason === "string" && typeof value.message === "string"
|
|
43866
|
+
);
|
|
43867
|
+
}
|
|
43868
|
+
function buildDaemonApiRawRoutePath(routeKey, options = {}) {
|
|
43869
|
+
const route3 = daemonApiContract[routeKey];
|
|
43870
|
+
const query = encodeQuery2(routeKey, options.query);
|
|
43871
|
+
if (query && !(query instanceof URLSearchParams)) return query;
|
|
43872
|
+
const suffix = query && query.size > 0 ? `?${query.toString()}` : "";
|
|
43873
|
+
return `${options.pathPrefix ?? DAEMON_API_BASE_PATH}${route3.path}${suffix}`;
|
|
43874
|
+
}
|
|
43875
|
+
async function requestDaemonApiRawRoute(transport, routeKey, options = {}) {
|
|
43876
|
+
const route3 = daemonApiContract[routeKey];
|
|
43877
|
+
const path9 = buildDaemonApiRawRoutePath(routeKey, options);
|
|
43878
|
+
if (typeof path9 !== "string") return path9;
|
|
43879
|
+
const body = parseBody2(routeKey, options.body);
|
|
43880
|
+
if (isDaemonApiRawFailure(body)) return body;
|
|
43881
|
+
let response;
|
|
43882
|
+
try {
|
|
43883
|
+
response = await transport.request({
|
|
43884
|
+
routeKey,
|
|
43885
|
+
method: route3.method,
|
|
43886
|
+
path: path9,
|
|
43887
|
+
body
|
|
43888
|
+
});
|
|
43889
|
+
} catch (cause) {
|
|
43890
|
+
return failure2(routeKey, "transport_error", `Daemon API ${route3.key} transport request failed`, { cause });
|
|
43891
|
+
}
|
|
43892
|
+
if (!response.ok) {
|
|
43893
|
+
return failure2(routeKey, "http_error", response.error ?? `HTTP ${response.status}`, {
|
|
43894
|
+
status: response.status,
|
|
43895
|
+
errorCode: response.errorCode,
|
|
43896
|
+
suggestedNextAction: response.suggestedNextAction,
|
|
43897
|
+
response: response.data
|
|
43898
|
+
});
|
|
43899
|
+
}
|
|
43900
|
+
if (response.data === null) {
|
|
43901
|
+
return failure2(routeKey, "empty_response", `Daemon API ${route3.key} returned an empty response body`, {
|
|
43902
|
+
status: response.status
|
|
43903
|
+
});
|
|
43904
|
+
}
|
|
43905
|
+
try {
|
|
43906
|
+
return {
|
|
43907
|
+
ok: true,
|
|
43908
|
+
routeKey,
|
|
43909
|
+
status: response.status,
|
|
43910
|
+
data: parseDaemonApiResponse(routeKey, response.data)
|
|
43911
|
+
};
|
|
43912
|
+
} catch (cause) {
|
|
43913
|
+
return failure2(routeKey, "response_contract_mismatch", `Daemon API ${route3.key} response did not match the shared contract`, {
|
|
43914
|
+
status: response.status,
|
|
43915
|
+
cause,
|
|
43916
|
+
response: response.data
|
|
43917
|
+
});
|
|
43918
|
+
}
|
|
43919
|
+
}
|
|
43920
|
+
function requestOptionsFromMethodArgs2(routeKey, pathPrefix, args) {
|
|
43921
|
+
const route3 = daemonApiContract[routeKey];
|
|
43922
|
+
let index = 0;
|
|
43923
|
+
const requestOptions = { pathPrefix };
|
|
43924
|
+
if ("query" in route3.request) {
|
|
43925
|
+
requestOptions.query = args[index++];
|
|
43926
|
+
}
|
|
43927
|
+
if ("body" in route3.request) {
|
|
43928
|
+
requestOptions.body = args[index++];
|
|
43929
|
+
}
|
|
43930
|
+
return requestOptions;
|
|
43931
|
+
}
|
|
43932
|
+
function createDaemonApiRawClient(transport, options = {}) {
|
|
43933
|
+
const pathPrefix = options.pathPrefix ?? DAEMON_API_BASE_PATH;
|
|
43934
|
+
const client = {};
|
|
43935
|
+
for (const route3 of Object.values(daemonApiContract)) {
|
|
43936
|
+
const routeKey = route3.key;
|
|
43937
|
+
const { resource, method } = route3.client;
|
|
43938
|
+
const resourceClient = client[resource] ??= {};
|
|
43939
|
+
resourceClient[method] = (...args) => requestDaemonApiRawRoute(
|
|
43940
|
+
transport,
|
|
43941
|
+
routeKey,
|
|
43942
|
+
requestOptionsFromMethodArgs2(routeKey, pathPrefix, args)
|
|
43943
|
+
);
|
|
43944
|
+
}
|
|
43945
|
+
return client;
|
|
43946
|
+
}
|
|
43947
|
+
init_esm_shims();
|
|
43948
|
+
function normalizeBaseUrl2(baseUrl) {
|
|
43949
|
+
return baseUrl.replace(/\/+$/, "");
|
|
43950
|
+
}
|
|
43951
|
+
function mergeHeaders2(...headers) {
|
|
43952
|
+
return Object.assign({}, ...headers.filter(Boolean));
|
|
43953
|
+
}
|
|
43954
|
+
async function authHeadersForRequest2(auth, request) {
|
|
43955
|
+
if (!auth) return void 0;
|
|
43956
|
+
return typeof auth === "function" ? auth(request) : auth;
|
|
43957
|
+
}
|
|
43958
|
+
async function parseFetchResponse2(response) {
|
|
43959
|
+
const text = await response.text();
|
|
43960
|
+
if (!text.trim()) return null;
|
|
43961
|
+
try {
|
|
43962
|
+
return JSON.parse(text);
|
|
43963
|
+
} catch {
|
|
43964
|
+
return text;
|
|
43965
|
+
}
|
|
43966
|
+
}
|
|
43967
|
+
function transportResponseFromFetch2(response, data) {
|
|
43968
|
+
if (response.ok) {
|
|
43969
|
+
return {
|
|
43970
|
+
ok: true,
|
|
43971
|
+
status: response.status,
|
|
43972
|
+
data,
|
|
43973
|
+
error: null
|
|
43974
|
+
};
|
|
43975
|
+
}
|
|
43976
|
+
const objectData = data && typeof data === "object" ? data : {};
|
|
43977
|
+
return {
|
|
43978
|
+
ok: false,
|
|
43979
|
+
status: response.status,
|
|
43980
|
+
data,
|
|
43981
|
+
error: typeof objectData.error === "string" ? objectData.error : response.statusText || `HTTP ${response.status}`,
|
|
43982
|
+
errorCode: typeof objectData.errorCode === "string" ? objectData.errorCode : null,
|
|
43983
|
+
suggestedNextAction: typeof objectData.suggestedNextAction === "string" ? objectData.suggestedNextAction : null
|
|
43984
|
+
};
|
|
43985
|
+
}
|
|
43986
|
+
function createDaemonApiFetchTransport(options) {
|
|
43987
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
43988
|
+
const baseUrl = normalizeBaseUrl2(options.baseUrl);
|
|
43989
|
+
return {
|
|
43990
|
+
request: async (input) => {
|
|
43991
|
+
const authHeaders = await authHeadersForRequest2(options.auth, input);
|
|
43992
|
+
const headers = mergeHeaders2(
|
|
43993
|
+
{ accept: "application/json" },
|
|
43994
|
+
input.body === void 0 ? void 0 : { "content-type": "application/json" },
|
|
43995
|
+
options.headers,
|
|
43996
|
+
authHeaders
|
|
43997
|
+
);
|
|
43998
|
+
const init = {
|
|
43999
|
+
method: input.method,
|
|
44000
|
+
headers,
|
|
44001
|
+
body: input.body === void 0 ? void 0 : JSON.stringify(input.body)
|
|
44002
|
+
};
|
|
44003
|
+
const response = await fetchImpl(`${baseUrl}${input.path}`, init);
|
|
44004
|
+
return transportResponseFromFetch2(response, await parseFetchResponse2(response));
|
|
44005
|
+
}
|
|
44006
|
+
};
|
|
44007
|
+
}
|
|
44008
|
+
function errorFromRawFailure2(failure3) {
|
|
44009
|
+
if (failure3.reason === "transport_error") {
|
|
44010
|
+
return {
|
|
44011
|
+
kind: "transport",
|
|
44012
|
+
reason: failure3.reason,
|
|
44013
|
+
message: failure3.message,
|
|
44014
|
+
cause: failure3.cause
|
|
44015
|
+
};
|
|
44016
|
+
}
|
|
44017
|
+
if (failure3.reason === "http_error") {
|
|
44018
|
+
return {
|
|
44019
|
+
kind: "http",
|
|
44020
|
+
reason: failure3.reason,
|
|
44021
|
+
message: failure3.message,
|
|
44022
|
+
status: failure3.status ?? 0,
|
|
44023
|
+
errorCode: failure3.errorCode,
|
|
44024
|
+
suggestedNextAction: failure3.suggestedNextAction,
|
|
44025
|
+
response: failure3.response
|
|
44026
|
+
};
|
|
44027
|
+
}
|
|
44028
|
+
return {
|
|
44029
|
+
kind: "validation",
|
|
44030
|
+
reason: failure3.reason,
|
|
44031
|
+
message: failure3.message,
|
|
44032
|
+
status: failure3.status,
|
|
44033
|
+
cause: failure3.cause,
|
|
44034
|
+
response: failure3.response
|
|
44035
|
+
};
|
|
44036
|
+
}
|
|
44037
|
+
function daemonApiClientResultFromRaw(result2) {
|
|
44038
|
+
if (result2.ok) {
|
|
44039
|
+
const success2 = result2;
|
|
44040
|
+
return {
|
|
44041
|
+
ok: true,
|
|
44042
|
+
routeKey: success2.routeKey,
|
|
44043
|
+
status: success2.status,
|
|
44044
|
+
data: success2.data
|
|
44045
|
+
};
|
|
44046
|
+
}
|
|
44047
|
+
return {
|
|
44048
|
+
ok: false,
|
|
44049
|
+
routeKey: result2.routeKey,
|
|
44050
|
+
status: result2.status,
|
|
44051
|
+
error: errorFromRawFailure2(result2)
|
|
44052
|
+
};
|
|
44053
|
+
}
|
|
44054
|
+
function wrapRawClient2(rawClient) {
|
|
44055
|
+
const client = {};
|
|
44056
|
+
for (const [resource, methods] of Object.entries(rawClient)) {
|
|
44057
|
+
client[resource] = {};
|
|
44058
|
+
for (const [method, rawMethod] of Object.entries(methods)) {
|
|
44059
|
+
client[resource][method] = async (...args) => daemonApiClientResultFromRaw(await rawMethod(...args));
|
|
44060
|
+
}
|
|
44061
|
+
}
|
|
44062
|
+
return client;
|
|
44063
|
+
}
|
|
44064
|
+
function createDaemonApiClient(transportOrOptions, maybeOptions = {}) {
|
|
44065
|
+
const options = "request" in transportOrOptions ? { ...maybeOptions, transport: transportOrOptions } : transportOrOptions;
|
|
44066
|
+
const transport = options.transport ?? (options.fetch ? createDaemonApiFetchTransport(options.fetch) : void 0);
|
|
44067
|
+
if (!transport) {
|
|
44068
|
+
throw new Error("createDaemonApiClient requires either a transport or fetch options");
|
|
44069
|
+
}
|
|
44070
|
+
const pathPrefix = options.pathPrefix ?? DAEMON_API_BASE_PATH;
|
|
44071
|
+
const rawClient = createDaemonApiRawClient(transport, { pathPrefix });
|
|
44072
|
+
const generated = wrapRawClient2(rawClient);
|
|
44073
|
+
return {
|
|
44074
|
+
...generated,
|
|
44075
|
+
request: async (routeKey, requestOptions = {}) => daemonApiClientResultFromRaw(await requestDaemonApiRawRoute(transport, routeKey, {
|
|
44076
|
+
pathPrefix,
|
|
44077
|
+
...requestOptions
|
|
44078
|
+
}))
|
|
44079
|
+
};
|
|
44080
|
+
}
|
|
44081
|
+
init_esm_shims();
|
|
43518
44082
|
function formatAgentInboxSnapshot(rows) {
|
|
43519
44083
|
if (rows.length === 0) return "Inbox: empty";
|
|
43520
44084
|
return [
|
|
@@ -44026,66 +44590,84 @@ function buildAgentApiEventsPath(query) {
|
|
|
44026
44590
|
}
|
|
44027
44591
|
function rawTransportForClient(client) {
|
|
44028
44592
|
return {
|
|
44029
|
-
request: async (input) =>
|
|
44593
|
+
request: async (input) => {
|
|
44594
|
+
const route3 = agentApiContract[input.routeKey];
|
|
44595
|
+
if (getAgentApiResponseKind(route3.response) === "binary") {
|
|
44596
|
+
if (typeof client.requestBinary !== "function") {
|
|
44597
|
+
throw new CliError({
|
|
44598
|
+
code: "VIEW_FAILED",
|
|
44599
|
+
message: "Agent API binary download transport is unavailable in this CLI context"
|
|
44600
|
+
});
|
|
44601
|
+
}
|
|
44602
|
+
const response = await client.requestBinary(input.method, input.path);
|
|
44603
|
+
return {
|
|
44604
|
+
ok: response.ok,
|
|
44605
|
+
status: response.status,
|
|
44606
|
+
data: response.ok ? response.body : null,
|
|
44607
|
+
error: response.error
|
|
44608
|
+
};
|
|
44609
|
+
}
|
|
44610
|
+
return client.request(input.method, input.path, input.body);
|
|
44611
|
+
}
|
|
44030
44612
|
};
|
|
44031
44613
|
}
|
|
44032
|
-
function cliErrorFromRawFailure(
|
|
44033
|
-
switch (
|
|
44614
|
+
function cliErrorFromRawFailure(failure3) {
|
|
44615
|
+
switch (failure3.reason) {
|
|
44034
44616
|
case "missing_path_param":
|
|
44035
44617
|
case "request_contract_mismatch":
|
|
44036
44618
|
return new CliError({
|
|
44037
44619
|
code: "INVALID_ARG",
|
|
44038
|
-
message:
|
|
44039
|
-
cause:
|
|
44620
|
+
message: failure3.message,
|
|
44621
|
+
cause: failure3.cause
|
|
44040
44622
|
});
|
|
44041
44623
|
case "empty_response":
|
|
44042
44624
|
case "response_contract_mismatch":
|
|
44043
44625
|
case "missing_route":
|
|
44044
44626
|
return new CliError({
|
|
44045
44627
|
code: "INVALID_JSON_RESPONSE",
|
|
44046
|
-
message:
|
|
44047
|
-
cause:
|
|
44628
|
+
message: failure3.message,
|
|
44629
|
+
cause: failure3.cause
|
|
44048
44630
|
});
|
|
44049
44631
|
case "transport_error":
|
|
44050
44632
|
case "http_error":
|
|
44051
44633
|
return new CliError({
|
|
44052
44634
|
code: "CHECK_FAILED",
|
|
44053
|
-
message:
|
|
44054
|
-
cause:
|
|
44635
|
+
message: failure3.message,
|
|
44636
|
+
cause: failure3.cause
|
|
44055
44637
|
});
|
|
44056
44638
|
}
|
|
44057
44639
|
}
|
|
44058
|
-
function cliErrorFromClientFailure(
|
|
44059
|
-
switch (
|
|
44640
|
+
function cliErrorFromClientFailure(failure3) {
|
|
44641
|
+
switch (failure3.error.kind) {
|
|
44060
44642
|
case "validation":
|
|
44061
|
-
switch (
|
|
44643
|
+
switch (failure3.error.reason) {
|
|
44062
44644
|
case "missing_path_param":
|
|
44063
44645
|
case "request_contract_mismatch":
|
|
44064
44646
|
return new CliError({
|
|
44065
44647
|
code: "INVALID_ARG",
|
|
44066
|
-
message:
|
|
44067
|
-
cause:
|
|
44648
|
+
message: failure3.error.message,
|
|
44649
|
+
cause: failure3.error.cause
|
|
44068
44650
|
});
|
|
44069
44651
|
case "empty_response":
|
|
44070
44652
|
case "response_contract_mismatch":
|
|
44071
44653
|
case "missing_route":
|
|
44072
44654
|
return new CliError({
|
|
44073
44655
|
code: "INVALID_JSON_RESPONSE",
|
|
44074
|
-
message:
|
|
44075
|
-
cause:
|
|
44656
|
+
message: failure3.error.message,
|
|
44657
|
+
cause: failure3.error.cause
|
|
44076
44658
|
});
|
|
44077
44659
|
}
|
|
44078
44660
|
break;
|
|
44079
44661
|
case "transport":
|
|
44080
44662
|
return new CliError({
|
|
44081
44663
|
code: "CHECK_FAILED",
|
|
44082
|
-
message:
|
|
44083
|
-
cause:
|
|
44664
|
+
message: failure3.error.message,
|
|
44665
|
+
cause: failure3.error.cause
|
|
44084
44666
|
});
|
|
44085
44667
|
case "http":
|
|
44086
44668
|
return new CliError({
|
|
44087
44669
|
code: "CHECK_FAILED",
|
|
44088
|
-
message:
|
|
44670
|
+
message: failure3.error.message
|
|
44089
44671
|
});
|
|
44090
44672
|
}
|
|
44091
44673
|
}
|
|
@@ -44147,38 +44729,20 @@ async function requestMultipartContractAgentApiRoute(client, routeKey, form) {
|
|
|
44147
44729
|
});
|
|
44148
44730
|
}
|
|
44149
44731
|
}
|
|
44150
|
-
function
|
|
44151
|
-
const agentApi = createAgentApiClient(rawTransportForClient(client)
|
|
44152
|
-
pathPrefix: buildLegacyAgentApiPath(agentId, "")
|
|
44153
|
-
});
|
|
44732
|
+
function createAgentApiSurfaceClient(client) {
|
|
44733
|
+
const agentApi = createAgentApiClient(rawTransportForClient(client));
|
|
44154
44734
|
return {
|
|
44155
44735
|
server: {
|
|
44156
44736
|
info: () => requestClientAsApiResponse(agentApi.server.info())
|
|
44157
44737
|
},
|
|
44738
|
+
events: {
|
|
44739
|
+
get: (query) => requestClientAsApiResponse(agentApi.events.get(query))
|
|
44740
|
+
},
|
|
44158
44741
|
history: {
|
|
44159
44742
|
read: (query) => requestClientAsApiResponse(agentApi.history.read(query))
|
|
44160
44743
|
},
|
|
44161
|
-
|
|
44162
|
-
|
|
44163
|
-
resolve: (params) => requestClientAsApiResponse(agentApi.messages.resolve(params)),
|
|
44164
|
-
addReaction: (params, body) => requestClientAsApiResponse(agentApi.messages.addReaction(params, body)),
|
|
44165
|
-
removeReaction: (params, body) => requestClientAsApiResponse(agentApi.messages.removeReaction(params, body))
|
|
44166
|
-
},
|
|
44167
|
-
channels: {
|
|
44168
|
-
join: (params) => requestClientAsApiResponse(agentApi.channels.join(params)),
|
|
44169
|
-
leave: (params) => requestClientAsApiResponse(agentApi.channels.leave(params))
|
|
44170
|
-
},
|
|
44171
|
-
mentions: {
|
|
44172
|
-
pendingActions: (query) => requestClientAsApiResponse(agentApi.mentions.pendingActions(query ?? {})),
|
|
44173
|
-
executeAction: (body) => requestClientAsApiResponse(agentApi.mentions.executeAction(body))
|
|
44174
|
-
}
|
|
44175
|
-
};
|
|
44176
|
-
}
|
|
44177
|
-
function createAgentApiSurfaceClient(client) {
|
|
44178
|
-
const agentApi = createAgentApiClient(rawTransportForClient(client));
|
|
44179
|
-
return {
|
|
44180
|
-
events: {
|
|
44181
|
-
get: (query) => requestClientAsApiResponse(agentApi.events.get(query))
|
|
44744
|
+
knowledge: {
|
|
44745
|
+
get: (query) => requestClientAsApiResponse(agentApi.knowledge.get(query))
|
|
44182
44746
|
},
|
|
44183
44747
|
tasks: {
|
|
44184
44748
|
list: (query) => requestClientAsApiResponse(agentApi.tasks.list(query)),
|
|
@@ -44196,9 +44760,17 @@ function createAgentApiSurfaceClient(client) {
|
|
|
44196
44760
|
log: (params) => requestClientAsApiResponse(agentApi.reminders.log(params))
|
|
44197
44761
|
},
|
|
44198
44762
|
messages: {
|
|
44199
|
-
|
|
44763
|
+
send: (body) => requestClientAsApiResponse(agentApi.messages.send(body)),
|
|
44764
|
+
resolve: (params) => requestClientAsApiResponse(agentApi.messages.resolve(params)),
|
|
44765
|
+
search: (query) => requestClientAsApiResponse(agentApi.messages.search(query)),
|
|
44766
|
+
addReaction: (params, body) => requestClientAsApiResponse(agentApi.messages.addReaction(params, body)),
|
|
44767
|
+
removeReaction: (params, body) => requestClientAsApiResponse(agentApi.messages.removeReaction(params, body))
|
|
44200
44768
|
},
|
|
44201
44769
|
channels: {
|
|
44770
|
+
join: (params) => requestClientAsApiResponse(agentApi.channels.join(params)),
|
|
44771
|
+
leave: (params) => requestClientAsApiResponse(agentApi.channels.leave(params)),
|
|
44772
|
+
mute: (params) => requestClientAsApiResponse(agentApi.channels.mute(params)),
|
|
44773
|
+
unmute: (params) => requestClientAsApiResponse(agentApi.channels.unmute(params)),
|
|
44202
44774
|
members: (query) => requestClientAsApiResponse(agentApi.channels.members(query)),
|
|
44203
44775
|
resolve: (body) => requestClientAsApiResponse(agentApi.channels.resolve(body))
|
|
44204
44776
|
},
|
|
@@ -44207,18 +44779,27 @@ function createAgentApiSurfaceClient(client) {
|
|
|
44207
44779
|
},
|
|
44208
44780
|
profile: {
|
|
44209
44781
|
show: (query) => requestClientAsApiResponse(agentApi.profile.show(query)),
|
|
44210
|
-
update: (body) => requestClientAsApiResponse(agentApi.profile.update(body))
|
|
44782
|
+
update: (body) => requestClientAsApiResponse(agentApi.profile.update(body)),
|
|
44783
|
+
updateAvatar: (form) => requestMultipartContractAgentApiRoute(client, "profileAvatarUpdate", form)
|
|
44211
44784
|
},
|
|
44212
44785
|
integrations: {
|
|
44213
44786
|
list: () => requestClientAsApiResponse(agentApi.integrations.list()),
|
|
44214
44787
|
login: (body) => requestClientAsApiResponse(agentApi.integrations.login(body)),
|
|
44215
|
-
prepareApp: (body) => requestClientAsApiResponse(agentApi.integrations.prepareApp(body))
|
|
44788
|
+
prepareApp: (body) => requestClientAsApiResponse(agentApi.integrations.prepareApp(body)),
|
|
44789
|
+
rotateAppSecret: (body) => requestClientAsApiResponse(agentApi.integrations.rotateAppSecret(body))
|
|
44216
44790
|
},
|
|
44217
44791
|
actions: {
|
|
44218
44792
|
prepare: (body) => requestClientAsApiResponse(agentApi.actions.prepare(body))
|
|
44219
44793
|
},
|
|
44794
|
+
mentions: {
|
|
44795
|
+
pendingActions: (query) => requestClientAsApiResponse(agentApi.mentions.pendingActions(query ?? {})),
|
|
44796
|
+
executeAction: (body) => requestClientAsApiResponse(agentApi.mentions.executeAction(body))
|
|
44797
|
+
},
|
|
44220
44798
|
attachments: {
|
|
44221
|
-
upload: (form) => requestMultipartContractAgentApiRoute(client, "attachmentUpload", form)
|
|
44799
|
+
upload: (form) => requestMultipartContractAgentApiRoute(client, "attachmentUpload", form),
|
|
44800
|
+
download: (params) => requestClientAsApiResponse(agentApi.attachments.download(params)),
|
|
44801
|
+
view: (params) => requestClientAsApiResponse(agentApi.attachments.download(params)),
|
|
44802
|
+
comments: (params, query = {}) => requestClientAsApiResponse(agentApi.attachments.comments(params, query))
|
|
44222
44803
|
}
|
|
44223
44804
|
};
|
|
44224
44805
|
}
|
|
@@ -44307,7 +44888,6 @@ function routeFamilyForPath(pathname) {
|
|
|
44307
44888
|
if (normalized === "/internal/agent-api/activity") return "agent-api/activity";
|
|
44308
44889
|
if (normalized === "/internal/agent-api/events") return "agent-api/events";
|
|
44309
44890
|
if (normalized === "/internal/agent-api/inbox") return "agent-api/inbox";
|
|
44310
|
-
if (normalized === "/internal/agent-api/receive-ack") return "agent-api/events";
|
|
44311
44891
|
if (normalized === "/internal/agent-api/tasks/claim") return "tasks/claim";
|
|
44312
44892
|
if (normalized === "/internal/agent-api/tasks/update-status") return "tasks/update";
|
|
44313
44893
|
if (normalized === "/internal/agent-api/tasks" || normalized.startsWith("/internal/agent-api/tasks/")) {
|
|
@@ -44337,7 +44917,7 @@ function routeFamilyForPath(pathname) {
|
|
|
44337
44917
|
const firstAfterAgentId = parts[3] ?? "unknown";
|
|
44338
44918
|
if (firstAfterAgentId === "server") return "server";
|
|
44339
44919
|
if (firstAfterAgentId === "send") return "agent-api/send";
|
|
44340
|
-
if (firstAfterAgentId === "history" || firstAfterAgentId === "search" || firstAfterAgentId === "receive"
|
|
44920
|
+
if (firstAfterAgentId === "history" || firstAfterAgentId === "search" || firstAfterAgentId === "receive") {
|
|
44341
44921
|
return "agent-api/events";
|
|
44342
44922
|
}
|
|
44343
44923
|
if (firstAfterAgentId === "channel-members") return "channel-members";
|
|
@@ -44440,6 +45020,7 @@ var ApiClient = class {
|
|
|
44440
45020
|
if (!pathname.startsWith(agentPrefix)) return pathname;
|
|
44441
45021
|
const suffix = pathname.slice(agentPrefix.length);
|
|
44442
45022
|
if (suffix === "/server") return "/internal/agent-api/server";
|
|
45023
|
+
if (suffix === "/server/avatar") return "/internal/agent-api/server/avatar";
|
|
44443
45024
|
if (suffix === "/send") return "/internal/agent-api/send";
|
|
44444
45025
|
if (suffix.startsWith("/history")) return `/internal/agent-api/history${suffix.slice("/history".length)}`;
|
|
44445
45026
|
if (suffix.startsWith("/search")) return `/internal/agent-api/search${suffix.slice("/search".length)}`;
|
|
@@ -44457,6 +45038,7 @@ var ApiClient = class {
|
|
|
44457
45038
|
if (suffix === "/resolve-channel") return "/internal/agent-api/resolve-channel";
|
|
44458
45039
|
if (suffix === "/threads/unfollow") return "/internal/agent-api/threads/unfollow";
|
|
44459
45040
|
if (suffix === "/prepare-action") return "/internal/agent-api/prepare-action";
|
|
45041
|
+
if (suffix === "/channels") return "/internal/agent-api/channels";
|
|
44460
45042
|
if (suffix === "/tasks" || suffix.startsWith("/tasks?") || suffix.startsWith("/tasks/")) {
|
|
44461
45043
|
return `/internal/agent-api${suffix}`;
|
|
44462
45044
|
}
|
|
@@ -44477,6 +45059,14 @@ var ApiClient = class {
|
|
|
44477
45059
|
if (channelMembership) {
|
|
44478
45060
|
return `/internal/agent-api/channels/${channelMembership[1]}/${channelMembership[2]}`;
|
|
44479
45061
|
}
|
|
45062
|
+
const channelUpdate = /^\/channels\/([^/]+)$/.exec(suffix);
|
|
45063
|
+
if (channelUpdate) {
|
|
45064
|
+
return `/internal/agent-api/channels/${channelUpdate[1]}`;
|
|
45065
|
+
}
|
|
45066
|
+
const channelAddMember = /^\/channels\/([^/]+)\/members$/.exec(suffix);
|
|
45067
|
+
if (channelAddMember) {
|
|
45068
|
+
return `/internal/agent-api/channels/${channelAddMember[1]}/members`;
|
|
45069
|
+
}
|
|
44480
45070
|
return pathname;
|
|
44481
45071
|
}
|
|
44482
45072
|
normalizeAgentCredentialResponse(pathname, data) {
|
|
@@ -44616,10 +45206,7 @@ var ApiClient = class {
|
|
|
44616
45206
|
const res = await this.fetchWithTransportTrace(url2, pathname, init);
|
|
44617
45207
|
return this.parseJsonResponse(res);
|
|
44618
45208
|
}
|
|
44619
|
-
|
|
44620
|
-
// For non-JSON downloads (binary attachments). Caller is responsible for
|
|
44621
|
-
// consuming the body. On non-2xx, attempts to surface a JSON error.
|
|
44622
|
-
async requestRaw(method, pathname) {
|
|
45209
|
+
async requestBody(method, pathname) {
|
|
44623
45210
|
pathname = this.rewriteAgentCredentialPath(pathname);
|
|
44624
45211
|
const url2 = new URL(pathname, this.ctx.serverUrl);
|
|
44625
45212
|
const dispatcher = buildFetchDispatcher(url2.toString());
|
|
@@ -44646,6 +45233,21 @@ var ApiClient = class {
|
|
|
44646
45233
|
}
|
|
44647
45234
|
return { ok: res.ok, status: res.status, response: res, error: error48 };
|
|
44648
45235
|
}
|
|
45236
|
+
async requestBinary(method, pathname) {
|
|
45237
|
+
const res = await this.requestBody(method, pathname);
|
|
45238
|
+
if (!res.ok) {
|
|
45239
|
+
return { ok: false, status: res.status, body: new Uint8Array(), error: res.error };
|
|
45240
|
+
}
|
|
45241
|
+
return {
|
|
45242
|
+
ok: true,
|
|
45243
|
+
status: res.status,
|
|
45244
|
+
body: new Uint8Array(await res.response.arrayBuffer()),
|
|
45245
|
+
error: null
|
|
45246
|
+
};
|
|
45247
|
+
}
|
|
45248
|
+
async streamWakeHints(query) {
|
|
45249
|
+
return this.requestBody("GET", `/internal/agent-api/wake-hints/stream?${query.toString()}`);
|
|
45250
|
+
}
|
|
44649
45251
|
};
|
|
44650
45252
|
init_esm_shims();
|
|
44651
45253
|
var RAW_AGENT_ENV_KEYS = [
|
|
@@ -44714,21 +45316,21 @@ function readProfileCredential(slug, env) {
|
|
|
44714
45316
|
}
|
|
44715
45317
|
return { filePath, data: parsed };
|
|
44716
45318
|
}
|
|
44717
|
-
function readTokenFromFile(filePath) {
|
|
45319
|
+
function readTokenFromFile(filePath, envName) {
|
|
44718
45320
|
let raw;
|
|
44719
45321
|
try {
|
|
44720
45322
|
raw = fs.readFileSync(filePath, "utf-8");
|
|
44721
45323
|
} catch (err) {
|
|
44722
45324
|
throw new AgentBootstrapError(
|
|
44723
45325
|
"TOKEN_FILE_UNREADABLE",
|
|
44724
|
-
|
|
45326
|
+
`${envName}=${filePath} could not be read: ${err.message}`
|
|
44725
45327
|
);
|
|
44726
45328
|
}
|
|
44727
45329
|
const token = raw.trim();
|
|
44728
45330
|
if (!token) {
|
|
44729
45331
|
throw new AgentBootstrapError(
|
|
44730
45332
|
"TOKEN_FILE_EMPTY",
|
|
44731
|
-
|
|
45333
|
+
`${envName}=${filePath} is empty`
|
|
44732
45334
|
);
|
|
44733
45335
|
}
|
|
44734
45336
|
return token;
|
|
@@ -44781,7 +45383,7 @@ function loadAgentContext(env = process.env) {
|
|
|
44781
45383
|
"Set only one of SLOCK_AGENT_PROXY_TOKEN or SLOCK_AGENT_PROXY_TOKEN_FILE"
|
|
44782
45384
|
);
|
|
44783
45385
|
}
|
|
44784
|
-
const token = agentProxyToken ?? (agentProxyTokenFile ? readTokenFromFile(agentProxyTokenFile) : null);
|
|
45386
|
+
const token = agentProxyToken ?? (agentProxyTokenFile ? readTokenFromFile(agentProxyTokenFile, "SLOCK_AGENT_PROXY_TOKEN_FILE") : null);
|
|
44785
45387
|
if (!token) {
|
|
44786
45388
|
throw new AgentBootstrapError(
|
|
44787
45389
|
"MISSING_AGENT_PROXY_TOKEN",
|
|
@@ -44799,32 +45401,16 @@ function loadAgentContext(env = process.env) {
|
|
|
44799
45401
|
};
|
|
44800
45402
|
}
|
|
44801
45403
|
const tokenFile = env.SLOCK_AGENT_TOKEN_FILE;
|
|
44802
|
-
if (tokenFile) {
|
|
44803
|
-
return {
|
|
44804
|
-
agentId,
|
|
44805
|
-
serverUrl,
|
|
44806
|
-
serverId,
|
|
44807
|
-
token: readTokenFromFile(tokenFile),
|
|
44808
|
-
clientMode: "legacy-machine",
|
|
44809
|
-
secretSource: "legacy-token-file",
|
|
44810
|
-
activeCapabilities
|
|
44811
|
-
};
|
|
44812
|
-
}
|
|
44813
45404
|
const tokenLiteral = env.SLOCK_AGENT_TOKEN;
|
|
44814
|
-
if (tokenLiteral) {
|
|
44815
|
-
|
|
44816
|
-
|
|
44817
|
-
|
|
44818
|
-
|
|
44819
|
-
token: tokenLiteral,
|
|
44820
|
-
clientMode: "legacy-machine",
|
|
44821
|
-
secretSource: "legacy-token-env",
|
|
44822
|
-
activeCapabilities
|
|
44823
|
-
};
|
|
45405
|
+
if (tokenFile || tokenLiteral) {
|
|
45406
|
+
throw new AgentBootstrapError(
|
|
45407
|
+
"LEGACY_MACHINE_UNSUPPORTED",
|
|
45408
|
+
"SLOCK_AGENT_TOKEN_FILE/SLOCK_AGENT_TOKEN machine-token bootstrap is no longer supported by this CLI. Upgrade or restart the daemon so it injects SLOCK_AGENT_PROXY_URL plus SLOCK_AGENT_PROXY_TOKEN_FILE, or use RAFT_PROFILE with a credential from `raft agent login`."
|
|
45409
|
+
);
|
|
44824
45410
|
}
|
|
44825
45411
|
throw new AgentBootstrapError(
|
|
44826
45412
|
"MISSING_TOKEN",
|
|
44827
|
-
"Neither SLOCK_AGENT_PROXY_TOKEN_FILE
|
|
45413
|
+
"Neither SLOCK_AGENT_PROXY_TOKEN_FILE nor SLOCK_AGENT_PROXY_TOKEN is set. The daemon should inject proxy credentials when spawning the agent process, or use RAFT_PROFILE with a credential from `raft agent login`."
|
|
44828
45414
|
);
|
|
44829
45415
|
}
|
|
44830
45416
|
init_esm_shims();
|
|
@@ -45677,6 +46263,82 @@ function describeMintError(code, serverUrl) {
|
|
|
45677
46263
|
}
|
|
45678
46264
|
init_esm_shims();
|
|
45679
46265
|
init_esm_shims();
|
|
46266
|
+
function rawTransportForClient2(client) {
|
|
46267
|
+
return {
|
|
46268
|
+
request: (input) => client.request(input.method, input.path, input.body)
|
|
46269
|
+
};
|
|
46270
|
+
}
|
|
46271
|
+
function cliErrorFromClientFailure2(failure3) {
|
|
46272
|
+
switch (failure3.error.kind) {
|
|
46273
|
+
case "validation":
|
|
46274
|
+
switch (failure3.error.reason) {
|
|
46275
|
+
case "request_contract_mismatch":
|
|
46276
|
+
return new CliError({
|
|
46277
|
+
code: "INVALID_ARG",
|
|
46278
|
+
message: failure3.error.message,
|
|
46279
|
+
cause: failure3.error.cause
|
|
46280
|
+
});
|
|
46281
|
+
case "empty_response":
|
|
46282
|
+
case "response_contract_mismatch":
|
|
46283
|
+
return new CliError({
|
|
46284
|
+
code: "INVALID_JSON_RESPONSE",
|
|
46285
|
+
message: failure3.error.message,
|
|
46286
|
+
cause: failure3.error.cause
|
|
46287
|
+
});
|
|
46288
|
+
}
|
|
46289
|
+
break;
|
|
46290
|
+
case "transport":
|
|
46291
|
+
return new CliError({
|
|
46292
|
+
code: "CHECK_FAILED",
|
|
46293
|
+
message: failure3.error.message,
|
|
46294
|
+
cause: failure3.error.cause
|
|
46295
|
+
});
|
|
46296
|
+
case "http":
|
|
46297
|
+
return new CliError({
|
|
46298
|
+
code: "CHECK_FAILED",
|
|
46299
|
+
message: failure3.error.message
|
|
46300
|
+
});
|
|
46301
|
+
}
|
|
46302
|
+
}
|
|
46303
|
+
function apiResponseFromClientResult2(result2) {
|
|
46304
|
+
if (result2.ok) {
|
|
46305
|
+
return {
|
|
46306
|
+
ok: true,
|
|
46307
|
+
status: result2.status,
|
|
46308
|
+
data: result2.data,
|
|
46309
|
+
error: null
|
|
46310
|
+
};
|
|
46311
|
+
}
|
|
46312
|
+
if (result2.error.kind === "http") {
|
|
46313
|
+
return {
|
|
46314
|
+
ok: false,
|
|
46315
|
+
status: result2.error.status,
|
|
46316
|
+
data: null,
|
|
46317
|
+
error: result2.error.message,
|
|
46318
|
+
errorCode: result2.error.errorCode,
|
|
46319
|
+
suggestedNextAction: result2.error.suggestedNextAction
|
|
46320
|
+
};
|
|
46321
|
+
}
|
|
46322
|
+
throw cliErrorFromClientFailure2(result2);
|
|
46323
|
+
}
|
|
46324
|
+
async function requestClientAsApiResponse2(result2) {
|
|
46325
|
+
return apiResponseFromClientResult2(await result2);
|
|
46326
|
+
}
|
|
46327
|
+
function createDaemonApiSurfaceClient(client) {
|
|
46328
|
+
const daemonApi = createDaemonApiClient(rawTransportForClient2(client));
|
|
46329
|
+
return {
|
|
46330
|
+
inbox: {
|
|
46331
|
+
check: () => requestClientAsApiResponse2(daemonApi.inbox.check())
|
|
46332
|
+
},
|
|
46333
|
+
wakeHints: {
|
|
46334
|
+
fetch: (query) => requestClientAsApiResponse2(daemonApi.wakeHints.fetch(query))
|
|
46335
|
+
},
|
|
46336
|
+
activity: {
|
|
46337
|
+
forward: (body) => requestClientAsApiResponse2(daemonApi.activity.forward(body))
|
|
46338
|
+
}
|
|
46339
|
+
};
|
|
46340
|
+
}
|
|
46341
|
+
init_esm_shims();
|
|
45680
46342
|
var AGENT_COMMS_PROTOCOL_VERSION = "agent-comms-core.v1";
|
|
45681
46343
|
var AGENT_PROOF_SCHEMA_VERSION = "agent-proof.v1";
|
|
45682
46344
|
var AgentCommsBridgeLockError = class extends Error {
|
|
@@ -46480,17 +47142,17 @@ function statusFailureClass(status) {
|
|
|
46480
47142
|
if (status === 404 || status === 410) return "no_session";
|
|
46481
47143
|
return "injection_failed";
|
|
46482
47144
|
}
|
|
46483
|
-
function buildRaftChannelWakeFailedEvent(input,
|
|
47145
|
+
function buildRaftChannelWakeFailedEvent(input, failure3) {
|
|
46484
47146
|
return validateExternalAgentWakeEventEnvelope({
|
|
46485
47147
|
...input,
|
|
46486
47148
|
schema: "slock-external-agent-wake-event.v1",
|
|
46487
47149
|
kind: "wake_attempt",
|
|
46488
47150
|
outcome: "failed",
|
|
46489
47151
|
failureMeta: {
|
|
46490
|
-
failureClass:
|
|
46491
|
-
...
|
|
47152
|
+
failureClass: failure3.failureClass,
|
|
47153
|
+
...failure3.retryAfterMs ? { retryAfterMs: failure3.retryAfterMs } : {}
|
|
46492
47154
|
},
|
|
46493
|
-
reason:
|
|
47155
|
+
reason: failure3.reason,
|
|
46494
47156
|
lifecycleState: "degraded_backoff",
|
|
46495
47157
|
authority: {
|
|
46496
47158
|
source: "wake_adapter",
|
|
@@ -46533,11 +47195,12 @@ var agentBridgeCommand = defineCommand(
|
|
|
46533
47195
|
const limit = parsePositiveInt(options.limit, 50, "limit");
|
|
46534
47196
|
const activityDrainLimit = parsePositiveInt(options.activityDrainLimit, 50, "activity-drain-limit");
|
|
46535
47197
|
const client = ctx.createApiClient(agentContext);
|
|
46536
|
-
const
|
|
46537
|
-
const
|
|
47198
|
+
const daemonApi = createDaemonApiSurfaceClient(client);
|
|
47199
|
+
const pollSource = createDaemonApiWakeHintSource(daemonApi);
|
|
47200
|
+
const streamSource = options.once ? null : createDaemonApiWakeHintStreamSource(client, ctx.env);
|
|
46538
47201
|
const wakeAdapter = createWakeAdapter(options, ctx.env);
|
|
46539
47202
|
const activitySource = createActivityDrainSource(options, ctx.env);
|
|
46540
|
-
const activitySink = activitySource ?
|
|
47203
|
+
const activitySink = activitySource ? createDaemonApiActivitySink(daemonApi) : void 0;
|
|
46541
47204
|
let bridgeLock;
|
|
46542
47205
|
try {
|
|
46543
47206
|
bridgeLock = acquireAgentCommsBridgeLock({
|
|
@@ -46696,14 +47359,13 @@ var agentBridgeCommand = defineCommand(
|
|
|
46696
47359
|
function registerAgentBridgeCommand(parent, runtimeOptions) {
|
|
46697
47360
|
registerCliCommand(parent, agentBridgeCommand, runtimeOptions);
|
|
46698
47361
|
}
|
|
46699
|
-
function
|
|
47362
|
+
function createDaemonApiWakeHintSource(client) {
|
|
46700
47363
|
return {
|
|
46701
47364
|
async fetchWakeHints(input) {
|
|
46702
|
-
const
|
|
46703
|
-
since:
|
|
46704
|
-
limit:
|
|
47365
|
+
const response = await client.wakeHints.fetch({
|
|
47366
|
+
since: input.since,
|
|
47367
|
+
limit: input.limit
|
|
46705
47368
|
});
|
|
46706
|
-
const response = await client.request("GET", `/internal/agent-api/wake-hints?${query.toString()}`);
|
|
46707
47369
|
if (!response.ok) {
|
|
46708
47370
|
throw new CliError({
|
|
46709
47371
|
code: response.status >= 500 ? "SERVER_5XX" : "BRIDGE_WAKE_HINTS_FAILED",
|
|
@@ -46718,8 +47380,8 @@ function createAgentApiWakeHintSource(client) {
|
|
|
46718
47380
|
}
|
|
46719
47381
|
};
|
|
46720
47382
|
}
|
|
46721
|
-
function
|
|
46722
|
-
if (!client.
|
|
47383
|
+
function createDaemonApiWakeHintStreamSource(client, env = process.env) {
|
|
47384
|
+
if (!client.streamWakeHints) return null;
|
|
46723
47385
|
let reader = null;
|
|
46724
47386
|
let bufferedText = "";
|
|
46725
47387
|
let pendingEvent = {};
|
|
@@ -46734,7 +47396,7 @@ function createAgentApiWakeHintStreamSource(client, env = process.env) {
|
|
|
46734
47396
|
async function ensureReader(since) {
|
|
46735
47397
|
if (reader) return reader;
|
|
46736
47398
|
const query = new URLSearchParams({ since: String(since) });
|
|
46737
|
-
const response = await client.
|
|
47399
|
+
const response = await client.streamWakeHints(query);
|
|
46738
47400
|
if (!response.ok) {
|
|
46739
47401
|
throw new CliError({
|
|
46740
47402
|
code: response.status === 404 || response.status === 405 || response.status === 501 ? "BRIDGE_WAKE_STREAM_UNAVAILABLE" : response.status >= 500 ? "SERVER_5XX" : "BRIDGE_WAKE_STREAM_FAILED",
|
|
@@ -46919,10 +47581,10 @@ function createActivityDrainSource(options, env = process.env) {
|
|
|
46919
47581
|
}
|
|
46920
47582
|
};
|
|
46921
47583
|
}
|
|
46922
|
-
function
|
|
47584
|
+
function createDaemonApiActivitySink(client) {
|
|
46923
47585
|
return {
|
|
46924
47586
|
async forwardActivity(input) {
|
|
46925
|
-
const response = await client.
|
|
47587
|
+
const response = await client.activity.forward(input);
|
|
46926
47588
|
if (!response.ok) {
|
|
46927
47589
|
throw new CliError({
|
|
46928
47590
|
code: response.status >= 500 ? "SERVER_5XX" : "BRIDGE_ACTIVITY_FORWARD_FAILED",
|
|
@@ -47054,6 +47716,9 @@ function formatRuntimeContext(ctx) {
|
|
|
47054
47716
|
"Authoritative context for this agent process. Do not infer computer identity from hostname or cwd when this section is present."
|
|
47055
47717
|
];
|
|
47056
47718
|
if (ctx.agentId) lines.push(`- Agent ID: ${ctx.agentId}`);
|
|
47719
|
+
if (ctx.runtime) lines.push(`- Runtime: ${ctx.runtime}`);
|
|
47720
|
+
if (ctx.model) lines.push(`- Model: ${ctx.model}`);
|
|
47721
|
+
if (ctx.reasoningEffort) lines.push(`- Reasoning: ${ctx.reasoningEffort}`);
|
|
47057
47722
|
if (ctx.serverId) lines.push(`- Server ID: ${ctx.serverId}`);
|
|
47058
47723
|
if (ctx.machineName || ctx.machineId) {
|
|
47059
47724
|
const label = ctx.machineName && ctx.machineId ? `${ctx.machineName} (${ctx.machineId})` : ctx.machineName || ctx.machineId;
|
|
@@ -47067,14 +47732,26 @@ function formatRuntimeContext(ctx) {
|
|
|
47067
47732
|
|
|
47068
47733
|
` : "";
|
|
47069
47734
|
}
|
|
47735
|
+
function roleLabel(role) {
|
|
47736
|
+
return role && role !== "member" ? ` (${role})` : "";
|
|
47737
|
+
}
|
|
47738
|
+
function formatCurrentAgent(data) {
|
|
47739
|
+
if (!data.serverRole) return "";
|
|
47740
|
+
const lines = ["### Current Agent"];
|
|
47741
|
+
lines.push(`- Role: ${data.serverRole}`);
|
|
47742
|
+
return `${lines.join("\n")}
|
|
47743
|
+
|
|
47744
|
+
`;
|
|
47745
|
+
}
|
|
47070
47746
|
function formatServerInfo(data) {
|
|
47071
47747
|
let text = "## Server\n\n";
|
|
47072
47748
|
const channels = data.channels ?? [];
|
|
47073
47749
|
const agents = data.agents ?? [];
|
|
47074
47750
|
const humans = data.humans ?? [];
|
|
47075
47751
|
text += formatRuntimeContext(data.runtimeContext);
|
|
47752
|
+
text += formatCurrentAgent(data);
|
|
47076
47753
|
text += "### Channels\n";
|
|
47077
|
-
text +=
|
|
47754
|
+
text += "Visible public channels may appear even when `joined=false`. Private channels are shown only when you are a member; do not disclose private-channel names, membership, or content outside that channel. Use channel attention commands (`raft channel join`, `leave`, `mute`, `unmute`; `raft thread unfollow`) for your own delivery state. Admin agents can manage regular channels (`raft channel create`, `update`, `add-member`, `remove-member`) and server profile (`raft server update`). Run any subcommand with `--help` for syntax.\n";
|
|
47078
47755
|
if (channels.length > 0) {
|
|
47079
47756
|
for (const t of channels) {
|
|
47080
47757
|
const visibility = t.type === "private" ? "private" : "public";
|
|
@@ -47088,10 +47765,12 @@ function formatServerInfo(data) {
|
|
|
47088
47765
|
}
|
|
47089
47766
|
text += "\n### Agents\n";
|
|
47090
47767
|
text += "Other AI agents in this server.\n";
|
|
47768
|
+
text += "Role labels show server-level owner/admin authority; no role label means ordinary member.\n";
|
|
47091
47769
|
if (agents.length > 0) {
|
|
47092
47770
|
for (const a of agents) {
|
|
47093
|
-
|
|
47094
|
-
|
|
47771
|
+
const role = roleLabel(a.role);
|
|
47772
|
+
text += a.description ? ` - @${a.name} (${a.status})${role} \u2014 ${a.description}
|
|
47773
|
+
` : ` - @${a.name} (${a.status})${role}
|
|
47095
47774
|
`;
|
|
47096
47775
|
}
|
|
47097
47776
|
} else {
|
|
@@ -47100,10 +47779,12 @@ function formatServerInfo(data) {
|
|
|
47100
47779
|
text += "\n### Humans\n";
|
|
47101
47780
|
text += `To start a new DM: raft message send --target "dm:@name" <<'SLOCKMSG' followed by the message body and SLOCKMSG. To reply in an existing DM: reuse the target from received messages.
|
|
47102
47781
|
`;
|
|
47782
|
+
text += "Role labels show server-level owner/admin authority; no role label means ordinary member.\n";
|
|
47103
47783
|
if (humans.length > 0) {
|
|
47104
47784
|
for (const u of humans) {
|
|
47105
|
-
|
|
47106
|
-
|
|
47785
|
+
const role = roleLabel(u.role);
|
|
47786
|
+
text += u.description ? ` - @${u.name}${role} \u2014 ${u.description}
|
|
47787
|
+
` : ` - @${u.name}${role}
|
|
47107
47788
|
`;
|
|
47108
47789
|
}
|
|
47109
47790
|
} else {
|
|
@@ -47121,10 +47802,12 @@ function formatChannelMembers(data) {
|
|
|
47121
47802
|
`;
|
|
47122
47803
|
text += "Members means join/post authority for this surface.\n\n";
|
|
47123
47804
|
text += "### Agents\n";
|
|
47805
|
+
text += "Role labels show server-level owner/admin authority; no role label means ordinary member.\n";
|
|
47124
47806
|
if (agents.length > 0) {
|
|
47125
47807
|
for (const a of agents) {
|
|
47126
|
-
|
|
47127
|
-
|
|
47808
|
+
const role = roleLabel(a.role);
|
|
47809
|
+
text += a.description ? ` - @${a.name} (${a.status})${role} \u2014 ${a.description}
|
|
47810
|
+
` : ` - @${a.name} (${a.status})${role}
|
|
47128
47811
|
`;
|
|
47129
47812
|
}
|
|
47130
47813
|
} else {
|
|
@@ -47134,7 +47817,7 @@ function formatChannelMembers(data) {
|
|
|
47134
47817
|
text += "Role labels show server-level owner/admin authority; no role label means ordinary member.\n";
|
|
47135
47818
|
if (humans.length > 0) {
|
|
47136
47819
|
for (const u of humans) {
|
|
47137
|
-
const role =
|
|
47820
|
+
const role = roleLabel(u.role);
|
|
47138
47821
|
text += u.description ? ` - @${u.name}${role} \u2014 ${u.description}
|
|
47139
47822
|
` : ` - @${u.name}${role}
|
|
47140
47823
|
`;
|
|
@@ -47175,6 +47858,65 @@ function registerChannelMembersCommand(parent, runtimeOptions) {
|
|
|
47175
47858
|
registerCliCommand(parent, channelMembersCommand, runtimeOptions);
|
|
47176
47859
|
}
|
|
47177
47860
|
init_esm_shims();
|
|
47861
|
+
function normalizeChannelName(raw) {
|
|
47862
|
+
return (raw ?? "").trim().replace(/^#/, "");
|
|
47863
|
+
}
|
|
47864
|
+
function formatCreateChannelResult(channel) {
|
|
47865
|
+
const target = `#${channel.name}`;
|
|
47866
|
+
const visibility = channel.type === "private" ? "private" : "public";
|
|
47867
|
+
return `Created ${target} (${visibility}). You are joined and can send messages there.`;
|
|
47868
|
+
}
|
|
47869
|
+
var channelCreateCommand = defineCommand(
|
|
47870
|
+
{
|
|
47871
|
+
name: "create",
|
|
47872
|
+
description: "Create a public or private channel when this agent has server admin authority",
|
|
47873
|
+
options: [
|
|
47874
|
+
{
|
|
47875
|
+
flags: "--name <name>",
|
|
47876
|
+
description: "Channel name, with or without a leading '#'"
|
|
47877
|
+
},
|
|
47878
|
+
{
|
|
47879
|
+
flags: "--description <description>",
|
|
47880
|
+
description: "Optional channel description"
|
|
47881
|
+
},
|
|
47882
|
+
{
|
|
47883
|
+
flags: "--private",
|
|
47884
|
+
description: "Create a private channel instead of a public channel"
|
|
47885
|
+
}
|
|
47886
|
+
]
|
|
47887
|
+
},
|
|
47888
|
+
async (ctx, opts) => {
|
|
47889
|
+
const name = normalizeChannelName(opts.name);
|
|
47890
|
+
if (!name) {
|
|
47891
|
+
throw new CliError({
|
|
47892
|
+
code: "INVALID_ARG",
|
|
47893
|
+
message: "--name is required"
|
|
47894
|
+
});
|
|
47895
|
+
}
|
|
47896
|
+
const agentContext = ctx.loadAgentContext();
|
|
47897
|
+
const client = ctx.createApiClient(agentContext);
|
|
47898
|
+
const res = await client.request(
|
|
47899
|
+
"POST",
|
|
47900
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/channels`,
|
|
47901
|
+
{
|
|
47902
|
+
name,
|
|
47903
|
+
description: opts.description,
|
|
47904
|
+
visibility: opts.private ? "private" : "public"
|
|
47905
|
+
}
|
|
47906
|
+
);
|
|
47907
|
+
if (!res.ok || !res.data) {
|
|
47908
|
+
throw new CliError({
|
|
47909
|
+
code: res.status >= 500 ? "SERVER_5XX" : "CREATE_FAILED",
|
|
47910
|
+
message: res.error ?? `HTTP ${res.status}`
|
|
47911
|
+
});
|
|
47912
|
+
}
|
|
47913
|
+
writeText(ctx.io, formatCreateChannelResult(res.data) + "\n");
|
|
47914
|
+
}
|
|
47915
|
+
);
|
|
47916
|
+
function registerChannelCreateCommand(parent, runtimeOptions) {
|
|
47917
|
+
registerCliCommand(parent, channelCreateCommand, runtimeOptions);
|
|
47918
|
+
}
|
|
47919
|
+
init_esm_shims();
|
|
47178
47920
|
init_esm_shims();
|
|
47179
47921
|
function parseRegularChannelTarget(target) {
|
|
47180
47922
|
if (!target.startsWith("#")) return null;
|
|
@@ -47210,7 +47952,8 @@ var channelLeaveCommand = defineCommand(
|
|
|
47210
47952
|
}
|
|
47211
47953
|
const agentContext = ctx.loadAgentContext();
|
|
47212
47954
|
const client = ctx.createApiClient(agentContext);
|
|
47213
|
-
const
|
|
47955
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
47956
|
+
const infoRes = await agentApi.server.info();
|
|
47214
47957
|
if (!infoRes.ok) {
|
|
47215
47958
|
throw new CliError({
|
|
47216
47959
|
code: infoRes.status >= 500 ? "SERVER_5XX" : "INFO_FAILED",
|
|
@@ -47228,7 +47971,7 @@ var channelLeaveCommand = defineCommand(
|
|
|
47228
47971
|
writeText(ctx.io, formatAlreadyNotJoined(target) + "\n");
|
|
47229
47972
|
return;
|
|
47230
47973
|
}
|
|
47231
|
-
const leaveRes = await
|
|
47974
|
+
const leaveRes = await agentApi.channels.leave({
|
|
47232
47975
|
channelId: channel.id
|
|
47233
47976
|
});
|
|
47234
47977
|
if (!leaveRes.ok) {
|
|
@@ -47243,6 +47986,271 @@ var channelLeaveCommand = defineCommand(
|
|
|
47243
47986
|
function registerChannelLeaveCommand(parent, runtimeOptions) {
|
|
47244
47987
|
registerCliCommand(parent, channelLeaveCommand, runtimeOptions);
|
|
47245
47988
|
}
|
|
47989
|
+
function normalizeChannelName2(raw) {
|
|
47990
|
+
return (raw ?? "").trim().replace(/^#/, "");
|
|
47991
|
+
}
|
|
47992
|
+
function formatUpdateChannelResult(channel) {
|
|
47993
|
+
const visibility = channel.type === "private" ? "private" : "public";
|
|
47994
|
+
return `Updated #${channel.name} (${visibility}).`;
|
|
47995
|
+
}
|
|
47996
|
+
var channelUpdateCommand = defineCommand(
|
|
47997
|
+
{
|
|
47998
|
+
name: "update",
|
|
47999
|
+
description: "Edit a regular channel when this agent has server admin authority",
|
|
48000
|
+
options: [
|
|
48001
|
+
{
|
|
48002
|
+
flags: "--target <target>",
|
|
48003
|
+
description: "Regular channel to edit, e.g. '#engineering'"
|
|
48004
|
+
},
|
|
48005
|
+
{
|
|
48006
|
+
flags: "--name <name>",
|
|
48007
|
+
description: "New channel name, with or without a leading '#'"
|
|
48008
|
+
},
|
|
48009
|
+
{
|
|
48010
|
+
flags: "--description <description>",
|
|
48011
|
+
description: "New channel description"
|
|
48012
|
+
},
|
|
48013
|
+
{
|
|
48014
|
+
flags: "--public",
|
|
48015
|
+
description: "Make the channel public"
|
|
48016
|
+
},
|
|
48017
|
+
{
|
|
48018
|
+
flags: "--private",
|
|
48019
|
+
description: "Make the channel private"
|
|
48020
|
+
}
|
|
48021
|
+
]
|
|
48022
|
+
},
|
|
48023
|
+
async (ctx, opts) => {
|
|
48024
|
+
const target = opts.target ?? "";
|
|
48025
|
+
const channelName = parseRegularChannelTarget(target);
|
|
48026
|
+
if (!channelName) {
|
|
48027
|
+
throw new CliError({
|
|
48028
|
+
code: "INVALID_TARGET",
|
|
48029
|
+
message: "Target must be a regular channel in the form '#channel-name'. DMs and thread targets are not supported."
|
|
48030
|
+
});
|
|
48031
|
+
}
|
|
48032
|
+
if (opts.public && opts.private) {
|
|
48033
|
+
throw new CliError({
|
|
48034
|
+
code: "INVALID_ARG",
|
|
48035
|
+
message: "Use either --public or --private, not both."
|
|
48036
|
+
});
|
|
48037
|
+
}
|
|
48038
|
+
const body = {};
|
|
48039
|
+
if (opts.name !== void 0) body.name = normalizeChannelName2(opts.name);
|
|
48040
|
+
if (opts.description !== void 0) body.description = opts.description;
|
|
48041
|
+
if (opts.public) body.visibility = "public";
|
|
48042
|
+
if (opts.private) body.visibility = "private";
|
|
48043
|
+
if (body.name === void 0 && body.description === void 0 && body.visibility === void 0) {
|
|
48044
|
+
throw new CliError({
|
|
48045
|
+
code: "INVALID_ARG",
|
|
48046
|
+
message: "Provide at least one of --name, --description, --public, or --private."
|
|
48047
|
+
});
|
|
48048
|
+
}
|
|
48049
|
+
const agentContext = ctx.loadAgentContext();
|
|
48050
|
+
const client = ctx.createApiClient(agentContext);
|
|
48051
|
+
const infoRes = await client.request(
|
|
48052
|
+
"GET",
|
|
48053
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/server`
|
|
48054
|
+
);
|
|
48055
|
+
if (!infoRes.ok) {
|
|
48056
|
+
throw new CliError({
|
|
48057
|
+
code: infoRes.status >= 500 ? "SERVER_5XX" : "INFO_FAILED",
|
|
48058
|
+
message: infoRes.error ?? `HTTP ${infoRes.status}`
|
|
48059
|
+
});
|
|
48060
|
+
}
|
|
48061
|
+
const channel = (infoRes.data?.channels ?? []).find((candidate) => candidate.name === channelName);
|
|
48062
|
+
if (!channel) {
|
|
48063
|
+
throw new CliError({
|
|
48064
|
+
code: "NOT_FOUND",
|
|
48065
|
+
message: `Channel not found: ${target}`
|
|
48066
|
+
});
|
|
48067
|
+
}
|
|
48068
|
+
const updateRes = await client.request(
|
|
48069
|
+
"PATCH",
|
|
48070
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/channels/${encodeURIComponent(channel.id)}`,
|
|
48071
|
+
body
|
|
48072
|
+
);
|
|
48073
|
+
if (!updateRes.ok || !updateRes.data) {
|
|
48074
|
+
throw new CliError({
|
|
48075
|
+
code: updateRes.status >= 500 ? "SERVER_5XX" : "UPDATE_FAILED",
|
|
48076
|
+
message: updateRes.error ?? `HTTP ${updateRes.status}`
|
|
48077
|
+
});
|
|
48078
|
+
}
|
|
48079
|
+
writeText(ctx.io, formatUpdateChannelResult(updateRes.data) + "\n");
|
|
48080
|
+
}
|
|
48081
|
+
);
|
|
48082
|
+
function registerChannelUpdateCommand(parent, runtimeOptions) {
|
|
48083
|
+
registerCliCommand(parent, channelUpdateCommand, runtimeOptions);
|
|
48084
|
+
}
|
|
48085
|
+
init_esm_shims();
|
|
48086
|
+
function normalizeHandle(raw) {
|
|
48087
|
+
return (raw ?? "").trim().replace(/^@/, "");
|
|
48088
|
+
}
|
|
48089
|
+
function formatAddMemberResult(target, memberType, memberName, alreadyMember) {
|
|
48090
|
+
const member = `@${memberName}`;
|
|
48091
|
+
if (alreadyMember) {
|
|
48092
|
+
return `${member} is already in ${target}.`;
|
|
48093
|
+
}
|
|
48094
|
+
return `Added ${member} to ${target} as ${memberType === "agent" ? "an agent" : "a user"}.`;
|
|
48095
|
+
}
|
|
48096
|
+
var channelAddMemberCommand = defineCommand(
|
|
48097
|
+
{
|
|
48098
|
+
name: "add-member",
|
|
48099
|
+
description: "Add a human or agent to a regular channel when this agent has server admin authority",
|
|
48100
|
+
options: [
|
|
48101
|
+
{
|
|
48102
|
+
flags: "--target <target>",
|
|
48103
|
+
description: "Regular channel to add a member to, e.g. '#engineering'"
|
|
48104
|
+
},
|
|
48105
|
+
{
|
|
48106
|
+
flags: "--user <handle>",
|
|
48107
|
+
description: "Human handle to add, e.g. '@alice'"
|
|
48108
|
+
},
|
|
48109
|
+
{
|
|
48110
|
+
flags: "--agent <handle>",
|
|
48111
|
+
description: "Agent handle to add, e.g. '@assistant'"
|
|
48112
|
+
}
|
|
48113
|
+
]
|
|
48114
|
+
},
|
|
48115
|
+
async (ctx, opts) => {
|
|
48116
|
+
const target = opts.target ?? "";
|
|
48117
|
+
const channelName = parseRegularChannelTarget(target);
|
|
48118
|
+
if (!channelName) {
|
|
48119
|
+
throw new CliError({
|
|
48120
|
+
code: "INVALID_TARGET",
|
|
48121
|
+
message: "Target must be a regular channel in the form '#channel-name'. DMs and thread targets are not supported."
|
|
48122
|
+
});
|
|
48123
|
+
}
|
|
48124
|
+
const user = normalizeHandle(opts.user);
|
|
48125
|
+
const agent = normalizeHandle(opts.agent);
|
|
48126
|
+
if ((user ? 1 : 0) + (agent ? 1 : 0) !== 1) {
|
|
48127
|
+
throw new CliError({
|
|
48128
|
+
code: "INVALID_ARG",
|
|
48129
|
+
message: "Provide exactly one of --user or --agent."
|
|
48130
|
+
});
|
|
48131
|
+
}
|
|
48132
|
+
const agentContext = ctx.loadAgentContext();
|
|
48133
|
+
const client = ctx.createApiClient(agentContext);
|
|
48134
|
+
const infoRes = await client.request(
|
|
48135
|
+
"GET",
|
|
48136
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/server`
|
|
48137
|
+
);
|
|
48138
|
+
if (!infoRes.ok) {
|
|
48139
|
+
throw new CliError({
|
|
48140
|
+
code: infoRes.status >= 500 ? "SERVER_5XX" : "INFO_FAILED",
|
|
48141
|
+
message: infoRes.error ?? `HTTP ${infoRes.status}`
|
|
48142
|
+
});
|
|
48143
|
+
}
|
|
48144
|
+
const channel = (infoRes.data?.channels ?? []).find((candidate) => candidate.name === channelName);
|
|
48145
|
+
if (!channel) {
|
|
48146
|
+
throw new CliError({
|
|
48147
|
+
code: "NOT_FOUND",
|
|
48148
|
+
message: `Channel not found: ${target}`
|
|
48149
|
+
});
|
|
48150
|
+
}
|
|
48151
|
+
const body = user ? { user } : { agent };
|
|
48152
|
+
const addRes = await client.request(
|
|
48153
|
+
"POST",
|
|
48154
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/channels/${encodeURIComponent(channel.id)}/members`,
|
|
48155
|
+
body
|
|
48156
|
+
);
|
|
48157
|
+
if (!addRes.ok) {
|
|
48158
|
+
throw new CliError({
|
|
48159
|
+
code: addRes.status >= 500 ? "SERVER_5XX" : "MEMBERS_FAILED",
|
|
48160
|
+
message: addRes.error ?? `HTTP ${addRes.status}`
|
|
48161
|
+
});
|
|
48162
|
+
}
|
|
48163
|
+
const memberName = addRes.data?.member?.name ?? (user || agent);
|
|
48164
|
+
const memberType = addRes.data?.member?.type === "agent" ? "agent" : "user";
|
|
48165
|
+
writeText(ctx.io, formatAddMemberResult(target, memberType, memberName, addRes.data?.alreadyMember === true) + "\n");
|
|
48166
|
+
}
|
|
48167
|
+
);
|
|
48168
|
+
function registerChannelAddMemberCommand(parent, runtimeOptions) {
|
|
48169
|
+
registerCliCommand(parent, channelAddMemberCommand, runtimeOptions);
|
|
48170
|
+
}
|
|
48171
|
+
init_esm_shims();
|
|
48172
|
+
function normalizeHandle2(raw) {
|
|
48173
|
+
return (raw ?? "").trim().replace(/^@/, "");
|
|
48174
|
+
}
|
|
48175
|
+
function formatRemoveMemberResult(target, memberName, wasMember) {
|
|
48176
|
+
const member = `@${memberName}`;
|
|
48177
|
+
return wasMember ? `Removed ${member} from ${target}.` : `${member} was not in ${target}.`;
|
|
48178
|
+
}
|
|
48179
|
+
var channelRemoveMemberCommand = defineCommand(
|
|
48180
|
+
{
|
|
48181
|
+
name: "remove-member",
|
|
48182
|
+
description: "Remove a human or agent from a regular channel when this agent has server admin authority",
|
|
48183
|
+
options: [
|
|
48184
|
+
{
|
|
48185
|
+
flags: "--target <target>",
|
|
48186
|
+
description: "Regular channel to remove a member from, e.g. '#engineering'"
|
|
48187
|
+
},
|
|
48188
|
+
{
|
|
48189
|
+
flags: "--user <handle>",
|
|
48190
|
+
description: "Human handle to remove, e.g. '@alice'"
|
|
48191
|
+
},
|
|
48192
|
+
{
|
|
48193
|
+
flags: "--agent <handle>",
|
|
48194
|
+
description: "Agent handle to remove, e.g. '@assistant'"
|
|
48195
|
+
}
|
|
48196
|
+
]
|
|
48197
|
+
},
|
|
48198
|
+
async (ctx, opts) => {
|
|
48199
|
+
const target = opts.target ?? "";
|
|
48200
|
+
const channelName = parseRegularChannelTarget(target);
|
|
48201
|
+
if (!channelName) {
|
|
48202
|
+
throw new CliError({
|
|
48203
|
+
code: "INVALID_TARGET",
|
|
48204
|
+
message: "Target must be a regular channel in the form '#channel-name'. DMs and thread targets are not supported."
|
|
48205
|
+
});
|
|
48206
|
+
}
|
|
48207
|
+
const user = normalizeHandle2(opts.user);
|
|
48208
|
+
const agent = normalizeHandle2(opts.agent);
|
|
48209
|
+
if ((user ? 1 : 0) + (agent ? 1 : 0) !== 1) {
|
|
48210
|
+
throw new CliError({
|
|
48211
|
+
code: "INVALID_ARG",
|
|
48212
|
+
message: "Provide exactly one of --user or --agent."
|
|
48213
|
+
});
|
|
48214
|
+
}
|
|
48215
|
+
const agentContext = ctx.loadAgentContext();
|
|
48216
|
+
const client = ctx.createApiClient(agentContext);
|
|
48217
|
+
const infoRes = await client.request(
|
|
48218
|
+
"GET",
|
|
48219
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/server`
|
|
48220
|
+
);
|
|
48221
|
+
if (!infoRes.ok) {
|
|
48222
|
+
throw new CliError({
|
|
48223
|
+
code: infoRes.status >= 500 ? "SERVER_5XX" : "INFO_FAILED",
|
|
48224
|
+
message: infoRes.error ?? `HTTP ${infoRes.status}`
|
|
48225
|
+
});
|
|
48226
|
+
}
|
|
48227
|
+
const channel = (infoRes.data?.channels ?? []).find((candidate) => candidate.name === channelName);
|
|
48228
|
+
if (!channel) {
|
|
48229
|
+
throw new CliError({
|
|
48230
|
+
code: "NOT_FOUND",
|
|
48231
|
+
message: `Channel not found: ${target}`
|
|
48232
|
+
});
|
|
48233
|
+
}
|
|
48234
|
+
const body = user ? { user } : { agent };
|
|
48235
|
+
const removeRes = await client.request(
|
|
48236
|
+
"DELETE",
|
|
48237
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/channels/${encodeURIComponent(channel.id)}/members`,
|
|
48238
|
+
body
|
|
48239
|
+
);
|
|
48240
|
+
if (!removeRes.ok) {
|
|
48241
|
+
throw new CliError({
|
|
48242
|
+
code: removeRes.status >= 500 ? "SERVER_5XX" : "MEMBERS_FAILED",
|
|
48243
|
+
message: removeRes.error ?? `HTTP ${removeRes.status}`
|
|
48244
|
+
});
|
|
48245
|
+
}
|
|
48246
|
+
const memberName = removeRes.data?.member?.name ?? (user || agent);
|
|
48247
|
+
writeText(ctx.io, formatRemoveMemberResult(target, memberName, removeRes.data?.wasMember === true) + "\n");
|
|
48248
|
+
}
|
|
48249
|
+
);
|
|
48250
|
+
function registerChannelRemoveMemberCommand(parent, runtimeOptions) {
|
|
48251
|
+
registerCliCommand(parent, channelRemoveMemberCommand, runtimeOptions);
|
|
48252
|
+
}
|
|
48253
|
+
init_esm_shims();
|
|
47246
48254
|
function formatJoinChannelResult(target) {
|
|
47247
48255
|
return `Joined ${target}. You can now send messages there and receive ordinary channel delivery.`;
|
|
47248
48256
|
}
|
|
@@ -47271,7 +48279,8 @@ var channelJoinCommand = defineCommand(
|
|
|
47271
48279
|
}
|
|
47272
48280
|
const agentContext = ctx.loadAgentContext();
|
|
47273
48281
|
const client = ctx.createApiClient(agentContext);
|
|
47274
|
-
const
|
|
48282
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
48283
|
+
const infoRes = await agentApi.server.info();
|
|
47275
48284
|
if (!infoRes.ok) {
|
|
47276
48285
|
throw new CliError({
|
|
47277
48286
|
code: infoRes.status >= 500 ? "SERVER_5XX" : "INFO_FAILED",
|
|
@@ -47289,7 +48298,7 @@ var channelJoinCommand = defineCommand(
|
|
|
47289
48298
|
writeText(ctx.io, formatAlreadyJoined(target) + "\n");
|
|
47290
48299
|
return;
|
|
47291
48300
|
}
|
|
47292
|
-
const joinRes = await
|
|
48301
|
+
const joinRes = await agentApi.channels.join({
|
|
47293
48302
|
channelId: channel.id
|
|
47294
48303
|
});
|
|
47295
48304
|
if (!joinRes.ok) {
|
|
@@ -47345,7 +48354,8 @@ function makeChannelMuteCommand(action) {
|
|
|
47345
48354
|
}
|
|
47346
48355
|
const agentContext = ctx.loadAgentContext();
|
|
47347
48356
|
const client = ctx.createApiClient(agentContext);
|
|
47348
|
-
const
|
|
48357
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
48358
|
+
const infoRes = await agentApi.server.info();
|
|
47349
48359
|
if (!infoRes.ok) {
|
|
47350
48360
|
throw new CliError({
|
|
47351
48361
|
code: infoRes.status >= 500 ? "SERVER_5XX" : "INFO_FAILED",
|
|
@@ -47359,10 +48369,7 @@ function makeChannelMuteCommand(action) {
|
|
|
47359
48369
|
message: `Channel not found: ${target}`
|
|
47360
48370
|
});
|
|
47361
48371
|
}
|
|
47362
|
-
const res = await
|
|
47363
|
-
"POST",
|
|
47364
|
-
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/channels/${encodeURIComponent(channel.id)}/${action}`
|
|
47365
|
-
);
|
|
48372
|
+
const res = action === "mute" ? await agentApi.channels.mute({ channelId: channel.id }) : await agentApi.channels.unmute({ channelId: channel.id });
|
|
47366
48373
|
if (!res.ok) {
|
|
47367
48374
|
throw new CliError({
|
|
47368
48375
|
code: res.status >= 500 ? "SERVER_5XX" : action === "mute" ? "MUTE_FAILED" : "UNMUTE_FAILED",
|
|
@@ -47391,7 +48398,7 @@ var serverInfoCommand = defineCommand(
|
|
|
47391
48398
|
async (ctx) => {
|
|
47392
48399
|
const agentContext = ctx.loadAgentContext();
|
|
47393
48400
|
const client = ctx.createApiClient(agentContext);
|
|
47394
|
-
const res = await
|
|
48401
|
+
const res = await createAgentApiSurfaceClient(client).server.info();
|
|
47395
48402
|
if (!res.ok) {
|
|
47396
48403
|
const code = res.status >= 500 ? "SERVER_5XX" : "INFO_FAILED";
|
|
47397
48404
|
throw new CliError({
|
|
@@ -47413,14 +48420,327 @@ function registerServerInfoCommand(parent, runtimeOptions) {
|
|
|
47413
48420
|
registerCliCommand(parent, serverInfoCommand, runtimeOptions);
|
|
47414
48421
|
}
|
|
47415
48422
|
init_esm_shims();
|
|
47416
|
-
|
|
47417
|
-
|
|
47418
|
-
|
|
47419
|
-
if (
|
|
47420
|
-
|
|
47421
|
-
|
|
47422
|
-
return
|
|
48423
|
+
init_esm_shims();
|
|
48424
|
+
init_esm_shims();
|
|
48425
|
+
function formatCreatedAgents(createdAgents) {
|
|
48426
|
+
if (createdAgents.length === 0) {
|
|
48427
|
+
return ["- Created Agents: none"];
|
|
48428
|
+
}
|
|
48429
|
+
return [
|
|
48430
|
+
`- Created Agents (${createdAgents.length}):`,
|
|
48431
|
+
...createdAgents.map((createdAgent) => ` - @${createdAgent.name} (${getRuntimeDisplayName(createdAgent.runtime)}, ${createdAgent.status})`)
|
|
48432
|
+
];
|
|
48433
|
+
}
|
|
48434
|
+
function formatHumanProfile(profile) {
|
|
48435
|
+
const lines = [
|
|
48436
|
+
"## Profile",
|
|
48437
|
+
"",
|
|
48438
|
+
"- Type: human",
|
|
48439
|
+
`- Handle: @${profile.name}`,
|
|
48440
|
+
`- Display Name: ${profile.displayName ?? "(none)"}`,
|
|
48441
|
+
`- Description: ${profile.description ?? "(none)"}`,
|
|
48442
|
+
`- Membership: ${profile.membershipStatus}`
|
|
48443
|
+
];
|
|
48444
|
+
if (profile.role) lines.push(`- Role: ${profile.role}`);
|
|
48445
|
+
if (profile.joinedAt) lines.push(`- Joined: ${profile.joinedAt}`);
|
|
48446
|
+
if (profile.email) lines.push(`- Email: ${profile.email}`);
|
|
48447
|
+
return [...lines, ...formatCreatedAgents(profile.createdAgents)].join("\n");
|
|
48448
|
+
}
|
|
48449
|
+
function formatCreator(profile) {
|
|
48450
|
+
if (!profile.creator) return null;
|
|
48451
|
+
return profile.creator.displayName ? `${profile.creator.displayName} (@${profile.creator.name})` : `@${profile.creator.name}`;
|
|
48452
|
+
}
|
|
48453
|
+
function formatAgentProfile(profile) {
|
|
48454
|
+
const lines = [
|
|
48455
|
+
"## Profile",
|
|
48456
|
+
"",
|
|
48457
|
+
"- Type: agent",
|
|
48458
|
+
`- Handle: @${profile.name}`,
|
|
48459
|
+
`- Display Name: ${profile.displayName ?? "(none)"}`,
|
|
48460
|
+
`- Description: ${profile.description ?? "(none)"}`,
|
|
48461
|
+
`- Status: ${profile.status}`,
|
|
48462
|
+
`- Role: ${profile.serverRole}`,
|
|
48463
|
+
`- Runtime: ${getRuntimeDisplayName(profile.runtime)}`,
|
|
48464
|
+
`- Model: ${profile.model}`,
|
|
48465
|
+
`- Reasoning: ${profile.reasoningEffort ?? "medium"}`
|
|
48466
|
+
];
|
|
48467
|
+
if (profile.executionMode) lines.push(`- Execution: ${profile.executionMode}`);
|
|
48468
|
+
if (profile.computerName || profile.computerId) {
|
|
48469
|
+
const label = profile.computerName && profile.computerId ? `${profile.computerName} (${profile.computerId})` : profile.computerName ?? profile.computerId;
|
|
48470
|
+
lines.push(`- Computer: ${label}`);
|
|
48471
|
+
}
|
|
48472
|
+
if (profile.computerHostname) lines.push(`- Hostname: ${profile.computerHostname}`);
|
|
48473
|
+
if (profile.daemonVersion) lines.push(`- Daemon: v${profile.daemonVersion}`);
|
|
48474
|
+
lines.push(`- Created: ${profile.createdAt}`);
|
|
48475
|
+
if (profile.deletedAt) lines.push(`- Deleted At: ${profile.deletedAt}`);
|
|
48476
|
+
const creator = formatCreator(profile);
|
|
48477
|
+
if (creator) lines.push(`- Creator: ${creator}`);
|
|
48478
|
+
return [...lines, ...formatCreatedAgents(profile.createdAgents)].join("\n");
|
|
48479
|
+
}
|
|
48480
|
+
function formatProfile(profile) {
|
|
48481
|
+
return profile.kind === "human" ? formatHumanProfile(profile) : formatAgentProfile(profile);
|
|
48482
|
+
}
|
|
48483
|
+
var MAX_PROFILE_AVATAR_BYTES = 2 * 1024 * 1024;
|
|
48484
|
+
var PROFILE_AVATAR_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
48485
|
+
"image/jpeg",
|
|
48486
|
+
"image/png",
|
|
48487
|
+
"image/gif",
|
|
48488
|
+
"image/webp"
|
|
48489
|
+
]);
|
|
48490
|
+
var FILENAME_MIME_MAP = {
|
|
48491
|
+
".jpg": "image/jpeg",
|
|
48492
|
+
".jpeg": "image/jpeg",
|
|
48493
|
+
".png": "image/png",
|
|
48494
|
+
".gif": "image/gif",
|
|
48495
|
+
".webp": "image/webp"
|
|
48496
|
+
};
|
|
48497
|
+
var MAX_PROFILE_DESCRIPTION_LENGTH = 3e3;
|
|
48498
|
+
var MAX_PROFILE_DISPLAY_NAME_LENGTH = 80;
|
|
48499
|
+
function inferImageMimeType(filename, buffer) {
|
|
48500
|
+
const lowerFilename = filename.toLowerCase();
|
|
48501
|
+
if (buffer.length >= 8 && buffer.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
|
|
48502
|
+
return "image/png";
|
|
48503
|
+
}
|
|
48504
|
+
if (buffer.length >= 3 && buffer.subarray(0, 3).equals(Buffer.from([255, 216, 255]))) {
|
|
48505
|
+
return "image/jpeg";
|
|
48506
|
+
}
|
|
48507
|
+
if (buffer.length >= 6) {
|
|
48508
|
+
const header = buffer.subarray(0, 6).toString("ascii");
|
|
48509
|
+
if (header === "GIF87a" || header === "GIF89a") return "image/gif";
|
|
48510
|
+
}
|
|
48511
|
+
if (buffer.length >= 12 && buffer.subarray(0, 4).toString("ascii") === "RIFF" && buffer.subarray(8, 12).toString("ascii") === "WEBP") {
|
|
48512
|
+
return "image/webp";
|
|
48513
|
+
}
|
|
48514
|
+
const dot = lowerFilename.lastIndexOf(".");
|
|
48515
|
+
return dot >= 0 ? FILENAME_MIME_MAP[lowerFilename.slice(dot)] ?? null : null;
|
|
48516
|
+
}
|
|
48517
|
+
function readAvatarFile(avatarFile) {
|
|
48518
|
+
if (!existsSync(avatarFile)) {
|
|
48519
|
+
throw cliError("PROFILE_FILE_NOT_FOUND", `Avatar file does not exist: ${avatarFile}`);
|
|
48520
|
+
}
|
|
48521
|
+
const stat2 = statSync(avatarFile);
|
|
48522
|
+
if (!stat2.isFile()) {
|
|
48523
|
+
throw cliError("PROFILE_FILE_NOT_FOUND", `Avatar file is not a regular file: ${avatarFile}`);
|
|
48524
|
+
}
|
|
48525
|
+
if (stat2.size > MAX_PROFILE_AVATAR_BYTES) {
|
|
48526
|
+
throw cliError(
|
|
48527
|
+
"PROFILE_AVATAR_TOO_LARGE",
|
|
48528
|
+
`Avatar file is ${stat2.size} bytes; max size is ${MAX_PROFILE_AVATAR_BYTES} bytes`
|
|
48529
|
+
);
|
|
48530
|
+
}
|
|
48531
|
+
const buffer = readFileSync2(avatarFile);
|
|
48532
|
+
const filename = basename(avatarFile);
|
|
48533
|
+
const mimeType = inferImageMimeType(filename, buffer);
|
|
48534
|
+
if (!mimeType || !PROFILE_AVATAR_MIME_TYPES.has(mimeType)) {
|
|
48535
|
+
throw cliError(
|
|
48536
|
+
"PROFILE_AVATAR_BAD_FORMAT",
|
|
48537
|
+
"Avatar must be a JPEG, PNG, GIF, or WebP image"
|
|
48538
|
+
);
|
|
48539
|
+
}
|
|
48540
|
+
return { filename, buffer, mimeType };
|
|
48541
|
+
}
|
|
48542
|
+
function normalizeAvatarUrl(avatarUrl) {
|
|
48543
|
+
const trimmed = avatarUrl.trim();
|
|
48544
|
+
if (trimmed.length === 0) {
|
|
48545
|
+
throw cliError("INVALID_ARG", "--avatar-url must not be empty");
|
|
48546
|
+
}
|
|
48547
|
+
if (!trimmed.startsWith("pixel:")) {
|
|
48548
|
+
throw cliError("INVALID_ARG", "--avatar-url currently supports only pixel avatar URLs; use --avatar-file for image uploads");
|
|
48549
|
+
}
|
|
48550
|
+
return trimmed;
|
|
48551
|
+
}
|
|
48552
|
+
var profileUpdateCommand = defineCommand(
|
|
48553
|
+
{
|
|
48554
|
+
name: "update",
|
|
48555
|
+
description: "Update your own profile",
|
|
48556
|
+
options: [
|
|
48557
|
+
{ flags: "--avatar-file <path>", description: "Path to a local image file to use as your avatar" },
|
|
48558
|
+
{ flags: "--avatar-url <value>", description: "Set a pixel avatar URL such as pixel:random:<seed>" },
|
|
48559
|
+
{ flags: "--display-name <name>", description: "Set your display name (non-empty)" },
|
|
48560
|
+
{ flags: "--description <text>", description: "Set your profile description (non-empty)" },
|
|
48561
|
+
{ flags: "--json", description: "Emit machine-readable JSON" }
|
|
48562
|
+
]
|
|
48563
|
+
},
|
|
48564
|
+
async (ctx, opts) => {
|
|
48565
|
+
const hasAvatar = opts.avatarFile !== void 0;
|
|
48566
|
+
const hasAvatarUrl = opts.avatarUrl !== void 0;
|
|
48567
|
+
const hasDisplayName = opts.displayName !== void 0;
|
|
48568
|
+
const hasDescription = opts.description !== void 0;
|
|
48569
|
+
if (!hasAvatar && !hasAvatarUrl && !hasDisplayName && !hasDescription) {
|
|
48570
|
+
throw cliError("INVALID_ARG", "Provide at least one of --avatar-file, --avatar-url, --display-name, or --description");
|
|
48571
|
+
}
|
|
48572
|
+
if (hasAvatar && hasAvatarUrl) {
|
|
48573
|
+
throw cliError("INVALID_ARG", "Use either --avatar-file or --avatar-url, not both");
|
|
48574
|
+
}
|
|
48575
|
+
let normalizedAvatarUrl;
|
|
48576
|
+
if (hasAvatarUrl) {
|
|
48577
|
+
normalizedAvatarUrl = normalizeAvatarUrl(opts.avatarUrl);
|
|
48578
|
+
}
|
|
48579
|
+
let trimmedDisplayName;
|
|
48580
|
+
if (hasDisplayName) {
|
|
48581
|
+
trimmedDisplayName = opts.displayName.trim();
|
|
48582
|
+
if (trimmedDisplayName.length === 0) {
|
|
48583
|
+
throw cliError("INVALID_ARG", "--display-name must not be empty");
|
|
48584
|
+
}
|
|
48585
|
+
if (trimmedDisplayName.length > MAX_PROFILE_DISPLAY_NAME_LENGTH) {
|
|
48586
|
+
throw cliError("INVALID_ARG", `--display-name must be at most ${MAX_PROFILE_DISPLAY_NAME_LENGTH} characters`);
|
|
48587
|
+
}
|
|
48588
|
+
}
|
|
48589
|
+
if (hasDescription) {
|
|
48590
|
+
if (opts.description.length === 0) {
|
|
48591
|
+
throw cliError("INVALID_ARG", "--description must not be empty");
|
|
48592
|
+
}
|
|
48593
|
+
if (opts.description.length > MAX_PROFILE_DESCRIPTION_LENGTH) {
|
|
48594
|
+
throw cliError("INVALID_ARG", `--description must be at most ${MAX_PROFILE_DESCRIPTION_LENGTH} characters`);
|
|
48595
|
+
}
|
|
48596
|
+
}
|
|
48597
|
+
const avatar = hasAvatar ? readAvatarFile(opts.avatarFile) : null;
|
|
48598
|
+
const agentContext = ctx.loadAgentContext();
|
|
48599
|
+
const client = ctx.createApiClient(agentContext);
|
|
48600
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
48601
|
+
let latestProfile = null;
|
|
48602
|
+
if (hasAvatarUrl || hasDisplayName || hasDescription) {
|
|
48603
|
+
const body = {};
|
|
48604
|
+
if (hasAvatarUrl) {
|
|
48605
|
+
body.avatarUrl = normalizedAvatarUrl;
|
|
48606
|
+
}
|
|
48607
|
+
if (hasDisplayName) {
|
|
48608
|
+
body.displayName = trimmedDisplayName;
|
|
48609
|
+
}
|
|
48610
|
+
if (hasDescription) {
|
|
48611
|
+
body.description = opts.description;
|
|
48612
|
+
}
|
|
48613
|
+
const res = await agentApi.profile.update(body);
|
|
48614
|
+
if (!res.ok || !res.data) {
|
|
48615
|
+
const code = res.errorCode ?? (res.status >= 500 ? "SERVER_5XX" : "PROFILE_UPDATE_FAILED");
|
|
48616
|
+
throw cliError(code, res.error ?? `HTTP ${res.status}`);
|
|
48617
|
+
}
|
|
48618
|
+
latestProfile = res.data;
|
|
48619
|
+
}
|
|
48620
|
+
if (hasAvatar) {
|
|
48621
|
+
const form = new FormData();
|
|
48622
|
+
const avatarBytes = Uint8Array.from(avatar.buffer);
|
|
48623
|
+
form.append("avatar", new Blob([avatarBytes], { type: avatar.mimeType }), avatar.filename);
|
|
48624
|
+
const res = await agentApi.profile.updateAvatar(form);
|
|
48625
|
+
if (!res.ok || !res.data) {
|
|
48626
|
+
const code = res.errorCode ?? (res.status >= 500 ? "SERVER_5XX" : "PROFILE_UPDATE_FAILED");
|
|
48627
|
+
throw cliError(code, res.error ?? `HTTP ${res.status}`);
|
|
48628
|
+
}
|
|
48629
|
+
latestProfile = res.data;
|
|
48630
|
+
}
|
|
48631
|
+
if (!latestProfile) {
|
|
48632
|
+
throw cliError("PROFILE_UPDATE_FAILED", "No profile returned from server");
|
|
48633
|
+
}
|
|
48634
|
+
if (opts.json) {
|
|
48635
|
+
writeJson(ctx.io, { ok: true, data: latestProfile });
|
|
48636
|
+
return;
|
|
48637
|
+
}
|
|
48638
|
+
writeText(ctx.io, `${formatProfile(latestProfile)}
|
|
48639
|
+
`);
|
|
48640
|
+
}
|
|
48641
|
+
);
|
|
48642
|
+
function registerProfileUpdateCommand(parent, runtimeOptions = {}) {
|
|
48643
|
+
registerCliCommand(parent, profileUpdateCommand, runtimeOptions);
|
|
47423
48644
|
}
|
|
48645
|
+
function formatServerUpdateResult(server) {
|
|
48646
|
+
return `Updated server ${server.name ?? server.id ?? "profile"}.`;
|
|
48647
|
+
}
|
|
48648
|
+
var serverUpdateCommand = defineCommand(
|
|
48649
|
+
{
|
|
48650
|
+
name: "update",
|
|
48651
|
+
description: "Update the current server profile when this agent has server admin authority",
|
|
48652
|
+
options: [
|
|
48653
|
+
{
|
|
48654
|
+
flags: "--name <name>",
|
|
48655
|
+
description: "Set the server name"
|
|
48656
|
+
},
|
|
48657
|
+
{
|
|
48658
|
+
flags: "--avatar-file <path>",
|
|
48659
|
+
description: "Path to a local image file to use as the server avatar"
|
|
48660
|
+
},
|
|
48661
|
+
{
|
|
48662
|
+
flags: "--json",
|
|
48663
|
+
description: "Emit machine-readable JSON"
|
|
48664
|
+
}
|
|
48665
|
+
]
|
|
48666
|
+
},
|
|
48667
|
+
async (ctx, opts) => {
|
|
48668
|
+
const hasName = opts.name !== void 0;
|
|
48669
|
+
const hasAvatar = opts.avatarFile !== void 0;
|
|
48670
|
+
if (!hasName && !hasAvatar) {
|
|
48671
|
+
throw new CliError({
|
|
48672
|
+
code: "INVALID_ARG",
|
|
48673
|
+
message: "Provide at least one of --name or --avatar-file."
|
|
48674
|
+
});
|
|
48675
|
+
}
|
|
48676
|
+
let trimmedName;
|
|
48677
|
+
if (hasName) {
|
|
48678
|
+
trimmedName = opts.name.trim();
|
|
48679
|
+
if (!trimmedName) {
|
|
48680
|
+
throw new CliError({
|
|
48681
|
+
code: "INVALID_ARG",
|
|
48682
|
+
message: "--name must not be empty"
|
|
48683
|
+
});
|
|
48684
|
+
}
|
|
48685
|
+
if (trimmedName.length > 100) {
|
|
48686
|
+
throw new CliError({
|
|
48687
|
+
code: "INVALID_ARG",
|
|
48688
|
+
message: "--name must be 100 characters or fewer"
|
|
48689
|
+
});
|
|
48690
|
+
}
|
|
48691
|
+
}
|
|
48692
|
+
const avatar = hasAvatar ? readAvatarFile(opts.avatarFile) : null;
|
|
48693
|
+
const agentContext = ctx.loadAgentContext();
|
|
48694
|
+
const client = ctx.createApiClient(agentContext);
|
|
48695
|
+
let latestServer = null;
|
|
48696
|
+
if (hasName) {
|
|
48697
|
+
const res = await client.request(
|
|
48698
|
+
"PATCH",
|
|
48699
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/server`,
|
|
48700
|
+
{ name: trimmedName }
|
|
48701
|
+
);
|
|
48702
|
+
if (!res.ok || !res.data) {
|
|
48703
|
+
throw new CliError({
|
|
48704
|
+
code: res.status >= 500 ? "SERVER_5XX" : "UPDATE_FAILED",
|
|
48705
|
+
message: res.error ?? `HTTP ${res.status}`
|
|
48706
|
+
});
|
|
48707
|
+
}
|
|
48708
|
+
latestServer = res.data;
|
|
48709
|
+
}
|
|
48710
|
+
if (hasAvatar) {
|
|
48711
|
+
const form = new FormData();
|
|
48712
|
+
const avatarBytes = Uint8Array.from(avatar.buffer);
|
|
48713
|
+
form.append("avatar", new Blob([avatarBytes], { type: avatar.mimeType }), avatar.filename);
|
|
48714
|
+
const res = await client.requestMultipart(
|
|
48715
|
+
"POST",
|
|
48716
|
+
`/internal/agent/${encodeURIComponent(agentContext.agentId)}/server/avatar`,
|
|
48717
|
+
form
|
|
48718
|
+
);
|
|
48719
|
+
if (!res.ok || !res.data) {
|
|
48720
|
+
throw new CliError({
|
|
48721
|
+
code: res.status >= 500 ? "SERVER_5XX" : "UPDATE_FAILED",
|
|
48722
|
+
message: res.error ?? `HTTP ${res.status}`
|
|
48723
|
+
});
|
|
48724
|
+
}
|
|
48725
|
+
latestServer = res.data;
|
|
48726
|
+
}
|
|
48727
|
+
if (!latestServer) {
|
|
48728
|
+
throw new CliError({
|
|
48729
|
+
code: "UPDATE_FAILED",
|
|
48730
|
+
message: "No server profile returned from server"
|
|
48731
|
+
});
|
|
48732
|
+
}
|
|
48733
|
+
if (opts.json) {
|
|
48734
|
+
writeJson(ctx.io, { ok: true, data: latestServer });
|
|
48735
|
+
return;
|
|
48736
|
+
}
|
|
48737
|
+
writeText(ctx.io, formatServerUpdateResult(latestServer) + "\n");
|
|
48738
|
+
}
|
|
48739
|
+
);
|
|
48740
|
+
function registerServerUpdateCommand(parent, runtimeOptions) {
|
|
48741
|
+
registerCliCommand(parent, serverUpdateCommand, runtimeOptions);
|
|
48742
|
+
}
|
|
48743
|
+
init_esm_shims();
|
|
47424
48744
|
function formatKnowledgeStdout(content) {
|
|
47425
48745
|
return content.endsWith("\n") ? content : `${content}
|
|
47426
48746
|
`;
|
|
@@ -47467,10 +48787,12 @@ var knowledgeGetCommand = defineCommand(
|
|
|
47467
48787
|
async (ctx, topic, opts) => {
|
|
47468
48788
|
const agentContext = ctx.loadAgentContext();
|
|
47469
48789
|
const client = ctx.createApiClient(agentContext);
|
|
47470
|
-
const res = await client.
|
|
47471
|
-
|
|
47472
|
-
|
|
47473
|
-
|
|
48790
|
+
const res = await createAgentApiSurfaceClient(client).knowledge.get({
|
|
48791
|
+
topic,
|
|
48792
|
+
reason: opts.reason,
|
|
48793
|
+
turn_id: opts.turnId,
|
|
48794
|
+
trace_id: opts.traceId
|
|
48795
|
+
});
|
|
47474
48796
|
if (!res.ok) {
|
|
47475
48797
|
throw new CliError({
|
|
47476
48798
|
code: toKnowledgeErrorCode(res.errorCode, res.status),
|
|
@@ -47508,7 +48830,7 @@ var inboxCheckCommand = defineCommand(
|
|
|
47508
48830
|
});
|
|
47509
48831
|
}
|
|
47510
48832
|
const client = ctx.createApiClient(agentContext);
|
|
47511
|
-
const response = await client.
|
|
48833
|
+
const response = await createDaemonApiSurfaceClient(client).inbox.check();
|
|
47512
48834
|
if (!response.ok) {
|
|
47513
48835
|
throw new CliError({
|
|
47514
48836
|
code: response.status >= 500 ? "SERVER_5XX" : "INBOX_CHECK_FAILED",
|
|
@@ -47857,6 +49179,7 @@ function renderSearchPreview(content, query) {
|
|
|
47857
49179
|
}
|
|
47858
49180
|
function formatSearchResults(query, data) {
|
|
47859
49181
|
if (!data.results || data.results.length === 0) return "No search results.";
|
|
49182
|
+
const trimmedQuery = query.trim();
|
|
47860
49183
|
const formatted = data.results.map((result2, index) => {
|
|
47861
49184
|
const ref = `msg:${result2.id}`;
|
|
47862
49185
|
const content = result2.content ?? result2.snippet ?? "";
|
|
@@ -47869,14 +49192,14 @@ function formatSearchResults(query, data) {
|
|
|
47869
49192
|
`Time: ${result2.createdAt ? toLocalTime(result2.createdAt) : "-"}`,
|
|
47870
49193
|
"",
|
|
47871
49194
|
"<preview>",
|
|
47872
|
-
renderSearchPreview(content,
|
|
49195
|
+
renderSearchPreview(content, trimmedQuery),
|
|
47873
49196
|
"</preview>",
|
|
47874
49197
|
"</result>"
|
|
47875
49198
|
].join("\n");
|
|
47876
49199
|
}).join("\n\n");
|
|
47877
49200
|
const resultLabel = data.results.length === 1 ? "result" : "results";
|
|
47878
49201
|
return [
|
|
47879
|
-
`Search results for: "${
|
|
49202
|
+
trimmedQuery ? `Search results for: "${trimmedQuery}" (${data.results.length} ${resultLabel})` : `Filtered message results (${data.results.length} ${resultLabel})`,
|
|
47880
49203
|
"",
|
|
47881
49204
|
formatted,
|
|
47882
49205
|
"",
|
|
@@ -48258,7 +49581,7 @@ var messageSendCommand = defineCommand(
|
|
|
48258
49581
|
if (outgoingAttachmentIds.length > 0) {
|
|
48259
49582
|
body.attachmentIds = outgoingAttachmentIds;
|
|
48260
49583
|
}
|
|
48261
|
-
const agentApi =
|
|
49584
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
48262
49585
|
const res = await agentApi.messages.send(body);
|
|
48263
49586
|
if (!res.ok) {
|
|
48264
49587
|
const code = res.status >= 500 ? "SERVER_5XX" : "SEND_FAILED";
|
|
@@ -48316,47 +49639,18 @@ function sortedMessages(messages) {
|
|
|
48316
49639
|
function result(messages, opts = {}) {
|
|
48317
49640
|
return {
|
|
48318
49641
|
messages: sortedMessages(messages),
|
|
48319
|
-
...opts.ackFailure ? { ackFailure: opts.ackFailure } : {},
|
|
48320
49642
|
...opts.drainedMore ? { drainedMore: true } : {},
|
|
48321
49643
|
...opts.hasMore ? { hasMore: true } : {},
|
|
48322
49644
|
...opts.drainComplete ? { drainComplete: true } : {}
|
|
48323
49645
|
};
|
|
48324
49646
|
}
|
|
48325
|
-
function hasMoreField(data) {
|
|
48326
|
-
if (!data) return false;
|
|
48327
|
-
return Object.prototype.hasOwnProperty.call(data, "has_more") || Object.prototype.hasOwnProperty.call(data, "hasMore");
|
|
48328
|
-
}
|
|
48329
49647
|
async function drainInbox(ctx, opts, client = new ApiClient(ctx)) {
|
|
48330
|
-
const agentPath = `/internal/agent/${encodeURIComponent(ctx.agentId)}`;
|
|
48331
49648
|
const failCode = opts.block ? "WAIT_FAILED" : "CHECK_FAILED";
|
|
48332
|
-
const
|
|
48333
|
-
if (opts.block) query.push("block=true");
|
|
48334
|
-
if (opts.block && opts.timeoutMs !== void 0) query.push(`timeout=${opts.timeoutMs}`);
|
|
48335
|
-
const usesAgentApiSurface = ctx.clientMode === "managed-runner" || ctx.clientMode === "self-hosted-runner";
|
|
48336
|
-
const path9 = query.length > 0 ? `${agentPath}/receive?${query.join("&")}` : `${agentPath}/receive`;
|
|
49649
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
48337
49650
|
const allMessages = [];
|
|
48338
49651
|
let sawHasMore = false;
|
|
48339
49652
|
for (let round = 0; round < MAX_DRAIN_ROUNDS; round += 1) {
|
|
48340
|
-
|
|
48341
|
-
const res2 = await createAgentApiSurfaceClient(client).events.get({ since: "latest" });
|
|
48342
|
-
if (!res2.ok) {
|
|
48343
|
-
if (allMessages.length > 0) {
|
|
48344
|
-
return result(allMessages, { drainedMore: sawHasMore, hasMore: true });
|
|
48345
|
-
}
|
|
48346
|
-
throw new CliError({
|
|
48347
|
-
code: res2.status >= 500 ? "SERVER_5XX" : failCode,
|
|
48348
|
-
message: res2.error ?? `HTTP ${res2.status}`
|
|
48349
|
-
});
|
|
48350
|
-
}
|
|
48351
|
-
const messages2 = res2.data?.events ?? [];
|
|
48352
|
-
allMessages.push(...messages2);
|
|
48353
|
-
const hasMore2 = res2.data?.has_more === true;
|
|
48354
|
-
const drainComplete2 = !hasMore2 && allMessages.length > 0;
|
|
48355
|
-
sawHasMore = sawHasMore || hasMore2;
|
|
48356
|
-
if (hasMore2 && messages2.length > 0) continue;
|
|
48357
|
-
return result(allMessages, { drainedMore: sawHasMore, hasMore: hasMore2, drainComplete: drainComplete2 });
|
|
48358
|
-
}
|
|
48359
|
-
const res = await client.request("GET", path9);
|
|
49653
|
+
const res = await agentApi.events.get({ since: "latest" });
|
|
48360
49654
|
if (!res.ok) {
|
|
48361
49655
|
if (allMessages.length > 0) {
|
|
48362
49656
|
return result(allMessages, { drainedMore: sawHasMore, hasMore: true });
|
|
@@ -48366,25 +49660,13 @@ async function drainInbox(ctx, opts, client = new ApiClient(ctx)) {
|
|
|
48366
49660
|
message: res.error ?? `HTTP ${res.status}`
|
|
48367
49661
|
});
|
|
48368
49662
|
}
|
|
48369
|
-
const messages = res.data?.
|
|
49663
|
+
const messages = res.data?.events ?? [];
|
|
48370
49664
|
allMessages.push(...messages);
|
|
48371
|
-
const hasMore = res.data?.has_more === true
|
|
48372
|
-
const
|
|
48373
|
-
const drainComplete = hasExplicitHasMore && !hasMore && allMessages.length > 0;
|
|
49665
|
+
const hasMore = res.data?.has_more === true;
|
|
49666
|
+
const drainComplete = !hasMore && allMessages.length > 0;
|
|
48374
49667
|
sawHasMore = sawHasMore || hasMore;
|
|
48375
|
-
|
|
48376
|
-
|
|
48377
|
-
const ack = await client.request("POST", `${agentPath}/receive-ack`, { seqs });
|
|
48378
|
-
if (!ack.ok) {
|
|
48379
|
-
const ackCode = ack.status >= 500 ? "SERVER_5XX" : "ACK_FAILED";
|
|
48380
|
-
const ackMessage = ack.error ?? `HTTP ${ack.status}`;
|
|
48381
|
-
return result(allMessages, {
|
|
48382
|
-
ackFailure: { code: ackCode, message: ackMessage },
|
|
48383
|
-
drainedMore: sawHasMore,
|
|
48384
|
-
hasMore
|
|
48385
|
-
});
|
|
48386
|
-
}
|
|
48387
|
-
if (!hasMore) return result(allMessages, { drainedMore: sawHasMore, drainComplete });
|
|
49668
|
+
if (hasMore && messages.length > 0) continue;
|
|
49669
|
+
return result(allMessages, { drainedMore: sawHasMore, hasMore, drainComplete });
|
|
48388
49670
|
}
|
|
48389
49671
|
return result(allMessages, { drainedMore: sawHasMore, hasMore: true });
|
|
48390
49672
|
}
|
|
@@ -48488,7 +49770,7 @@ var messageReadCommand = defineCommand(
|
|
|
48488
49770
|
const readOpts = validateReadOpts(opts);
|
|
48489
49771
|
const agentContext = ctx.loadAgentContext();
|
|
48490
49772
|
const client = ctx.createApiClient(agentContext);
|
|
48491
|
-
const agentApi =
|
|
49773
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
48492
49774
|
const res = await agentApi.history.read({
|
|
48493
49775
|
channel: readOpts.channel,
|
|
48494
49776
|
...readOpts.before !== void 0 ? { before: readOpts.before } : {},
|
|
@@ -48561,29 +49843,53 @@ function parsePositiveInt3(name, raw) {
|
|
|
48561
49843
|
}
|
|
48562
49844
|
return n;
|
|
48563
49845
|
}
|
|
48564
|
-
function
|
|
48565
|
-
|
|
48566
|
-
|
|
49846
|
+
function parseNonNegativeInt(name, raw) {
|
|
49847
|
+
if (raw === void 0) return void 0;
|
|
49848
|
+
const n = Number(raw);
|
|
49849
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 0) {
|
|
48567
49850
|
throw new CliError({
|
|
48568
49851
|
code: "INVALID_ARG",
|
|
48569
|
-
message:
|
|
49852
|
+
message: `--${name} must be a non-negative integer; got ${raw}`
|
|
48570
49853
|
});
|
|
48571
49854
|
}
|
|
49855
|
+
return n;
|
|
49856
|
+
}
|
|
49857
|
+
function normalizeSearchOpts(opts) {
|
|
49858
|
+
const query = opts.query?.trim();
|
|
48572
49859
|
if (opts.sort !== void 0 && opts.sort !== "relevance" && opts.sort !== "recent") {
|
|
48573
49860
|
throw new CliError({
|
|
48574
49861
|
code: "INVALID_ARG",
|
|
48575
49862
|
message: `--sort must be "relevance" or "recent"; got ${opts.sort}`
|
|
48576
49863
|
});
|
|
48577
49864
|
}
|
|
49865
|
+
const channel = opts.channel?.trim();
|
|
49866
|
+
const sender = opts.sender ? normalizeMemberHandleRef(opts.sender) : void 0;
|
|
49867
|
+
const hasFilter = Boolean(channel || sender || opts.before || opts.after);
|
|
49868
|
+
if (!query && !hasFilter) {
|
|
49869
|
+
throw new CliError({
|
|
49870
|
+
code: "INVALID_ARG",
|
|
49871
|
+
message: "--query is required unless --sender, --channel, --before, or --after is provided"
|
|
49872
|
+
});
|
|
49873
|
+
}
|
|
49874
|
+
if (!query && opts.sort === "relevance") {
|
|
49875
|
+
throw new CliError({
|
|
49876
|
+
code: "INVALID_ARG",
|
|
49877
|
+
message: "--sort relevance requires --query; filter-only search is sorted by recent"
|
|
49878
|
+
});
|
|
49879
|
+
}
|
|
48578
49880
|
const limit = parsePositiveInt3("limit", opts.limit);
|
|
49881
|
+
const offset = parseNonNegativeInt("offset", opts.offset);
|
|
49882
|
+
const sort = opts.sort ?? (query ? void 0 : "recent");
|
|
48579
49883
|
return {
|
|
48580
|
-
query,
|
|
48581
|
-
|
|
48582
|
-
...
|
|
48583
|
-
...
|
|
49884
|
+
...query ? { query } : {},
|
|
49885
|
+
displayQuery: query ?? "",
|
|
49886
|
+
...channel ? { channel } : {},
|
|
49887
|
+
...sender ? { sender } : {},
|
|
49888
|
+
...sort ? { sort } : {},
|
|
48584
49889
|
...opts.before ? { before: opts.before } : {},
|
|
48585
49890
|
...opts.after ? { after: opts.after } : {},
|
|
48586
|
-
...limit !== void 0 ? { limit } : {}
|
|
49891
|
+
...limit !== void 0 ? { limit } : {},
|
|
49892
|
+
...offset !== void 0 ? { offset } : {}
|
|
48587
49893
|
};
|
|
48588
49894
|
}
|
|
48589
49895
|
function toSearchErrorCode(errorCode2, status) {
|
|
@@ -48600,13 +49906,14 @@ var messageSearchCommand = defineCommand(
|
|
|
48600
49906
|
name: "search",
|
|
48601
49907
|
description: "Search messages across channels the agent can see",
|
|
48602
49908
|
options: [
|
|
48603
|
-
{ flags: "--query <q>", description: "Search query string" },
|
|
49909
|
+
{ flags: "--query <q>", description: "Search query string (optional when filters are provided)" },
|
|
48604
49910
|
{ flags: "--channel <target>", description: "Restrict to a single channel/DM/thread" },
|
|
48605
49911
|
{ flags: "--sender <handle>", description: "Restrict to messages by sender handle, e.g. @alice" },
|
|
48606
|
-
{ flags: "--sort <mode>", description: "Sort results by relevance or recent (default: relevance)" },
|
|
49912
|
+
{ flags: "--sort <mode>", description: "Sort results by relevance or recent (default: relevance; filter-only searches use recent)" },
|
|
48607
49913
|
{ flags: "--before <iso>", description: "Only messages before this ISO datetime" },
|
|
48608
49914
|
{ flags: "--after <iso>", description: "Only messages after this ISO datetime" },
|
|
48609
|
-
{ flags: "--limit <n>", description: "Max results (server default applies if omitted)" }
|
|
49915
|
+
{ flags: "--limit <n>", description: "Max results (server default applies if omitted)" },
|
|
49916
|
+
{ flags: "--offset <n>", description: "Skip this many results (server default applies if omitted)" }
|
|
48610
49917
|
]
|
|
48611
49918
|
},
|
|
48612
49919
|
async (ctx, opts) => {
|
|
@@ -48615,13 +49922,14 @@ var messageSearchCommand = defineCommand(
|
|
|
48615
49922
|
const client = ctx.createApiClient(agentContext);
|
|
48616
49923
|
const agentApi = createAgentApiSurfaceClient(client);
|
|
48617
49924
|
const res = await agentApi.messages.search({
|
|
48618
|
-
q: searchOpts.query,
|
|
49925
|
+
...searchOpts.query ? { q: searchOpts.query } : {},
|
|
48619
49926
|
...searchOpts.channel ? { channel: searchOpts.channel } : {},
|
|
48620
49927
|
...searchOpts.sender ? { sender: searchOpts.sender } : {},
|
|
48621
49928
|
...searchOpts.sort ? { sort: searchOpts.sort } : {},
|
|
48622
49929
|
...searchOpts.before ? { before: searchOpts.before } : {},
|
|
48623
49930
|
...searchOpts.after ? { after: searchOpts.after } : {},
|
|
48624
|
-
...searchOpts.limit !== void 0 ? { limit: String(searchOpts.limit) } : {}
|
|
49931
|
+
...searchOpts.limit !== void 0 ? { limit: String(searchOpts.limit) } : {},
|
|
49932
|
+
...searchOpts.offset !== void 0 ? { offset: String(searchOpts.offset) } : {}
|
|
48625
49933
|
});
|
|
48626
49934
|
if (!res.ok) {
|
|
48627
49935
|
throw new CliError({
|
|
@@ -48629,7 +49937,7 @@ var messageSearchCommand = defineCommand(
|
|
|
48629
49937
|
message: res.error ?? `HTTP ${res.status}`
|
|
48630
49938
|
});
|
|
48631
49939
|
}
|
|
48632
|
-
writeText(ctx.io, `${formatSearchResults(searchOpts.
|
|
49940
|
+
writeText(ctx.io, `${formatSearchResults(searchOpts.displayQuery, res.data)}
|
|
48633
49941
|
`);
|
|
48634
49942
|
}
|
|
48635
49943
|
);
|
|
@@ -48677,7 +49985,7 @@ var messageResolveCommand = defineCommand(
|
|
|
48677
49985
|
}
|
|
48678
49986
|
const agentContext = ctx.loadAgentContext();
|
|
48679
49987
|
const client = ctx.createApiClient(agentContext);
|
|
48680
|
-
const res = await
|
|
49988
|
+
const res = await createAgentApiSurfaceClient(client).messages.resolve({ msgId: asMessageId(id) });
|
|
48681
49989
|
if (!res.ok) {
|
|
48682
49990
|
const mapped = mapResolveError(res);
|
|
48683
49991
|
throw new CliError(mapped);
|
|
@@ -48734,7 +50042,7 @@ var messageReactCommand = defineCommand(
|
|
|
48734
50042
|
}
|
|
48735
50043
|
const agentContext = ctx.loadAgentContext();
|
|
48736
50044
|
const client = ctx.createApiClient(agentContext);
|
|
48737
|
-
const agentApi =
|
|
50045
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
48738
50046
|
const messageId = asMessageId(opts.messageId.trim());
|
|
48739
50047
|
const res = opts.remove ? await agentApi.messages.removeReaction({ msgId: messageId }, { emoji: emoji3 }) : await agentApi.messages.addReaction({ msgId: messageId }, { emoji: emoji3 });
|
|
48740
50048
|
if (!res.ok) {
|
|
@@ -48752,7 +50060,7 @@ function registerReactCommand(parent, runtimeOptions = {}) {
|
|
|
48752
50060
|
init_esm_shims();
|
|
48753
50061
|
var MAX_ATTACHMENT_UPLOAD_BYTES = 50 * 1024 * 1024;
|
|
48754
50062
|
var MAX_ATTACHMENT_UPLOAD_LABEL = "50MB";
|
|
48755
|
-
var
|
|
50063
|
+
var FILENAME_MIME_MAP2 = {
|
|
48756
50064
|
".jpg": "image/jpeg",
|
|
48757
50065
|
".jpeg": "image/jpeg",
|
|
48758
50066
|
".png": "image/png",
|
|
@@ -48775,7 +50083,7 @@ var AttachmentUploadArgError = class extends Error {
|
|
|
48775
50083
|
function inferMimeTypeFromFilename(filename) {
|
|
48776
50084
|
const index = filename.lastIndexOf(".");
|
|
48777
50085
|
const ext = index >= 0 ? filename.slice(index).toLowerCase() : "";
|
|
48778
|
-
return
|
|
50086
|
+
return FILENAME_MIME_MAP2[ext] || null;
|
|
48779
50087
|
}
|
|
48780
50088
|
function inferMimeTypeFromBuffer(buffer) {
|
|
48781
50089
|
if (buffer.length >= 8 && buffer.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
|
|
@@ -48850,10 +50158,10 @@ var attachmentUploadCommand = defineCommand(
|
|
|
48850
50158
|
if (typeof opts.path !== "string" || opts.path.length === 0) {
|
|
48851
50159
|
throw cliError("INVALID_ARG", "--path is required");
|
|
48852
50160
|
}
|
|
48853
|
-
if (!
|
|
50161
|
+
if (!existsSync2(opts.path)) {
|
|
48854
50162
|
throw cliError("INVALID_ARG", `--path does not exist: ${opts.path}`);
|
|
48855
50163
|
}
|
|
48856
|
-
const stat2 =
|
|
50164
|
+
const stat2 = statSync2(opts.path);
|
|
48857
50165
|
if (!stat2.isFile()) {
|
|
48858
50166
|
throw cliError("INVALID_ARG", `--path is not a regular file: ${opts.path}`);
|
|
48859
50167
|
}
|
|
@@ -48869,8 +50177,8 @@ var attachmentUploadCommand = defineCommand(
|
|
|
48869
50177
|
"v0 server requires a channel to attach the upload to. Pass --channel '#name', 'dm:@peer', or a thread target."
|
|
48870
50178
|
);
|
|
48871
50179
|
}
|
|
48872
|
-
const buffer =
|
|
48873
|
-
const filename =
|
|
50180
|
+
const buffer = readFileSync3(opts.path);
|
|
50181
|
+
const filename = basename2(opts.path);
|
|
48874
50182
|
let explicitMimeType;
|
|
48875
50183
|
try {
|
|
48876
50184
|
explicitMimeType = normalizeExplicitMimeType(opts.mimeType);
|
|
@@ -48944,17 +50252,20 @@ var attachmentViewCommand = defineCommand(
|
|
|
48944
50252
|
const { id, output } = validateViewOpts(opts);
|
|
48945
50253
|
const agentContext = ctx.loadAgentContext();
|
|
48946
50254
|
const client = ctx.createApiClient(agentContext);
|
|
48947
|
-
const res = await client.
|
|
48948
|
-
"GET",
|
|
48949
|
-
`/api/attachments/${encodeURIComponent(id)}`
|
|
48950
|
-
);
|
|
50255
|
+
const res = await createAgentApiSurfaceClient(client).attachments.view({ attachmentId: id });
|
|
48951
50256
|
if (!res.ok) {
|
|
48952
50257
|
throw new CliError({
|
|
48953
50258
|
code: res.status >= 500 ? "SERVER_5XX" : "VIEW_FAILED",
|
|
48954
50259
|
message: res.error ?? `HTTP ${res.status}`
|
|
48955
50260
|
});
|
|
48956
50261
|
}
|
|
48957
|
-
|
|
50262
|
+
if (res.data === null) {
|
|
50263
|
+
throw new CliError({
|
|
50264
|
+
code: "VIEW_FAILED",
|
|
50265
|
+
message: "Attachment download returned no bytes"
|
|
50266
|
+
});
|
|
50267
|
+
}
|
|
50268
|
+
const buffer = Buffer.from(res.data);
|
|
48958
50269
|
writeFileSync(output, buffer);
|
|
48959
50270
|
writeText(ctx.io, `Downloaded to: ${output}
|
|
48960
50271
|
`);
|
|
@@ -49002,11 +50313,9 @@ var attachmentCommentsCommand = defineCommand(
|
|
|
49002
50313
|
}
|
|
49003
50314
|
const agentContext = ctx.loadAgentContext();
|
|
49004
50315
|
const client = ctx.createApiClient(agentContext);
|
|
49005
|
-
const
|
|
49006
|
-
const
|
|
49007
|
-
|
|
49008
|
-
`/api/attachments/${encodeURIComponent(id)}/comments${limitParam}`
|
|
49009
|
-
);
|
|
50316
|
+
const agentApi = createAgentApiSurfaceClient(client);
|
|
50317
|
+
const limit = opts.limit && Number.isFinite(Number(opts.limit)) ? String(Number(opts.limit)) : void 0;
|
|
50318
|
+
const res = await agentApi.attachments.comments({ attachmentId: id }, limit ? { limit } : {});
|
|
49010
50319
|
if (!res.ok || !res.data) {
|
|
49011
50320
|
const code = res.status >= 500 ? "SERVER_5XX" : "COMMENTS_FAILED";
|
|
49012
50321
|
throw new CliError({ code, message: res.error ?? `HTTP ${res.status}` });
|
|
@@ -49065,7 +50374,7 @@ function formatClaimResults(channel, data) {
|
|
|
49065
50374
|
const msgShort = r.messageId ? r.messageId.slice(0, 8) : "";
|
|
49066
50375
|
return `${label} (msg:${msgShort}): claimed`;
|
|
49067
50376
|
}
|
|
49068
|
-
return `${label}: FAILED \u2014 ${r.reason || "already claimed"}. Do not
|
|
50377
|
+
return `${label}: FAILED \u2014 ${r.reason || "already claimed"}. Do not work on this task unless an owner/admin explicitly redirects it to you.`;
|
|
49069
50378
|
});
|
|
49070
50379
|
const succeeded = data.results.filter((r) => r.success).length;
|
|
49071
50380
|
const failed = data.results.length - succeeded;
|
|
@@ -49404,7 +50713,7 @@ function buildMentionExecuteCommand(action) {
|
|
|
49404
50713
|
const ids = normalizeResolutionIds(resolutionIds);
|
|
49405
50714
|
const agentContext = ctx.loadAgentContext();
|
|
49406
50715
|
const client = ctx.createApiClient(agentContext);
|
|
49407
|
-
const res = await
|
|
50716
|
+
const res = await createAgentApiSurfaceClient(client).mentions.executeAction({
|
|
49408
50717
|
action,
|
|
49409
50718
|
resolutionIds: ids
|
|
49410
50719
|
});
|
|
@@ -49434,7 +50743,7 @@ var mentionPendingCommand = defineCommand(
|
|
|
49434
50743
|
async (ctx, opts = {}) => {
|
|
49435
50744
|
const agentContext = ctx.loadAgentContext();
|
|
49436
50745
|
const client = ctx.createApiClient(agentContext);
|
|
49437
|
-
const res = await
|
|
50746
|
+
const res = await createAgentApiSurfaceClient(client).mentions.pendingActions();
|
|
49438
50747
|
if (!res.ok || !res.data) {
|
|
49439
50748
|
throw cliError(res.status >= 500 ? "SERVER_5XX" : "MENTION_PENDING_FAILED", res.error ?? `HTTP ${res.status}`);
|
|
49440
50749
|
}
|
|
@@ -49454,65 +50763,6 @@ function registerMentionCommands(parent, runtimeOptions = {}) {
|
|
|
49454
50763
|
registerMentionExecuteCommands(parent, runtimeOptions);
|
|
49455
50764
|
}
|
|
49456
50765
|
init_esm_shims();
|
|
49457
|
-
init_esm_shims();
|
|
49458
|
-
function formatCreatedAgents(createdAgents) {
|
|
49459
|
-
if (createdAgents.length === 0) {
|
|
49460
|
-
return ["- Created Agents: none"];
|
|
49461
|
-
}
|
|
49462
|
-
return [
|
|
49463
|
-
`- Created Agents (${createdAgents.length}):`,
|
|
49464
|
-
...createdAgents.map((createdAgent) => ` - @${createdAgent.name} (${getRuntimeDisplayName(createdAgent.runtime)}, ${createdAgent.status})`)
|
|
49465
|
-
];
|
|
49466
|
-
}
|
|
49467
|
-
function formatHumanProfile(profile) {
|
|
49468
|
-
const lines = [
|
|
49469
|
-
"## Profile",
|
|
49470
|
-
"",
|
|
49471
|
-
"- Type: human",
|
|
49472
|
-
`- Handle: @${profile.name}`,
|
|
49473
|
-
`- Display Name: ${profile.displayName ?? "(none)"}`,
|
|
49474
|
-
`- Description: ${profile.description ?? "(none)"}`,
|
|
49475
|
-
`- Membership: ${profile.membershipStatus}`
|
|
49476
|
-
];
|
|
49477
|
-
if (profile.role) lines.push(`- Role: ${profile.role}`);
|
|
49478
|
-
if (profile.joinedAt) lines.push(`- Joined: ${profile.joinedAt}`);
|
|
49479
|
-
if (profile.email) lines.push(`- Email: ${profile.email}`);
|
|
49480
|
-
return [...lines, ...formatCreatedAgents(profile.createdAgents)].join("\n");
|
|
49481
|
-
}
|
|
49482
|
-
function formatCreator(profile) {
|
|
49483
|
-
if (!profile.creator) return null;
|
|
49484
|
-
return profile.creator.displayName ? `${profile.creator.displayName} (@${profile.creator.name})` : `@${profile.creator.name}`;
|
|
49485
|
-
}
|
|
49486
|
-
function formatAgentProfile(profile) {
|
|
49487
|
-
const lines = [
|
|
49488
|
-
"## Profile",
|
|
49489
|
-
"",
|
|
49490
|
-
"- Type: agent",
|
|
49491
|
-
`- Handle: @${profile.name}`,
|
|
49492
|
-
`- Display Name: ${profile.displayName ?? "(none)"}`,
|
|
49493
|
-
`- Description: ${profile.description ?? "(none)"}`,
|
|
49494
|
-
`- Status: ${profile.status}`,
|
|
49495
|
-
`- Role: ${profile.serverRole}`,
|
|
49496
|
-
`- Runtime: ${getRuntimeDisplayName(profile.runtime)}`,
|
|
49497
|
-
`- Model: ${profile.model}`,
|
|
49498
|
-
`- Reasoning: ${profile.reasoningEffort ?? "medium"}`
|
|
49499
|
-
];
|
|
49500
|
-
if (profile.executionMode) lines.push(`- Execution: ${profile.executionMode}`);
|
|
49501
|
-
if (profile.computerName || profile.computerId) {
|
|
49502
|
-
const label = profile.computerName && profile.computerId ? `${profile.computerName} (${profile.computerId})` : profile.computerName ?? profile.computerId;
|
|
49503
|
-
lines.push(`- Computer: ${label}`);
|
|
49504
|
-
}
|
|
49505
|
-
if (profile.computerHostname) lines.push(`- Hostname: ${profile.computerHostname}`);
|
|
49506
|
-
if (profile.daemonVersion) lines.push(`- Daemon: v${profile.daemonVersion}`);
|
|
49507
|
-
lines.push(`- Created: ${profile.createdAt}`);
|
|
49508
|
-
if (profile.deletedAt) lines.push(`- Deleted At: ${profile.deletedAt}`);
|
|
49509
|
-
const creator = formatCreator(profile);
|
|
49510
|
-
if (creator) lines.push(`- Creator: ${creator}`);
|
|
49511
|
-
return [...lines, ...formatCreatedAgents(profile.createdAgents)].join("\n");
|
|
49512
|
-
}
|
|
49513
|
-
function formatProfile(profile) {
|
|
49514
|
-
return profile.kind === "human" ? formatHumanProfile(profile) : formatAgentProfile(profile);
|
|
49515
|
-
}
|
|
49516
50766
|
function normalizeTarget(target) {
|
|
49517
50767
|
if (target === void 0) return null;
|
|
49518
50768
|
const trimmed = target.trim();
|
|
@@ -49562,173 +50812,6 @@ function registerProfileShowCommand(parent, runtimeOptions) {
|
|
|
49562
50812
|
registerCliCommand(parent, profileShowCommand, runtimeOptions);
|
|
49563
50813
|
}
|
|
49564
50814
|
init_esm_shims();
|
|
49565
|
-
var MAX_PROFILE_AVATAR_BYTES = 2 * 1024 * 1024;
|
|
49566
|
-
var PROFILE_AVATAR_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
49567
|
-
"image/jpeg",
|
|
49568
|
-
"image/png",
|
|
49569
|
-
"image/gif",
|
|
49570
|
-
"image/webp"
|
|
49571
|
-
]);
|
|
49572
|
-
var FILENAME_MIME_MAP2 = {
|
|
49573
|
-
".jpg": "image/jpeg",
|
|
49574
|
-
".jpeg": "image/jpeg",
|
|
49575
|
-
".png": "image/png",
|
|
49576
|
-
".gif": "image/gif",
|
|
49577
|
-
".webp": "image/webp"
|
|
49578
|
-
};
|
|
49579
|
-
var MAX_PROFILE_DESCRIPTION_LENGTH = 3e3;
|
|
49580
|
-
var MAX_PROFILE_DISPLAY_NAME_LENGTH = 80;
|
|
49581
|
-
function inferImageMimeType(filename, buffer) {
|
|
49582
|
-
const lowerFilename = filename.toLowerCase();
|
|
49583
|
-
if (buffer.length >= 8 && buffer.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
|
|
49584
|
-
return "image/png";
|
|
49585
|
-
}
|
|
49586
|
-
if (buffer.length >= 3 && buffer.subarray(0, 3).equals(Buffer.from([255, 216, 255]))) {
|
|
49587
|
-
return "image/jpeg";
|
|
49588
|
-
}
|
|
49589
|
-
if (buffer.length >= 6) {
|
|
49590
|
-
const header = buffer.subarray(0, 6).toString("ascii");
|
|
49591
|
-
if (header === "GIF87a" || header === "GIF89a") return "image/gif";
|
|
49592
|
-
}
|
|
49593
|
-
if (buffer.length >= 12 && buffer.subarray(0, 4).toString("ascii") === "RIFF" && buffer.subarray(8, 12).toString("ascii") === "WEBP") {
|
|
49594
|
-
return "image/webp";
|
|
49595
|
-
}
|
|
49596
|
-
const dot = lowerFilename.lastIndexOf(".");
|
|
49597
|
-
return dot >= 0 ? FILENAME_MIME_MAP2[lowerFilename.slice(dot)] ?? null : null;
|
|
49598
|
-
}
|
|
49599
|
-
function readAvatarFile(avatarFile) {
|
|
49600
|
-
if (!existsSync2(avatarFile)) {
|
|
49601
|
-
throw cliError("PROFILE_FILE_NOT_FOUND", `Avatar file does not exist: ${avatarFile}`);
|
|
49602
|
-
}
|
|
49603
|
-
const stat2 = statSync2(avatarFile);
|
|
49604
|
-
if (!stat2.isFile()) {
|
|
49605
|
-
throw cliError("PROFILE_FILE_NOT_FOUND", `Avatar file is not a regular file: ${avatarFile}`);
|
|
49606
|
-
}
|
|
49607
|
-
if (stat2.size > MAX_PROFILE_AVATAR_BYTES) {
|
|
49608
|
-
throw cliError(
|
|
49609
|
-
"PROFILE_AVATAR_TOO_LARGE",
|
|
49610
|
-
`Avatar file is ${stat2.size} bytes; max size is ${MAX_PROFILE_AVATAR_BYTES} bytes`
|
|
49611
|
-
);
|
|
49612
|
-
}
|
|
49613
|
-
const buffer = readFileSync3(avatarFile);
|
|
49614
|
-
const filename = basename2(avatarFile);
|
|
49615
|
-
const mimeType = inferImageMimeType(filename, buffer);
|
|
49616
|
-
if (!mimeType || !PROFILE_AVATAR_MIME_TYPES.has(mimeType)) {
|
|
49617
|
-
throw cliError(
|
|
49618
|
-
"PROFILE_AVATAR_BAD_FORMAT",
|
|
49619
|
-
"Avatar must be a JPEG, PNG, GIF, or WebP image"
|
|
49620
|
-
);
|
|
49621
|
-
}
|
|
49622
|
-
return { filename, buffer, mimeType };
|
|
49623
|
-
}
|
|
49624
|
-
function normalizeAvatarUrl(avatarUrl) {
|
|
49625
|
-
const trimmed = avatarUrl.trim();
|
|
49626
|
-
if (trimmed.length === 0) {
|
|
49627
|
-
throw cliError("INVALID_ARG", "--avatar-url must not be empty");
|
|
49628
|
-
}
|
|
49629
|
-
if (!trimmed.startsWith("pixel:")) {
|
|
49630
|
-
throw cliError("INVALID_ARG", "--avatar-url currently supports only pixel avatar URLs; use --avatar-file for image uploads");
|
|
49631
|
-
}
|
|
49632
|
-
return trimmed;
|
|
49633
|
-
}
|
|
49634
|
-
var profileUpdateCommand = defineCommand(
|
|
49635
|
-
{
|
|
49636
|
-
name: "update",
|
|
49637
|
-
description: "Update your own profile",
|
|
49638
|
-
options: [
|
|
49639
|
-
{ flags: "--avatar-file <path>", description: "Path to a local image file to use as your avatar" },
|
|
49640
|
-
{ flags: "--avatar-url <value>", description: "Set a pixel avatar URL such as pixel:random:<seed>" },
|
|
49641
|
-
{ flags: "--display-name <name>", description: "Set your display name (non-empty)" },
|
|
49642
|
-
{ flags: "--description <text>", description: "Set your profile description (non-empty)" },
|
|
49643
|
-
{ flags: "--json", description: "Emit machine-readable JSON" }
|
|
49644
|
-
]
|
|
49645
|
-
},
|
|
49646
|
-
async (ctx, opts) => {
|
|
49647
|
-
const hasAvatar = opts.avatarFile !== void 0;
|
|
49648
|
-
const hasAvatarUrl = opts.avatarUrl !== void 0;
|
|
49649
|
-
const hasDisplayName = opts.displayName !== void 0;
|
|
49650
|
-
const hasDescription = opts.description !== void 0;
|
|
49651
|
-
if (!hasAvatar && !hasAvatarUrl && !hasDisplayName && !hasDescription) {
|
|
49652
|
-
throw cliError("INVALID_ARG", "Provide at least one of --avatar-file, --avatar-url, --display-name, or --description");
|
|
49653
|
-
}
|
|
49654
|
-
if (hasAvatar && hasAvatarUrl) {
|
|
49655
|
-
throw cliError("INVALID_ARG", "Use either --avatar-file or --avatar-url, not both");
|
|
49656
|
-
}
|
|
49657
|
-
let normalizedAvatarUrl;
|
|
49658
|
-
if (hasAvatarUrl) {
|
|
49659
|
-
normalizedAvatarUrl = normalizeAvatarUrl(opts.avatarUrl);
|
|
49660
|
-
}
|
|
49661
|
-
let trimmedDisplayName;
|
|
49662
|
-
if (hasDisplayName) {
|
|
49663
|
-
trimmedDisplayName = opts.displayName.trim();
|
|
49664
|
-
if (trimmedDisplayName.length === 0) {
|
|
49665
|
-
throw cliError("INVALID_ARG", "--display-name must not be empty");
|
|
49666
|
-
}
|
|
49667
|
-
if (trimmedDisplayName.length > MAX_PROFILE_DISPLAY_NAME_LENGTH) {
|
|
49668
|
-
throw cliError("INVALID_ARG", `--display-name must be at most ${MAX_PROFILE_DISPLAY_NAME_LENGTH} characters`);
|
|
49669
|
-
}
|
|
49670
|
-
}
|
|
49671
|
-
if (hasDescription) {
|
|
49672
|
-
if (opts.description.length === 0) {
|
|
49673
|
-
throw cliError("INVALID_ARG", "--description must not be empty");
|
|
49674
|
-
}
|
|
49675
|
-
if (opts.description.length > MAX_PROFILE_DESCRIPTION_LENGTH) {
|
|
49676
|
-
throw cliError("INVALID_ARG", `--description must be at most ${MAX_PROFILE_DESCRIPTION_LENGTH} characters`);
|
|
49677
|
-
}
|
|
49678
|
-
}
|
|
49679
|
-
const avatar = hasAvatar ? readAvatarFile(opts.avatarFile) : null;
|
|
49680
|
-
const agentContext = ctx.loadAgentContext();
|
|
49681
|
-
const client = ctx.createApiClient(agentContext);
|
|
49682
|
-
const agentApi = createAgentApiSurfaceClient(client);
|
|
49683
|
-
let latestProfile = null;
|
|
49684
|
-
if (hasAvatarUrl || hasDisplayName || hasDescription) {
|
|
49685
|
-
const body = {};
|
|
49686
|
-
if (hasAvatarUrl) {
|
|
49687
|
-
body.avatarUrl = normalizedAvatarUrl;
|
|
49688
|
-
}
|
|
49689
|
-
if (hasDisplayName) {
|
|
49690
|
-
body.displayName = trimmedDisplayName;
|
|
49691
|
-
}
|
|
49692
|
-
if (hasDescription) {
|
|
49693
|
-
body.description = opts.description;
|
|
49694
|
-
}
|
|
49695
|
-
const res = await agentApi.profile.update(body);
|
|
49696
|
-
if (!res.ok || !res.data) {
|
|
49697
|
-
const code = res.errorCode ?? (res.status >= 500 ? "SERVER_5XX" : "PROFILE_UPDATE_FAILED");
|
|
49698
|
-
throw cliError(code, res.error ?? `HTTP ${res.status}`);
|
|
49699
|
-
}
|
|
49700
|
-
latestProfile = res.data;
|
|
49701
|
-
}
|
|
49702
|
-
if (hasAvatar) {
|
|
49703
|
-
const form = new FormData();
|
|
49704
|
-
const avatarBytes = Uint8Array.from(avatar.buffer);
|
|
49705
|
-
form.append("avatar", new Blob([avatarBytes], { type: avatar.mimeType }), avatar.filename);
|
|
49706
|
-
const res = await client.requestMultipart(
|
|
49707
|
-
"POST",
|
|
49708
|
-
"/internal/agent-api/profile/avatar",
|
|
49709
|
-
form
|
|
49710
|
-
);
|
|
49711
|
-
if (!res.ok || !res.data) {
|
|
49712
|
-
const code = res.errorCode ?? (res.status >= 500 ? "SERVER_5XX" : "PROFILE_UPDATE_FAILED");
|
|
49713
|
-
throw cliError(code, res.error ?? `HTTP ${res.status}`);
|
|
49714
|
-
}
|
|
49715
|
-
latestProfile = res.data;
|
|
49716
|
-
}
|
|
49717
|
-
if (!latestProfile) {
|
|
49718
|
-
throw cliError("PROFILE_UPDATE_FAILED", "No profile returned from server");
|
|
49719
|
-
}
|
|
49720
|
-
if (opts.json) {
|
|
49721
|
-
writeJson(ctx.io, { ok: true, data: latestProfile });
|
|
49722
|
-
return;
|
|
49723
|
-
}
|
|
49724
|
-
writeText(ctx.io, `${formatProfile(latestProfile)}
|
|
49725
|
-
`);
|
|
49726
|
-
}
|
|
49727
|
-
);
|
|
49728
|
-
function registerProfileUpdateCommand(parent, runtimeOptions = {}) {
|
|
49729
|
-
registerCliCommand(parent, profileUpdateCommand, runtimeOptions);
|
|
49730
|
-
}
|
|
49731
|
-
init_esm_shims();
|
|
49732
50815
|
init_esm_shims();
|
|
49733
50816
|
function formatMaybe(value) {
|
|
49734
50817
|
return value?.trim() || "-";
|
|
@@ -49753,6 +50836,7 @@ function pushServiceBlock(lines, service, active) {
|
|
|
49753
50836
|
if (service.agentManifestUrl) {
|
|
49754
50837
|
lines.push(` agent behavior manifest: ${service.agentManifestUrl}`);
|
|
49755
50838
|
lines.push(` local CLI env: raft integration env --service ${JSON.stringify(service.clientId)}`);
|
|
50839
|
+
lines.push(` if manifest exposes HTTP API actions: raft integration invoke --service ${JSON.stringify(service.clientId)} --list-actions`);
|
|
49756
50840
|
}
|
|
49757
50841
|
if (service.homepageUrl) lines.push(` homepage: ${service.homepageUrl}`);
|
|
49758
50842
|
if (service.description) lines.push(` description: ${service.description}`);
|
|
@@ -49792,6 +50876,7 @@ function formatIntegrationList(data) {
|
|
|
49792
50876
|
if (login.agentManifestUrl) {
|
|
49793
50877
|
lines.push(` agent behavior manifest: ${login.agentManifestUrl}`);
|
|
49794
50878
|
lines.push(` local CLI env: raft integration env --service ${JSON.stringify(login.clientId)}`);
|
|
50879
|
+
lines.push(` if manifest exposes HTTP API actions: raft integration invoke --service ${JSON.stringify(login.clientId)} --list-actions`);
|
|
49795
50880
|
}
|
|
49796
50881
|
lines.push(` created: ${login.createdAt}`);
|
|
49797
50882
|
}
|
|
@@ -49828,14 +50913,15 @@ function formatIntegrationLogin(data) {
|
|
|
49828
50913
|
if (data.service.agentManifestUrl) {
|
|
49829
50914
|
lines.push(`agent behavior manifest: ${data.service.agentManifestUrl}`);
|
|
49830
50915
|
lines.push(`local CLI env: raft integration env --service ${JSON.stringify(data.service.clientId)}`);
|
|
50916
|
+
lines.push(`if manifest exposes HTTP API actions: raft integration invoke --service ${JSON.stringify(data.service.clientId)} --list-actions`);
|
|
49831
50917
|
}
|
|
49832
50918
|
lines.push("complete: this agent login is configured in Slock; no human OAuth is required");
|
|
49833
50919
|
lines.push("identity: run `raft profile show` if the service or human asks for your Slock Agent identity card");
|
|
49834
50920
|
const callbackHandoffUrl = buildAgentCallbackHandoffUrl(data.service.returnUrl, data.requestId);
|
|
49835
50921
|
if (callbackHandoffUrl) {
|
|
49836
50922
|
lines.push(`service callback handoff URL: ${callbackHandoffUrl}`);
|
|
49837
|
-
lines.push("
|
|
49838
|
-
lines.push(
|
|
50923
|
+
lines.push("note: stateless Login with Raft API-action services use this callback once to create their service session");
|
|
50924
|
+
lines.push(`next: prefer \`raft integration invoke --service ${JSON.stringify(data.service.clientId)} --list-actions\` when the service manifest exposes actions`);
|
|
49839
50925
|
} else {
|
|
49840
50926
|
lines.push("next: use the service, or run `raft integration list` to confirm active login");
|
|
49841
50927
|
}
|
|
@@ -49927,7 +51013,10 @@ init_esm_shims();
|
|
|
49927
51013
|
init_esm_shims();
|
|
49928
51014
|
var AGENT_MANIFEST_MAX_BYTES = 64 * 1024;
|
|
49929
51015
|
var AGENT_MANIFEST_SCHEMA_V0 = "slock-agent-manifest.v0";
|
|
51016
|
+
var RAFT_AGENT_MANIFEST_SCHEMA_V0 = "raft-agent-manifest.v0";
|
|
49930
51017
|
var AGENT_MANIFEST_SCHEMA_V0_URL = "https://app.slock.ai/schemas/agent-manifest.v0.json";
|
|
51018
|
+
var RAFT_AGENT_MANIFEST_WELL_KNOWN_PATH = "/.well-known/raft-agent-manifest.json";
|
|
51019
|
+
var SLOCK_AGENT_MANIFEST_WELL_KNOWN_PATH = "/.well-known/slock-agent-manifest.json";
|
|
49931
51020
|
var AgentManifestFetchError = class extends Error {
|
|
49932
51021
|
constructor(message, status) {
|
|
49933
51022
|
super(message);
|
|
@@ -49972,10 +51061,125 @@ function requireCommand(value) {
|
|
|
49972
51061
|
}
|
|
49973
51062
|
return command;
|
|
49974
51063
|
}
|
|
51064
|
+
function requireName(value, field) {
|
|
51065
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
51066
|
+
throw new Error(`${field} must be a non-empty string`);
|
|
51067
|
+
}
|
|
51068
|
+
const name = value.trim();
|
|
51069
|
+
if (!/^[A-Za-z0-9._:-]{1,80}$/.test(name)) {
|
|
51070
|
+
throw new Error(`${field} may only contain letters, digits, dot, underscore, colon, or dash`);
|
|
51071
|
+
}
|
|
51072
|
+
return name;
|
|
51073
|
+
}
|
|
51074
|
+
function optionalString(value) {
|
|
51075
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
51076
|
+
}
|
|
51077
|
+
function requireEndpointPath(value, field) {
|
|
51078
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
51079
|
+
throw new Error(`${field} must be a non-empty path string`);
|
|
51080
|
+
}
|
|
51081
|
+
const path9 = value.trim();
|
|
51082
|
+
if (!path9.startsWith("/")) {
|
|
51083
|
+
throw new Error(`${field} must start with /`);
|
|
51084
|
+
}
|
|
51085
|
+
if (path9.startsWith("//")) {
|
|
51086
|
+
throw new Error(`${field} must be a relative service path`);
|
|
51087
|
+
}
|
|
51088
|
+
try {
|
|
51089
|
+
const parsed = new URL(path9, "https://manifest.local");
|
|
51090
|
+
if (parsed.origin !== "https://manifest.local" || parsed.username || parsed.password || parsed.hash) {
|
|
51091
|
+
throw new Error();
|
|
51092
|
+
}
|
|
51093
|
+
} catch {
|
|
51094
|
+
throw new Error(`${field} must be a relative service path`);
|
|
51095
|
+
}
|
|
51096
|
+
return path9;
|
|
51097
|
+
}
|
|
51098
|
+
function normalizeActionMethod(value) {
|
|
51099
|
+
if (typeof value !== "string") {
|
|
51100
|
+
throw new Error("actions[].endpoint.method must be a string");
|
|
51101
|
+
}
|
|
51102
|
+
const method = value.trim().toUpperCase();
|
|
51103
|
+
if (method !== "GET" && method !== "POST" && method !== "PUT" && method !== "PATCH" && method !== "DELETE") {
|
|
51104
|
+
throw new Error("actions[].endpoint.method must be GET, POST, PUT, PATCH, or DELETE");
|
|
51105
|
+
}
|
|
51106
|
+
return method;
|
|
51107
|
+
}
|
|
51108
|
+
function normalizeActionFields(value, field) {
|
|
51109
|
+
if (value === void 0) return void 0;
|
|
51110
|
+
if (!isRecord(value)) throw new Error(`${field} must be an object when present`);
|
|
51111
|
+
const fields = {};
|
|
51112
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
51113
|
+
const name = requireName(key, `${field} key`);
|
|
51114
|
+
if (!isRecord(raw)) throw new Error(`${field}.${name} must be an object`);
|
|
51115
|
+
if (typeof raw.type !== "string" || !raw.type.trim()) {
|
|
51116
|
+
throw new Error(`${field}.${name}.type must be a non-empty string`);
|
|
51117
|
+
}
|
|
51118
|
+
fields[name] = {
|
|
51119
|
+
type: raw.type.trim(),
|
|
51120
|
+
description: optionalString(raw.description),
|
|
51121
|
+
required: raw.required === true
|
|
51122
|
+
};
|
|
51123
|
+
}
|
|
51124
|
+
return fields;
|
|
51125
|
+
}
|
|
51126
|
+
function normalizeActionReturns(value) {
|
|
51127
|
+
if (value === void 0) return void 0;
|
|
51128
|
+
if (!isRecord(value)) throw new Error("actions[].returns must be an object when present");
|
|
51129
|
+
const fields = {};
|
|
51130
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
51131
|
+
const name = requireName(key, "actions[].returns key");
|
|
51132
|
+
if (!isRecord(raw)) throw new Error(`actions[].returns.${name} must be an object`);
|
|
51133
|
+
if (typeof raw.type !== "string" || !raw.type.trim()) {
|
|
51134
|
+
throw new Error(`actions[].returns.${name}.type must be a non-empty string`);
|
|
51135
|
+
}
|
|
51136
|
+
fields[name] = {
|
|
51137
|
+
type: raw.type.trim(),
|
|
51138
|
+
description: optionalString(raw.description)
|
|
51139
|
+
};
|
|
51140
|
+
}
|
|
51141
|
+
return fields;
|
|
51142
|
+
}
|
|
51143
|
+
function normalizeActions(value) {
|
|
51144
|
+
if (value === void 0) return void 0;
|
|
51145
|
+
if (!Array.isArray(value)) throw new Error("actions must be an array when present");
|
|
51146
|
+
const actions = value.map((raw, index) => {
|
|
51147
|
+
if (!isRecord(raw)) throw new Error(`actions[${index}] must be an object`);
|
|
51148
|
+
const endpoint = raw.endpoint;
|
|
51149
|
+
if (!isRecord(endpoint)) throw new Error(`actions[${index}].endpoint must be an object`);
|
|
51150
|
+
return {
|
|
51151
|
+
name: requireName(raw.name, `actions[${index}].name`),
|
|
51152
|
+
description: optionalString(raw.description),
|
|
51153
|
+
endpoint: {
|
|
51154
|
+
method: normalizeActionMethod(endpoint.method),
|
|
51155
|
+
path: requireEndpointPath(endpoint.path, `actions[${index}].endpoint.path`)
|
|
51156
|
+
},
|
|
51157
|
+
parameters: normalizeActionFields(raw.parameters, `actions[${index}].parameters`),
|
|
51158
|
+
returns: normalizeActionReturns(raw.returns)
|
|
51159
|
+
};
|
|
51160
|
+
});
|
|
51161
|
+
const seen = /* @__PURE__ */ new Set();
|
|
51162
|
+
for (const action of actions) {
|
|
51163
|
+
if (seen.has(action.name)) throw new Error(`duplicate action name: ${action.name}`);
|
|
51164
|
+
seen.add(action.name);
|
|
51165
|
+
}
|
|
51166
|
+
return actions;
|
|
51167
|
+
}
|
|
51168
|
+
function normalizeAuth(value) {
|
|
51169
|
+
if (value === void 0) return void 0;
|
|
51170
|
+
if (!isRecord(value)) throw new Error("auth must be an object when present");
|
|
51171
|
+
if (value.type !== "login_with_raft") {
|
|
51172
|
+
throw new Error("auth.type must be login_with_raft");
|
|
51173
|
+
}
|
|
51174
|
+
return {
|
|
51175
|
+
type: "login_with_raft",
|
|
51176
|
+
login_url: value.login_url === void 0 ? void 0 : requireUrl(value.login_url, "auth.login_url")
|
|
51177
|
+
};
|
|
51178
|
+
}
|
|
49975
51179
|
function validateAgentManifestV0(value) {
|
|
49976
51180
|
if (!isRecord(value)) throw new Error("manifest must be a JSON object");
|
|
49977
|
-
if (value.schema !== AGENT_MANIFEST_SCHEMA_V0 && value.schema !== AGENT_MANIFEST_SCHEMA_V0_URL) {
|
|
49978
|
-
throw new Error(`manifest schema must be ${AGENT_MANIFEST_SCHEMA_V0}`);
|
|
51181
|
+
if (value.schema !== AGENT_MANIFEST_SCHEMA_V0 && value.schema !== RAFT_AGENT_MANIFEST_SCHEMA_V0 && value.schema !== AGENT_MANIFEST_SCHEMA_V0_URL) {
|
|
51182
|
+
throw new Error(`manifest schema must be ${AGENT_MANIFEST_SCHEMA_V0} or ${RAFT_AGENT_MANIFEST_SCHEMA_V0}`);
|
|
49979
51183
|
}
|
|
49980
51184
|
const execution = value.execution;
|
|
49981
51185
|
if (!isRecord(execution)) throw new Error("execution must be an object");
|
|
@@ -49997,12 +51201,17 @@ function validateAgentManifestV0(value) {
|
|
|
49997
51201
|
return {
|
|
49998
51202
|
schema: AGENT_MANIFEST_SCHEMA_V0,
|
|
49999
51203
|
service: typeof value.service === "string" && value.service.trim() ? value.service.trim() : void 0,
|
|
51204
|
+
name: optionalString(value.name),
|
|
51205
|
+
description: optionalString(value.description),
|
|
50000
51206
|
docs_url: value.docs_url === void 0 ? void 0 : requireUrl(value.docs_url, "docs_url"),
|
|
51207
|
+
app_origin: value.app_origin === void 0 ? void 0 : requireUrl(value.app_origin, "app_origin"),
|
|
50001
51208
|
execution: {
|
|
50002
51209
|
mode: execution.mode,
|
|
50003
51210
|
command: execution.mode === "local_cli" ? requireCommand(execution.command) : void 0,
|
|
50004
51211
|
base_url: execution.base_url === void 0 ? void 0 : requireUrl(execution.base_url, "execution.base_url")
|
|
50005
51212
|
},
|
|
51213
|
+
auth: normalizeAuth(value.auth),
|
|
51214
|
+
actions: normalizeActions(value.actions),
|
|
50006
51215
|
credential_boundary: credentialStorage ? {
|
|
50007
51216
|
storage: credentialStorage,
|
|
50008
51217
|
forbid_user_home: forbidUserHome
|
|
@@ -50050,13 +51259,45 @@ async function fetchAgentManifest(url2) {
|
|
|
50050
51259
|
}
|
|
50051
51260
|
return validateAgentManifestV0(parsedJson);
|
|
50052
51261
|
}
|
|
51262
|
+
function wellKnownAliasUrl(url2) {
|
|
51263
|
+
const parsed = new URL(url2);
|
|
51264
|
+
if (parsed.pathname === RAFT_AGENT_MANIFEST_WELL_KNOWN_PATH) {
|
|
51265
|
+
parsed.pathname = SLOCK_AGENT_MANIFEST_WELL_KNOWN_PATH;
|
|
51266
|
+
return parsed.toString();
|
|
51267
|
+
}
|
|
51268
|
+
if (parsed.pathname === SLOCK_AGENT_MANIFEST_WELL_KNOWN_PATH) {
|
|
51269
|
+
parsed.pathname = RAFT_AGENT_MANIFEST_WELL_KNOWN_PATH;
|
|
51270
|
+
return parsed.toString();
|
|
51271
|
+
}
|
|
51272
|
+
return null;
|
|
51273
|
+
}
|
|
51274
|
+
function shouldTryWellKnownAlias(err) {
|
|
51275
|
+
if (err instanceof AgentManifestFetchError) return err.status === 404 || err.status === 410;
|
|
51276
|
+
return err instanceof AgentManifestResponseFormatError;
|
|
51277
|
+
}
|
|
51278
|
+
async function fetchAgentManifestWithWellKnownAliases(url2, fetchManifestImpl = fetchAgentManifest) {
|
|
51279
|
+
try {
|
|
51280
|
+
return await fetchManifestImpl(url2);
|
|
51281
|
+
} catch (err) {
|
|
51282
|
+
if (!shouldTryWellKnownAlias(err)) throw err;
|
|
51283
|
+
const alias = wellKnownAliasUrl(url2);
|
|
51284
|
+
if (!alias) throw err;
|
|
51285
|
+
return await fetchManifestImpl(alias);
|
|
51286
|
+
}
|
|
51287
|
+
}
|
|
50053
51288
|
function sanitizePathSegment(value) {
|
|
50054
51289
|
const segment = value.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
50055
51290
|
return segment || "service";
|
|
50056
51291
|
}
|
|
50057
|
-
function resolveSlockHome(env) {
|
|
50058
|
-
|
|
50059
|
-
|
|
51292
|
+
function resolveSlockHome(env, homeDir = os4.homedir()) {
|
|
51293
|
+
const configured = env.SLOCK_HOME?.trim() || env.RAFT_HOME?.trim();
|
|
51294
|
+
const raw = configured && configured.length > 0 ? configured : path8.join(homeDir, ".slock");
|
|
51295
|
+
return path8.resolve(expandHome(raw, homeDir));
|
|
51296
|
+
}
|
|
51297
|
+
function expandHome(input, homeDir) {
|
|
51298
|
+
if (input === "~") return homeDir;
|
|
51299
|
+
if (input.startsWith("~/")) return path8.join(homeDir, input.slice(2));
|
|
51300
|
+
return input;
|
|
50060
51301
|
}
|
|
50061
51302
|
function buildLocalCliProfileEnv(input) {
|
|
50062
51303
|
if (input.manifest.execution.mode !== "local_cli" || !input.manifest.execution.command) {
|
|
@@ -50068,7 +51309,7 @@ function buildLocalCliProfileEnv(input) {
|
|
|
50068
51309
|
if (input.manifest.credential_boundary.forbid_user_home !== true) {
|
|
50069
51310
|
throw new Error("manifest must set credential_boundary.forbid_user_home=true for local_cli isolation");
|
|
50070
51311
|
}
|
|
50071
|
-
const root = resolveSlockHome(input.env ?? process.env);
|
|
51312
|
+
const root = resolveSlockHome(input.env ?? process.env, input.homeDir);
|
|
50072
51313
|
const profileHome = path8.join(
|
|
50073
51314
|
root,
|
|
50074
51315
|
"integration-profiles",
|
|
@@ -50120,7 +51361,10 @@ function findService(data, service) {
|
|
|
50120
51361
|
}
|
|
50121
51362
|
function describeNoLocalEnv(manifest) {
|
|
50122
51363
|
if (manifest.execution.mode !== "local_cli") {
|
|
50123
|
-
|
|
51364
|
+
if (manifest.actions && manifest.actions.length > 0) {
|
|
51365
|
+
return "manifest exposes HTTP API actions; no local CLI env is required";
|
|
51366
|
+
}
|
|
51367
|
+
return "manifest execution mode is http_api; no local CLI env is required";
|
|
50124
51368
|
}
|
|
50125
51369
|
if (!manifest.credential_boundary) {
|
|
50126
51370
|
return "manifest does not request a Slock-managed local environment";
|
|
@@ -50165,7 +51409,7 @@ async function resolveIntegrationEnv(input) {
|
|
|
50165
51409
|
message: describeMissingManifest({ service: input.service })
|
|
50166
51410
|
};
|
|
50167
51411
|
}
|
|
50168
|
-
const fetchManifestImpl = input.fetchManifest ?? fetchAgentManifest;
|
|
51412
|
+
const fetchManifestImpl = input.fetchManifest ?? (isInferredWellKnownManifest(input.service) ? fetchAgentManifestWithWellKnownAliases : fetchAgentManifest);
|
|
50169
51413
|
let manifest;
|
|
50170
51414
|
try {
|
|
50171
51415
|
manifest = await fetchManifestImpl(input.service.agentManifestUrl);
|
|
@@ -50204,13 +51448,19 @@ async function resolveIntegrationEnv(input) {
|
|
|
50204
51448
|
}
|
|
50205
51449
|
}
|
|
50206
51450
|
function formatNoLocalEnv(input) {
|
|
50207
|
-
|
|
51451
|
+
const lines = [
|
|
50208
51452
|
`# Slock integration profile for ${input.service}`,
|
|
50209
51453
|
input.manifestUrl ? `# manifest: ${input.manifestUrl}` : "# manifest: none declared",
|
|
50210
51454
|
"# No local CLI environment exports are required for this service.",
|
|
50211
|
-
`# ${input.message}
|
|
50212
|
-
|
|
50213
|
-
|
|
51455
|
+
`# ${input.message}`
|
|
51456
|
+
];
|
|
51457
|
+
if (input.actions && input.actions.length > 0) {
|
|
51458
|
+
lines.push(`# API actions: ${input.actions.join(", ")}`);
|
|
51459
|
+
lines.push(`# list actions: raft integration invoke --service ${JSON.stringify(input.service)} --list-actions`);
|
|
51460
|
+
lines.push(`# invoke action: raft integration invoke --service ${JSON.stringify(input.service)} --action <name>`);
|
|
51461
|
+
}
|
|
51462
|
+
lines.push("# Slock did not set HOME/XDG exports and did not execute manifest commands.");
|
|
51463
|
+
return lines.join("\n");
|
|
50214
51464
|
}
|
|
50215
51465
|
var integrationEnvCommand = defineCommand(
|
|
50216
51466
|
{
|
|
@@ -50254,6 +51504,7 @@ var integrationEnvCommand = defineCommand(
|
|
|
50254
51504
|
manifestUrl: resolution.manifestUrl,
|
|
50255
51505
|
requiresLocalEnv: false,
|
|
50256
51506
|
command: resolution.manifest?.execution.command ?? null,
|
|
51507
|
+
actions: resolution.manifest?.actions?.map((action) => action.name) ?? [],
|
|
50257
51508
|
env: {},
|
|
50258
51509
|
message: resolution.message
|
|
50259
51510
|
}
|
|
@@ -50263,7 +51514,8 @@ var integrationEnvCommand = defineCommand(
|
|
|
50263
51514
|
writeText(cmdCtx.io, `${formatNoLocalEnv({
|
|
50264
51515
|
service: resolution.service.clientId,
|
|
50265
51516
|
manifestUrl: resolution.manifestUrl,
|
|
50266
|
-
message: resolution.message
|
|
51517
|
+
message: resolution.message,
|
|
51518
|
+
actions: resolution.manifest?.actions?.map((action) => action.name) ?? []
|
|
50267
51519
|
})}
|
|
50268
51520
|
`);
|
|
50269
51521
|
return;
|
|
@@ -50290,6 +51542,16 @@ function registerIntegrationEnvCommand(parent, runtimeOptions = {}) {
|
|
|
50290
51542
|
registerCliCommand(parent, integrationEnvCommand, runtimeOptions);
|
|
50291
51543
|
}
|
|
50292
51544
|
init_esm_shims();
|
|
51545
|
+
function normalizeService2(value) {
|
|
51546
|
+
return value.trim().toLowerCase();
|
|
51547
|
+
}
|
|
51548
|
+
function findService2(data, service) {
|
|
51549
|
+
const normalized = normalizeService2(service);
|
|
51550
|
+
if (!normalized) return null;
|
|
51551
|
+
return data.services.find(
|
|
51552
|
+
(candidate) => candidate.id === service || normalizeService2(candidate.clientId) === normalized || normalizeService2(candidate.name) === normalized
|
|
51553
|
+
) ?? null;
|
|
51554
|
+
}
|
|
50293
51555
|
function normalizeScopes2(raw) {
|
|
50294
51556
|
if (!raw || raw.length === 0) return void 0;
|
|
50295
51557
|
const scopes = Array.from(new Set(
|
|
@@ -50300,6 +51562,341 @@ function normalizeScopes2(raw) {
|
|
|
50300
51562
|
}
|
|
50301
51563
|
return scopes;
|
|
50302
51564
|
}
|
|
51565
|
+
function parseHandlerArgs(serviceArgOrOpts, actionArgOrOpts, maybeOpts) {
|
|
51566
|
+
if (typeof serviceArgOrOpts === "object" && serviceArgOrOpts !== null) {
|
|
51567
|
+
return { opts: serviceArgOrOpts };
|
|
51568
|
+
}
|
|
51569
|
+
if (typeof actionArgOrOpts === "object" && actionArgOrOpts !== null) {
|
|
51570
|
+
return { serviceArg: serviceArgOrOpts, opts: actionArgOrOpts };
|
|
51571
|
+
}
|
|
51572
|
+
return { serviceArg: serviceArgOrOpts, actionArg: actionArgOrOpts, opts: maybeOpts ?? {} };
|
|
51573
|
+
}
|
|
51574
|
+
function readTextReference(value) {
|
|
51575
|
+
if (!value.startsWith("@")) return value;
|
|
51576
|
+
const path9 = value.slice(1);
|
|
51577
|
+
if (!path9) throw cliError("INVALID_ARG", "@ file references must include a path");
|
|
51578
|
+
if (path9 === "-") return fs6.readFileSync(0, "utf8");
|
|
51579
|
+
return fs6.readFileSync(path9, "utf8");
|
|
51580
|
+
}
|
|
51581
|
+
function parseJsonObject(raw, label) {
|
|
51582
|
+
let parsed;
|
|
51583
|
+
try {
|
|
51584
|
+
parsed = JSON.parse(raw);
|
|
51585
|
+
} catch (err) {
|
|
51586
|
+
throw cliError("INVALID_ARG", `${label} is not valid JSON: ${err.message}`);
|
|
51587
|
+
}
|
|
51588
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
51589
|
+
throw cliError("INVALID_ARG", `${label} must be a JSON object`);
|
|
51590
|
+
}
|
|
51591
|
+
return parsed;
|
|
51592
|
+
}
|
|
51593
|
+
function parseActionPayload(opts) {
|
|
51594
|
+
if (opts.dataJson && opts.dataFile) {
|
|
51595
|
+
throw cliError("INVALID_ARG", "use only one of --data-json or --data-file");
|
|
51596
|
+
}
|
|
51597
|
+
const payload = {};
|
|
51598
|
+
if (opts.dataJson) {
|
|
51599
|
+
Object.assign(payload, parseJsonObject(opts.dataJson, "--data-json"));
|
|
51600
|
+
}
|
|
51601
|
+
if (opts.dataFile) {
|
|
51602
|
+
const raw = opts.dataFile === "-" ? fs6.readFileSync(0, "utf8") : fs6.readFileSync(opts.dataFile, "utf8");
|
|
51603
|
+
Object.assign(payload, parseJsonObject(raw, "--data-file"));
|
|
51604
|
+
}
|
|
51605
|
+
for (const rawParam of opts.param ?? []) {
|
|
51606
|
+
const separator = rawParam.indexOf("=");
|
|
51607
|
+
if (separator <= 0) {
|
|
51608
|
+
throw cliError("INVALID_ARG", "--param values must use key=value");
|
|
51609
|
+
}
|
|
51610
|
+
const key = rawParam.slice(0, separator).trim();
|
|
51611
|
+
if (!key) throw cliError("INVALID_ARG", "--param keys must not be empty");
|
|
51612
|
+
payload[key] = readTextReference(rawParam.slice(separator + 1));
|
|
51613
|
+
}
|
|
51614
|
+
return payload;
|
|
51615
|
+
}
|
|
51616
|
+
function validateRequiredParams(action, payload) {
|
|
51617
|
+
for (const [name, spec] of Object.entries(action.parameters ?? {})) {
|
|
51618
|
+
if (!spec.required) continue;
|
|
51619
|
+
if (payload[name] === void 0 || payload[name] === null || payload[name] === "") {
|
|
51620
|
+
throw cliError("INVALID_ARG", `missing required parameter ${name}`);
|
|
51621
|
+
}
|
|
51622
|
+
}
|
|
51623
|
+
}
|
|
51624
|
+
function safeUrl(value, label) {
|
|
51625
|
+
let url2;
|
|
51626
|
+
try {
|
|
51627
|
+
url2 = new URL(value);
|
|
51628
|
+
} catch {
|
|
51629
|
+
throw cliError("INVALID_ARG", `${label} must be a valid URL`);
|
|
51630
|
+
}
|
|
51631
|
+
if (url2.protocol !== "https:" && url2.protocol !== "http:") {
|
|
51632
|
+
throw cliError("INVALID_ARG", `${label} must use http or https`);
|
|
51633
|
+
}
|
|
51634
|
+
if (url2.username || url2.password) {
|
|
51635
|
+
throw cliError("INVALID_ARG", `${label} must not include credentials`);
|
|
51636
|
+
}
|
|
51637
|
+
return url2;
|
|
51638
|
+
}
|
|
51639
|
+
function resolveActionUrl(input) {
|
|
51640
|
+
const base = input.manifest.execution.base_url ?? input.manifest.app_origin ?? input.service.homepageUrl ?? (input.service.returnUrl ? safeUrl(input.service.returnUrl, "service return URL").origin : null);
|
|
51641
|
+
if (!base) {
|
|
51642
|
+
throw cliError(
|
|
51643
|
+
"INVALID_ARG",
|
|
51644
|
+
"manifest must provide execution.base_url or app_origin, or the service must provide a homepage/return URL"
|
|
51645
|
+
);
|
|
51646
|
+
}
|
|
51647
|
+
const baseUrl = safeUrl(base, "action base URL");
|
|
51648
|
+
return new URL(input.action.endpoint.path, baseUrl);
|
|
51649
|
+
}
|
|
51650
|
+
function cookieHeaderFromSetCookie(headers) {
|
|
51651
|
+
const getSetCookie = headers.getSetCookie;
|
|
51652
|
+
const values = typeof getSetCookie === "function" ? getSetCookie.call(headers) : [headers.get("set-cookie")].filter((value) => Boolean(value));
|
|
51653
|
+
const cookies = values.map((value) => value.split(";")[0]?.trim()).filter((value) => Boolean(value));
|
|
51654
|
+
return cookies.length > 0 ? cookies.join("; ") : null;
|
|
51655
|
+
}
|
|
51656
|
+
async function establishServiceSession(input) {
|
|
51657
|
+
const callbackUrl = buildAgentCallbackHandoffUrl(input.service.returnUrl, input.login.requestId);
|
|
51658
|
+
if (!callbackUrl) {
|
|
51659
|
+
throw cliError("INTEGRATION_INVOKE_FAILED", "service return URL cannot be used for Agent Login callback handoff");
|
|
51660
|
+
}
|
|
51661
|
+
const response = await fetch(callbackUrl, {
|
|
51662
|
+
method: "GET",
|
|
51663
|
+
redirect: "manual",
|
|
51664
|
+
headers: { accept: "text/html,application/json" }
|
|
51665
|
+
});
|
|
51666
|
+
if (response.status < 200 || response.status >= 400) {
|
|
51667
|
+
throw cliError("INTEGRATION_INVOKE_FAILED", `service callback handoff failed with HTTP ${response.status}`);
|
|
51668
|
+
}
|
|
51669
|
+
const cookie = cookieHeaderFromSetCookie(response.headers);
|
|
51670
|
+
if (!cookie) {
|
|
51671
|
+
throw cliError(
|
|
51672
|
+
"INTEGRATION_INVOKE_FAILED",
|
|
51673
|
+
"service callback handoff did not set a session cookie; the service may not support stateless Agent Login API actions yet"
|
|
51674
|
+
);
|
|
51675
|
+
}
|
|
51676
|
+
return cookie;
|
|
51677
|
+
}
|
|
51678
|
+
function appendPayloadAsQuery(url2, payload) {
|
|
51679
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
51680
|
+
if (value === void 0 || value === null) continue;
|
|
51681
|
+
url2.searchParams.set(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
51682
|
+
}
|
|
51683
|
+
}
|
|
51684
|
+
async function invokeHttpAction(input) {
|
|
51685
|
+
const url2 = new URL(input.url);
|
|
51686
|
+
const headers = {
|
|
51687
|
+
accept: "application/json,text/plain,*/*",
|
|
51688
|
+
cookie: input.cookie
|
|
51689
|
+
};
|
|
51690
|
+
const init = {
|
|
51691
|
+
method: input.action.endpoint.method,
|
|
51692
|
+
headers,
|
|
51693
|
+
redirect: "follow"
|
|
51694
|
+
};
|
|
51695
|
+
if (input.action.endpoint.method === "GET") {
|
|
51696
|
+
appendPayloadAsQuery(url2, input.payload);
|
|
51697
|
+
} else {
|
|
51698
|
+
headers["content-type"] = "application/json";
|
|
51699
|
+
init.body = JSON.stringify(input.payload);
|
|
51700
|
+
}
|
|
51701
|
+
const response = await fetch(url2, init);
|
|
51702
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
51703
|
+
if (contentType.includes("application/json")) {
|
|
51704
|
+
const value2 = await response.json().catch(() => {
|
|
51705
|
+
throw cliError("INVALID_JSON_RESPONSE", `service action returned invalid JSON (HTTP ${response.status})`);
|
|
51706
|
+
});
|
|
51707
|
+
if (!response.ok) {
|
|
51708
|
+
const message = value2 && typeof value2 === "object" && "error" in value2 ? String(value2.error) : `service action failed with HTTP ${response.status}`;
|
|
51709
|
+
throw cliError("INTEGRATION_INVOKE_FAILED", message);
|
|
51710
|
+
}
|
|
51711
|
+
return { kind: "json", status: response.status, value: value2 };
|
|
51712
|
+
}
|
|
51713
|
+
const value = await response.text();
|
|
51714
|
+
if (!response.ok) {
|
|
51715
|
+
throw cliError("INTEGRATION_INVOKE_FAILED", value || `service action failed with HTTP ${response.status}`);
|
|
51716
|
+
}
|
|
51717
|
+
return { kind: "text", status: response.status, value };
|
|
51718
|
+
}
|
|
51719
|
+
function formatActions(input) {
|
|
51720
|
+
const actions = input.manifest.actions ?? [];
|
|
51721
|
+
const lines = [
|
|
51722
|
+
`Actions for ${input.service.name}`,
|
|
51723
|
+
`service: ${input.service.clientId}`,
|
|
51724
|
+
`manifest: ${input.manifestUrl}`
|
|
51725
|
+
];
|
|
51726
|
+
if (actions.length === 0) {
|
|
51727
|
+
lines.push("- none");
|
|
51728
|
+
return lines.join("\n");
|
|
51729
|
+
}
|
|
51730
|
+
for (const action of actions) {
|
|
51731
|
+
const required2 = Object.entries(action.parameters ?? {}).filter(([, param]) => param.required).map(([name]) => name);
|
|
51732
|
+
lines.push(`- ${action.name}`);
|
|
51733
|
+
lines.push(` endpoint: ${action.endpoint.method} ${action.endpoint.path}`);
|
|
51734
|
+
if (action.description) lines.push(` description: ${action.description}`);
|
|
51735
|
+
if (required2.length > 0) lines.push(` required params: ${required2.join(", ")}`);
|
|
51736
|
+
}
|
|
51737
|
+
lines.push(`next: raft integration invoke --service ${JSON.stringify(input.service.clientId)} --action ${JSON.stringify(actions[0]?.name ?? "<name>")}`);
|
|
51738
|
+
return lines.join("\n");
|
|
51739
|
+
}
|
|
51740
|
+
function pickViewerUrl(value) {
|
|
51741
|
+
return value && typeof value === "object" && typeof value.viewerUrl === "string" ? value.viewerUrl : null;
|
|
51742
|
+
}
|
|
51743
|
+
function formatActionResult(input) {
|
|
51744
|
+
const lines = [
|
|
51745
|
+
`Action invoked: ${input.action.name}`,
|
|
51746
|
+
`service: ${input.service.clientId}`,
|
|
51747
|
+
`status: HTTP ${input.result.status}`
|
|
51748
|
+
];
|
|
51749
|
+
if (input.result.kind === "json") {
|
|
51750
|
+
const viewerUrl = pickViewerUrl(input.result.value);
|
|
51751
|
+
if (viewerUrl) lines.push(`viewer URL: ${viewerUrl}`);
|
|
51752
|
+
lines.push("result:");
|
|
51753
|
+
lines.push(JSON.stringify(input.result.value, null, 2));
|
|
51754
|
+
} else if (input.result.value) {
|
|
51755
|
+
lines.push("result:");
|
|
51756
|
+
lines.push(input.result.value);
|
|
51757
|
+
}
|
|
51758
|
+
return lines.join("\n");
|
|
51759
|
+
}
|
|
51760
|
+
async function fetchManifestForInvoke(service) {
|
|
51761
|
+
if (!service.agentManifestUrl) {
|
|
51762
|
+
throw cliError("INTEGRATION_MANIFEST_MISSING", `${service.name} does not expose an agent behavior manifest`);
|
|
51763
|
+
}
|
|
51764
|
+
try {
|
|
51765
|
+
const fetchManifest = service.agentManifestUrlSource === "well_known" ? fetchAgentManifestWithWellKnownAliases : fetchAgentManifest;
|
|
51766
|
+
return await fetchManifest(service.agentManifestUrl);
|
|
51767
|
+
} catch (err) {
|
|
51768
|
+
if (err instanceof AgentManifestFetchError && (err.status === 404 || err.status === 410)) {
|
|
51769
|
+
throw cliError("INTEGRATION_MANIFEST_MISSING", "agent behavior manifest was not found", { cause: err });
|
|
51770
|
+
}
|
|
51771
|
+
if (err instanceof AgentManifestResponseFormatError) {
|
|
51772
|
+
throw cliError("INTEGRATION_MANIFEST_INVALID", err.message, { cause: err });
|
|
51773
|
+
}
|
|
51774
|
+
throw cliError("INTEGRATION_MANIFEST_INVALID", err.message, { cause: err });
|
|
51775
|
+
}
|
|
51776
|
+
}
|
|
51777
|
+
var integrationInvokeCommand = defineCommand(
|
|
51778
|
+
{
|
|
51779
|
+
name: "invoke",
|
|
51780
|
+
description: "Invoke a manifest-backed HTTP API action for a registered integration",
|
|
51781
|
+
arguments: ["[service]", "[action]"],
|
|
51782
|
+
options: [
|
|
51783
|
+
{ flags: "--service <id>", description: "Registered service id, client id, or exact service name" },
|
|
51784
|
+
{ flags: "--action <name>", description: "Manifest action name to invoke" },
|
|
51785
|
+
{ flags: "--list-actions", description: "List manifest actions instead of invoking one" },
|
|
51786
|
+
{
|
|
51787
|
+
flags: "--param <key=value>",
|
|
51788
|
+
description: "Action parameter; repeatable. Use key=@file or key=@- to read text",
|
|
51789
|
+
parse: (value, previous = []) => {
|
|
51790
|
+
previous.push(value);
|
|
51791
|
+
return previous;
|
|
51792
|
+
}
|
|
51793
|
+
},
|
|
51794
|
+
{ flags: "--data-json <json>", description: "JSON object request body for the action" },
|
|
51795
|
+
{ flags: "--data-file <path>", description: "JSON object request body file, or - for stdin" },
|
|
51796
|
+
{
|
|
51797
|
+
flags: "--scope <scope>",
|
|
51798
|
+
description: "Login scope to request before invoking; can be repeated or comma-separated",
|
|
51799
|
+
parse: (value, previous = []) => {
|
|
51800
|
+
previous.push(value);
|
|
51801
|
+
return previous;
|
|
51802
|
+
}
|
|
51803
|
+
},
|
|
51804
|
+
{ flags: "--target <target>", description: "Conversation target to post a human approval card when approval is required" },
|
|
51805
|
+
{ flags: "--json", description: "Emit machine-readable JSON" }
|
|
51806
|
+
]
|
|
51807
|
+
},
|
|
51808
|
+
async (cmdCtx, serviceArgOrOpts, actionArgOrOpts, maybeOpts) => {
|
|
51809
|
+
const { serviceArg, actionArg, opts } = parseHandlerArgs(serviceArgOrOpts, actionArgOrOpts, maybeOpts);
|
|
51810
|
+
const serviceQuery = (opts.service ?? serviceArg ?? "").trim();
|
|
51811
|
+
const actionName = (opts.action ?? actionArg ?? "").trim();
|
|
51812
|
+
if (!serviceQuery) throw cliError("INVALID_ARG", "--service or service argument is required");
|
|
51813
|
+
if (!opts.listActions && !actionName) throw cliError("INVALID_ARG", "--action or action argument is required");
|
|
51814
|
+
const agentContext = cmdCtx.loadAgentContext();
|
|
51815
|
+
const client = cmdCtx.createApiClient(agentContext);
|
|
51816
|
+
const api = createAgentApiSurfaceClient(client);
|
|
51817
|
+
const listRes = await api.integrations.list();
|
|
51818
|
+
if (!listRes.ok || !listRes.data) {
|
|
51819
|
+
const code = listRes.status >= 500 ? "SERVER_5XX" : "INTEGRATION_LIST_FAILED";
|
|
51820
|
+
throw cliError(code, listRes.error ?? `HTTP ${listRes.status}`);
|
|
51821
|
+
}
|
|
51822
|
+
const service = findService2(listRes.data, serviceQuery);
|
|
51823
|
+
if (!service) {
|
|
51824
|
+
throw cliError("INTEGRATION_NOT_FOUND", `No registered integration matched ${serviceQuery}`);
|
|
51825
|
+
}
|
|
51826
|
+
const manifest = await fetchManifestForInvoke(service);
|
|
51827
|
+
if (manifest.execution.mode !== "http_api") {
|
|
51828
|
+
throw cliError("INTEGRATION_MANIFEST_UNSUPPORTED", "manifest execution mode is not http_api");
|
|
51829
|
+
}
|
|
51830
|
+
if (opts.listActions) {
|
|
51831
|
+
if (opts.json) {
|
|
51832
|
+
writeJson(cmdCtx.io, {
|
|
51833
|
+
ok: true,
|
|
51834
|
+
data: {
|
|
51835
|
+
service: service.clientId,
|
|
51836
|
+
manifestUrl: service.agentManifestUrl,
|
|
51837
|
+
actions: manifest.actions ?? []
|
|
51838
|
+
}
|
|
51839
|
+
});
|
|
51840
|
+
return;
|
|
51841
|
+
}
|
|
51842
|
+
writeText(cmdCtx.io, `${formatActions({ service, manifestUrl: service.agentManifestUrl ?? "-", manifest })}
|
|
51843
|
+
`);
|
|
51844
|
+
return;
|
|
51845
|
+
}
|
|
51846
|
+
const action = (manifest.actions ?? []).find((candidate) => candidate.name === actionName);
|
|
51847
|
+
if (!action) throw cliError("INVALID_ARG", `manifest does not define action ${actionName}`);
|
|
51848
|
+
const payload = parseActionPayload(opts);
|
|
51849
|
+
validateRequiredParams(action, payload);
|
|
51850
|
+
const scopes = normalizeScopes2(opts.scope);
|
|
51851
|
+
const loginRes = await api.integrations.login({
|
|
51852
|
+
service: service.clientId,
|
|
51853
|
+
scopes,
|
|
51854
|
+
target: opts.target?.trim() || void 0
|
|
51855
|
+
});
|
|
51856
|
+
if (!loginRes.ok || !loginRes.data) {
|
|
51857
|
+
const code = loginRes.status >= 500 ? "SERVER_5XX" : "INTEGRATION_LOGIN_FAILED";
|
|
51858
|
+
throw cliError(code, loginRes.error ?? `HTTP ${loginRes.status}`);
|
|
51859
|
+
}
|
|
51860
|
+
if (loginRes.data.status === "approval_required") {
|
|
51861
|
+
throw cliError(
|
|
51862
|
+
"INTEGRATION_APPROVAL_REQUIRED",
|
|
51863
|
+
"human approval is required before invoking this integration action",
|
|
51864
|
+
{ suggestedNextAction: "Ask a server owner/admin to approve the integration login request, then rerun the command." }
|
|
51865
|
+
);
|
|
51866
|
+
}
|
|
51867
|
+
const cookie = await establishServiceSession({ login: loginRes.data, service });
|
|
51868
|
+
const url2 = resolveActionUrl({ service, manifest, action });
|
|
51869
|
+
const result2 = await invokeHttpAction({ url: url2, action, payload, cookie });
|
|
51870
|
+
if (opts.json) {
|
|
51871
|
+
writeJson(cmdCtx.io, {
|
|
51872
|
+
ok: true,
|
|
51873
|
+
data: {
|
|
51874
|
+
service: service.clientId,
|
|
51875
|
+
action: action.name,
|
|
51876
|
+
status: result2.status,
|
|
51877
|
+
result: result2.value
|
|
51878
|
+
}
|
|
51879
|
+
});
|
|
51880
|
+
return;
|
|
51881
|
+
}
|
|
51882
|
+
writeText(cmdCtx.io, `${formatActionResult({ service, action, result: result2 })}
|
|
51883
|
+
`);
|
|
51884
|
+
}
|
|
51885
|
+
);
|
|
51886
|
+
function registerIntegrationInvokeCommand(parent, runtimeOptions = {}) {
|
|
51887
|
+
registerCliCommand(parent, integrationInvokeCommand, runtimeOptions);
|
|
51888
|
+
}
|
|
51889
|
+
init_esm_shims();
|
|
51890
|
+
function normalizeScopes3(raw) {
|
|
51891
|
+
if (!raw || raw.length === 0) return void 0;
|
|
51892
|
+
const scopes = Array.from(new Set(
|
|
51893
|
+
raw.flatMap((value) => value.split(",")).map((value) => value.trim()).filter(Boolean)
|
|
51894
|
+
)).sort();
|
|
51895
|
+
if (scopes.length === 0) {
|
|
51896
|
+
throw cliError("INVALID_ARG", "--scope must include at least one non-empty scope");
|
|
51897
|
+
}
|
|
51898
|
+
return scopes;
|
|
51899
|
+
}
|
|
50303
51900
|
function requiredTrimmed(value, flag) {
|
|
50304
51901
|
const trimmed = value?.trim() ?? "";
|
|
50305
51902
|
if (!trimmed) throw cliError("INVALID_ARG", `${flag} is required`);
|
|
@@ -50328,7 +51925,7 @@ function formatAppPrepare(data) {
|
|
|
50328
51925
|
async function prepareApp(mode, ctx, opts) {
|
|
50329
51926
|
const target = requiredTrimmed(opts.target, "--target");
|
|
50330
51927
|
const clientKey = requiredTrimmed(opts.clientKey, "--client-key");
|
|
50331
|
-
const scopes =
|
|
51928
|
+
const scopes = normalizeScopes3([...opts.scope ?? [], ...opts.scopes ?? []]);
|
|
50332
51929
|
const agentContext = ctx.loadAgentContext();
|
|
50333
51930
|
const client = ctx.createApiClient(agentContext);
|
|
50334
51931
|
const body = {
|
|
@@ -50359,6 +51956,40 @@ async function prepareApp(mode, ctx, opts) {
|
|
|
50359
51956
|
writeText(ctx.io, `${formatAppPrepare(res.data)}
|
|
50360
51957
|
`);
|
|
50361
51958
|
}
|
|
51959
|
+
function formatAppRotateSecret(data) {
|
|
51960
|
+
return [
|
|
51961
|
+
`Integration app secret regenerated for ${data.clientName} (${data.clientKey})`,
|
|
51962
|
+
`client secret: ${data.clientSecret}`,
|
|
51963
|
+
"shown once \u2014 store it now; regenerating again invalidates the previous secret"
|
|
51964
|
+
].join("\n");
|
|
51965
|
+
}
|
|
51966
|
+
async function rotateAppSecret(ctx, opts) {
|
|
51967
|
+
const clientKey = requiredTrimmed(opts.client, "--client");
|
|
51968
|
+
const agentContext = ctx.loadAgentContext();
|
|
51969
|
+
const client = ctx.createApiClient(agentContext);
|
|
51970
|
+
const res = await createAgentApiSurfaceClient(client).integrations.rotateAppSecret({ clientKey });
|
|
51971
|
+
if (!res.ok || !res.data) {
|
|
51972
|
+
const code = res.status >= 500 ? "SERVER_5XX" : "INTEGRATION_APP_ROTATE_SECRET_FAILED";
|
|
51973
|
+
throw cliError(code, res.error ?? `HTTP ${res.status}`);
|
|
51974
|
+
}
|
|
51975
|
+
if (opts.json) {
|
|
51976
|
+
writeJson(ctx.io, { ok: true, data: res.data });
|
|
51977
|
+
return;
|
|
51978
|
+
}
|
|
51979
|
+
writeText(ctx.io, `${formatAppRotateSecret(res.data)}
|
|
51980
|
+
`);
|
|
51981
|
+
}
|
|
51982
|
+
var integrationAppRotateSecretCommand = defineCommand(
|
|
51983
|
+
{
|
|
51984
|
+
name: "rotate-secret",
|
|
51985
|
+
description: "Regenerate the one-time client secret for a server-local app you registered (invalidates the previous secret)",
|
|
51986
|
+
options: [
|
|
51987
|
+
{ flags: "--client <key>", description: "App client key / OAuth client_id you registered" },
|
|
51988
|
+
{ flags: "--json", description: "Emit machine-readable JSON" }
|
|
51989
|
+
]
|
|
51990
|
+
},
|
|
51991
|
+
async (ctx, opts) => rotateAppSecret(ctx, opts)
|
|
51992
|
+
);
|
|
50362
51993
|
var sharedOptions = [
|
|
50363
51994
|
{ flags: "--client-key <key>", description: "Stable app client key / OAuth client_id to reserve or update" },
|
|
50364
51995
|
{ flags: "--name <name>", description: "App display name" },
|
|
@@ -50408,6 +52039,7 @@ function registerIntegrationAppCommands(parent, runtimeOptions = {}) {
|
|
|
50408
52039
|
const prepareCmd = appCmd.command("prepare").description("Prepare app registration/update action cards");
|
|
50409
52040
|
registerCliCommand(prepareCmd, integrationAppPrepareRegisterCommand, runtimeOptions);
|
|
50410
52041
|
registerCliCommand(prepareCmd, integrationAppPrepareUpdateCommand, runtimeOptions);
|
|
52042
|
+
registerCliCommand(appCmd, integrationAppRotateSecretCommand, runtimeOptions);
|
|
50411
52043
|
}
|
|
50412
52044
|
init_esm_shims();
|
|
50413
52045
|
init_esm_shims();
|
|
@@ -50800,6 +52432,10 @@ registerAgentListCommand(agentCmd);
|
|
|
50800
52432
|
registerAgentBridgeCommand(agentCmd);
|
|
50801
52433
|
var channelCmd = program2.command("channel").description("Channel membership and attention operations");
|
|
50802
52434
|
registerChannelMembersCommand(channelCmd);
|
|
52435
|
+
registerChannelCreateCommand(channelCmd);
|
|
52436
|
+
registerChannelUpdateCommand(channelCmd);
|
|
52437
|
+
registerChannelAddMemberCommand(channelCmd);
|
|
52438
|
+
registerChannelRemoveMemberCommand(channelCmd);
|
|
50803
52439
|
registerChannelJoinCommand(channelCmd);
|
|
50804
52440
|
registerChannelLeaveCommand(channelCmd);
|
|
50805
52441
|
registerChannelMuteCommand(channelCmd);
|
|
@@ -50808,6 +52444,7 @@ var threadCmd = program2.command("thread").description("Thread attention operati
|
|
|
50808
52444
|
registerThreadUnfollowCommand(threadCmd);
|
|
50809
52445
|
var serverCmd = program2.command("server").description("Server / workspace introspection");
|
|
50810
52446
|
registerServerInfoCommand(serverCmd);
|
|
52447
|
+
registerServerUpdateCommand(serverCmd);
|
|
50811
52448
|
var manualCmd = program2.command("manual").description("Slock Manual for Agents retrieval (canonical operating topics)");
|
|
50812
52449
|
registerKnowledgeGetCommand(manualCmd);
|
|
50813
52450
|
var knowledgeCmd = program2.command("knowledge").description("Legacy alias for `raft manual`");
|
|
@@ -50840,6 +52477,7 @@ var integrationCmd = program2.command("integration").description("Third-party se
|
|
|
50840
52477
|
registerIntegrationListCommand(integrationCmd);
|
|
50841
52478
|
registerIntegrationLoginCommand(integrationCmd);
|
|
50842
52479
|
registerIntegrationEnvCommand(integrationCmd);
|
|
52480
|
+
registerIntegrationInvokeCommand(integrationCmd);
|
|
50843
52481
|
registerIntegrationAppCommands(integrationCmd);
|
|
50844
52482
|
var reminderCmd = program2.command("reminder").description("Reminder operations");
|
|
50845
52483
|
registerReminderScheduleCommand(reminderCmd);
|