@pmate/cli 0.28.8 → 0.29.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/index.d.ts +52 -1
- package/dist/index.js +653 -228
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -385,12 +385,38 @@ var init_logs_types = __esm({
|
|
|
385
385
|
});
|
|
386
386
|
|
|
387
387
|
// node_modules/.pnpm/@pmate+meta@1.1.15/node_modules/@pmate/meta/src/types/message.types.ts
|
|
388
|
-
var PING, PONG;
|
|
388
|
+
var PING, PONG, MsgOp;
|
|
389
389
|
var init_message_types = __esm({
|
|
390
390
|
"node_modules/.pnpm/@pmate+meta@1.1.15/node_modules/@pmate/meta/src/types/message.types.ts"() {
|
|
391
391
|
"use strict";
|
|
392
392
|
PING = 1;
|
|
393
393
|
PONG = 2;
|
|
394
|
+
MsgOp = /* @__PURE__ */ ((MsgOp3) => {
|
|
395
|
+
MsgOp3[MsgOp3["CHAT"] = 1] = "CHAT";
|
|
396
|
+
MsgOp3[MsgOp3["AGENT"] = 2] = "AGENT";
|
|
397
|
+
MsgOp3[MsgOp3["ACK"] = 3] = "ACK";
|
|
398
|
+
MsgOp3[MsgOp3["AUTH"] = 4] = "AUTH";
|
|
399
|
+
MsgOp3[MsgOp3["LEFT"] = 5] = "LEFT";
|
|
400
|
+
MsgOp3[MsgOp3["TEXT"] = 16] = "TEXT";
|
|
401
|
+
MsgOp3[MsgOp3["HELLO"] = 18] = "HELLO";
|
|
402
|
+
MsgOp3[MsgOp3["EMOJI"] = 19] = "EMOJI";
|
|
403
|
+
MsgOp3[MsgOp3["IMAGE"] = 20] = "IMAGE";
|
|
404
|
+
MsgOp3[MsgOp3["GROUP_NEW_PEERS"] = 24] = "GROUP_NEW_PEERS";
|
|
405
|
+
MsgOp3[MsgOp3["GROUP_REMOVE_PEERS"] = 25] = "GROUP_REMOVE_PEERS";
|
|
406
|
+
MsgOp3[MsgOp3["FRIEND_DELETE"] = 26] = "FRIEND_DELETE";
|
|
407
|
+
MsgOp3[MsgOp3["DELETE_CHAT"] = 27] = "DELETE_CHAT";
|
|
408
|
+
MsgOp3[MsgOp3["REJECT"] = 32] = "REJECT";
|
|
409
|
+
MsgOp3[MsgOp3["PIPELINE_CALL"] = 33] = "PIPELINE_CALL";
|
|
410
|
+
MsgOp3[MsgOp3["PIPELINE_ACK"] = 34] = "PIPELINE_ACK";
|
|
411
|
+
MsgOp3[MsgOp3["PIPELINE_JOIN"] = 35] = "PIPELINE_JOIN";
|
|
412
|
+
MsgOp3[MsgOp3["SYSTEM_NOTIFY"] = 36] = "SYSTEM_NOTIFY";
|
|
413
|
+
MsgOp3[MsgOp3["RECALL"] = 49] = "RECALL";
|
|
414
|
+
MsgOp3[MsgOp3["AUTH_ACK"] = 1001] = "AUTH_ACK";
|
|
415
|
+
MsgOp3[MsgOp3["AGENT_REQUEST"] = 1002] = "AGENT_REQUEST";
|
|
416
|
+
MsgOp3[MsgOp3["AGENT_RESPONSE"] = 1003] = "AGENT_RESPONSE";
|
|
417
|
+
MsgOp3[MsgOp3["LAST_POSITION"] = 8194] = "LAST_POSITION";
|
|
418
|
+
return MsgOp3;
|
|
419
|
+
})(MsgOp || {});
|
|
394
420
|
}
|
|
395
421
|
});
|
|
396
422
|
|
|
@@ -8858,52 +8884,52 @@ var init_AgentClient = __esm({
|
|
|
8858
8884
|
await this.lease.connection.authenticate(timeoutMs);
|
|
8859
8885
|
return true;
|
|
8860
8886
|
}
|
|
8861
|
-
async prompt(
|
|
8887
|
+
async prompt(request2) {
|
|
8862
8888
|
return this.runInternal({
|
|
8863
|
-
agentId:
|
|
8864
|
-
payload:
|
|
8889
|
+
agentId: request2.agentId,
|
|
8890
|
+
payload: request2.payload
|
|
8865
8891
|
});
|
|
8866
8892
|
}
|
|
8867
|
-
async promptMany(
|
|
8868
|
-
return mapWithConcurrency(
|
|
8893
|
+
async promptMany(request2) {
|
|
8894
|
+
return mapWithConcurrency(request2.requests, request2.concurrency ?? 10, (item) => this.prompt(item));
|
|
8869
8895
|
}
|
|
8870
|
-
async submitPromptBatch(
|
|
8896
|
+
async submitPromptBatch(request2) {
|
|
8871
8897
|
return requireBatchResponse(await this.runInternal({
|
|
8872
|
-
agentId:
|
|
8898
|
+
agentId: request2.agentId,
|
|
8873
8899
|
payload: {
|
|
8874
8900
|
__pmateLlmBatch: {
|
|
8875
8901
|
operation: "submit",
|
|
8876
|
-
items:
|
|
8877
|
-
metadata:
|
|
8902
|
+
items: request2.items,
|
|
8903
|
+
metadata: request2.metadata
|
|
8878
8904
|
}
|
|
8879
8905
|
}
|
|
8880
8906
|
}));
|
|
8881
8907
|
}
|
|
8882
|
-
async getPromptBatch(
|
|
8908
|
+
async getPromptBatch(request2) {
|
|
8883
8909
|
return requireBatchResponse(await this.runInternal({
|
|
8884
|
-
agentId:
|
|
8910
|
+
agentId: request2.agentId,
|
|
8885
8911
|
payload: {
|
|
8886
8912
|
__pmateLlmBatch: {
|
|
8887
8913
|
operation: "get",
|
|
8888
|
-
batchId:
|
|
8914
|
+
batchId: request2.batchId
|
|
8889
8915
|
}
|
|
8890
8916
|
}
|
|
8891
8917
|
}));
|
|
8892
8918
|
}
|
|
8893
|
-
async getPromptBatchResults(
|
|
8919
|
+
async getPromptBatchResults(request2) {
|
|
8894
8920
|
return requireBatchResponse(await this.runInternal({
|
|
8895
|
-
agentId:
|
|
8921
|
+
agentId: request2.agentId,
|
|
8896
8922
|
payload: {
|
|
8897
8923
|
__pmateLlmBatch: {
|
|
8898
8924
|
operation: "results",
|
|
8899
|
-
batchId:
|
|
8925
|
+
batchId: request2.batchId
|
|
8900
8926
|
}
|
|
8901
8927
|
}
|
|
8902
8928
|
}));
|
|
8903
8929
|
}
|
|
8904
|
-
async waitPromptBatch(
|
|
8905
|
-
const pollIntervalMs =
|
|
8906
|
-
const timeoutMs =
|
|
8930
|
+
async waitPromptBatch(request2) {
|
|
8931
|
+
const pollIntervalMs = request2.pollIntervalMs ?? 1e4;
|
|
8932
|
+
const timeoutMs = request2.timeoutMs ?? 24 * 60 * 60 * 1e3;
|
|
8907
8933
|
if (!Number.isFinite(pollIntervalMs) || pollIntervalMs < 1) {
|
|
8908
8934
|
throw new Error("pollIntervalMs must be a positive number");
|
|
8909
8935
|
}
|
|
@@ -8912,89 +8938,89 @@ var init_AgentClient = __esm({
|
|
|
8912
8938
|
}
|
|
8913
8939
|
const deadline = Date.now() + timeoutMs;
|
|
8914
8940
|
while (true) {
|
|
8915
|
-
const batch = await this.getPromptBatch(
|
|
8941
|
+
const batch = await this.getPromptBatch(request2);
|
|
8916
8942
|
if (isPromptBatchTerminal(batch.status)) {
|
|
8917
8943
|
return batch;
|
|
8918
8944
|
}
|
|
8919
8945
|
const remainingMs = deadline - Date.now();
|
|
8920
8946
|
if (remainingMs <= 0) {
|
|
8921
|
-
throw new Error(`Timed out waiting for prompt batch "${
|
|
8947
|
+
throw new Error(`Timed out waiting for prompt batch "${request2.batchId}"; the server-side batch was not cancelled`);
|
|
8922
8948
|
}
|
|
8923
8949
|
await delay(Math.min(pollIntervalMs, remainingMs));
|
|
8924
8950
|
}
|
|
8925
8951
|
}
|
|
8926
|
-
async promptBatch(
|
|
8927
|
-
const submitted = await this.submitPromptBatch(
|
|
8952
|
+
async promptBatch(request2) {
|
|
8953
|
+
const submitted = await this.submitPromptBatch(request2);
|
|
8928
8954
|
const completed = await this.waitPromptBatch({
|
|
8929
|
-
agentId:
|
|
8955
|
+
agentId: request2.agentId,
|
|
8930
8956
|
batchId: submitted.id,
|
|
8931
|
-
pollIntervalMs:
|
|
8932
|
-
timeoutMs:
|
|
8957
|
+
pollIntervalMs: request2.pollIntervalMs,
|
|
8958
|
+
timeoutMs: request2.timeoutMs
|
|
8933
8959
|
});
|
|
8934
8960
|
if (completed.status === "failed" || completed.status === "cancelled") {
|
|
8935
8961
|
throw new Error(`Prompt batch "${completed.id}" ended with status "${completed.status}"`);
|
|
8936
8962
|
}
|
|
8937
8963
|
return this.getPromptBatchResults({
|
|
8938
|
-
agentId:
|
|
8964
|
+
agentId: request2.agentId,
|
|
8939
8965
|
batchId: completed.id
|
|
8940
8966
|
});
|
|
8941
8967
|
}
|
|
8942
|
-
async cancelPromptBatch(
|
|
8968
|
+
async cancelPromptBatch(request2) {
|
|
8943
8969
|
return requireBatchResponse(await this.runInternal({
|
|
8944
|
-
agentId:
|
|
8970
|
+
agentId: request2.agentId,
|
|
8945
8971
|
payload: {
|
|
8946
8972
|
__pmateLlmBatch: {
|
|
8947
8973
|
operation: "cancel",
|
|
8948
|
-
batchId:
|
|
8974
|
+
batchId: request2.batchId
|
|
8949
8975
|
}
|
|
8950
8976
|
}
|
|
8951
8977
|
}));
|
|
8952
8978
|
}
|
|
8953
|
-
async generateImage(
|
|
8979
|
+
async generateImage(request2) {
|
|
8954
8980
|
return this.runInternal({
|
|
8955
|
-
agentId:
|
|
8956
|
-
payload:
|
|
8981
|
+
agentId: request2.agentId,
|
|
8982
|
+
payload: request2.payload
|
|
8957
8983
|
});
|
|
8958
8984
|
}
|
|
8959
|
-
async echo(
|
|
8985
|
+
async echo(request2) {
|
|
8960
8986
|
return this.runInternal({
|
|
8961
|
-
agentId:
|
|
8962
|
-
payload:
|
|
8987
|
+
agentId: request2.agentId,
|
|
8988
|
+
payload: request2.payload
|
|
8963
8989
|
});
|
|
8964
8990
|
}
|
|
8965
|
-
async runInternal(
|
|
8991
|
+
async runInternal(request2) {
|
|
8966
8992
|
this.ensureReady();
|
|
8967
|
-
const taskId = this.createTaskId(
|
|
8968
|
-
const agent = await this.agentService.getAgentById(
|
|
8993
|
+
const taskId = this.createTaskId(request2.agentId);
|
|
8994
|
+
const agent = await this.agentService.getAgentById(request2.agentId);
|
|
8969
8995
|
const hubTo = `@hub/${agent.type}`;
|
|
8970
8996
|
const { waiter } = this.tasks.createTask(taskId, {
|
|
8971
8997
|
timeoutMs: this.timeoutMs,
|
|
8972
8998
|
failMode: "reject",
|
|
8973
8999
|
onFail: (message) => {
|
|
8974
|
-
logger5.error("Agent task failed",
|
|
9000
|
+
logger5.error("Agent task failed", request2.agentId, message);
|
|
8975
9001
|
}
|
|
8976
9002
|
});
|
|
8977
9003
|
const startPayload = {
|
|
8978
9004
|
taskId,
|
|
8979
|
-
agentId:
|
|
9005
|
+
agentId: request2.agentId,
|
|
8980
9006
|
op: 0 /* Start */,
|
|
8981
9007
|
auth: this.auth,
|
|
8982
9008
|
type: this.defaultRequestType,
|
|
8983
|
-
...
|
|
9009
|
+
...request2.payload ? { payload: request2.payload } : {}
|
|
8984
9010
|
};
|
|
8985
9011
|
const msg = Msg.create(this.from, hubTo, 2 /* AGENT */, createAgentRequestBody(startPayload), 0 /* PIPELINE */);
|
|
8986
9012
|
debugLog("[agent-client] sending agent request", {
|
|
8987
9013
|
taskId,
|
|
8988
|
-
agentId:
|
|
9014
|
+
agentId: request2.agentId,
|
|
8989
9015
|
from: this.from,
|
|
8990
9016
|
to: hubTo
|
|
8991
9017
|
});
|
|
8992
9018
|
await this.lease.connection.sendMsg(msg);
|
|
8993
9019
|
return await waiter;
|
|
8994
9020
|
}
|
|
8995
|
-
stream(
|
|
9021
|
+
stream(request2) {
|
|
8996
9022
|
this.ensureReady();
|
|
8997
|
-
const taskId = this.createTaskId(
|
|
9023
|
+
const taskId = this.createTaskId(request2.agentId);
|
|
8998
9024
|
const { waiter, onProgress } = this.tasks.createTask(taskId, {
|
|
8999
9025
|
timeoutMs: this.streamTimeoutMs,
|
|
9000
9026
|
failMode: "reject",
|
|
@@ -9002,10 +9028,10 @@ var init_AgentClient = __esm({
|
|
|
9002
9028
|
});
|
|
9003
9029
|
const from = this.from;
|
|
9004
9030
|
const connection = this.lease.connection;
|
|
9005
|
-
const minChunkSizeBytes =
|
|
9006
|
-
const inputStream = minChunkSizeBytes > 0 ? AsyncStream.chunkBlob(
|
|
9031
|
+
const minChunkSizeBytes = request2.minChunkSizeBytes ?? this.minChunkSizeBytes;
|
|
9032
|
+
const inputStream = minChunkSizeBytes > 0 ? AsyncStream.chunkBlob(request2.stream, {
|
|
9007
9033
|
minBytes: minChunkSizeBytes
|
|
9008
|
-
}) :
|
|
9034
|
+
}) : request2.stream;
|
|
9009
9035
|
const outputStream = new AsyncStream();
|
|
9010
9036
|
onProgress((data) => {
|
|
9011
9037
|
outputStream.push({ type: "progress", data });
|
|
@@ -9037,22 +9063,22 @@ var init_AgentClient = __esm({
|
|
|
9037
9063
|
outputStream.error(err2);
|
|
9038
9064
|
});
|
|
9039
9065
|
const startDataStream = async () => {
|
|
9040
|
-
const agent = await this.agentService.getAgentById(
|
|
9066
|
+
const agent = await this.agentService.getAgentById(request2.agentId);
|
|
9041
9067
|
const hubTo = `@hub/${agent.type}`;
|
|
9042
9068
|
const startMsg = Msg.create(from, hubTo, 2 /* AGENT */, createAgentRequestBody({
|
|
9043
9069
|
taskId,
|
|
9044
|
-
agentId:
|
|
9070
|
+
agentId: request2.agentId,
|
|
9045
9071
|
op: 0 /* Start */,
|
|
9046
9072
|
auth: this.auth,
|
|
9047
9073
|
type: this.defaultRequestType,
|
|
9048
|
-
...
|
|
9074
|
+
...request2.params ? { payload: request2.params } : {}
|
|
9049
9075
|
}), 0 /* PIPELINE */);
|
|
9050
9076
|
await connection.sendMsg(startMsg);
|
|
9051
9077
|
for await (const payload of inputStream) {
|
|
9052
9078
|
const dataType = payload instanceof Blob ? payload.type || this.defaultBinaryType : payload instanceof Uint8Array || payload instanceof ArrayBuffer ? this.defaultBinaryType : typeof payload === "string" ? "text" : this.defaultRequestType;
|
|
9053
9079
|
const body = {
|
|
9054
9080
|
taskId,
|
|
9055
|
-
agentId:
|
|
9081
|
+
agentId: request2.agentId,
|
|
9056
9082
|
op: 1 /* Data */,
|
|
9057
9083
|
auth: this.auth,
|
|
9058
9084
|
type: dataType,
|
|
@@ -9063,7 +9089,7 @@ var init_AgentClient = __esm({
|
|
|
9063
9089
|
}
|
|
9064
9090
|
const endMsg = Msg.create(from, hubTo, 2 /* AGENT */, createAgentRequestBody({
|
|
9065
9091
|
taskId,
|
|
9066
|
-
agentId:
|
|
9092
|
+
agentId: request2.agentId,
|
|
9067
9093
|
op: 2 /* End */,
|
|
9068
9094
|
auth: this.auth,
|
|
9069
9095
|
type: this.defaultRequestType
|
|
@@ -9466,8 +9492,8 @@ __export(index_exports, {
|
|
|
9466
9492
|
parseCommandArgs: () => parseCommandArgs
|
|
9467
9493
|
});
|
|
9468
9494
|
module.exports = __toCommonJS(index_exports);
|
|
9469
|
-
var
|
|
9470
|
-
var
|
|
9495
|
+
var import_node_fs28 = require("fs");
|
|
9496
|
+
var import_node_path33 = __toESM(require("path"));
|
|
9471
9497
|
var import_chalk4 = __toESM(require("chalk"));
|
|
9472
9498
|
|
|
9473
9499
|
// src/cli.ts
|
|
@@ -10257,8 +10283,8 @@ var LoginCommandHandler = class {
|
|
|
10257
10283
|
rejectToken = reject;
|
|
10258
10284
|
});
|
|
10259
10285
|
const openSockets = /* @__PURE__ */ new Set();
|
|
10260
|
-
const server = (0, import_node_http.createServer)((
|
|
10261
|
-
this.handleCallbackRequest(
|
|
10286
|
+
const server = (0, import_node_http.createServer)((request2, response) => {
|
|
10287
|
+
this.handleCallbackRequest(request2, response, resolveToken, rejectToken);
|
|
10262
10288
|
});
|
|
10263
10289
|
server.on("connection", (socket) => {
|
|
10264
10290
|
openSockets.add(socket);
|
|
@@ -10301,8 +10327,8 @@ var LoginCommandHandler = class {
|
|
|
10301
10327
|
close
|
|
10302
10328
|
};
|
|
10303
10329
|
}
|
|
10304
|
-
handleCallbackRequest(
|
|
10305
|
-
const url = new URL(
|
|
10330
|
+
handleCallbackRequest(request2, response, resolveToken, rejectToken) {
|
|
10331
|
+
const url = new URL(request2.url || "/", "http://127.0.0.1");
|
|
10306
10332
|
if (url.pathname !== CALLBACK_PATH) {
|
|
10307
10333
|
response.statusCode = 404;
|
|
10308
10334
|
response.end("Not found");
|
|
@@ -10581,14 +10607,14 @@ var AliyunService = class {
|
|
|
10581
10607
|
regionId: userConfig.aliyun?.region?.trim() || "cn-hangzhou"
|
|
10582
10608
|
});
|
|
10583
10609
|
const client = new import_alidns20150109.default(sdkConfig);
|
|
10584
|
-
const
|
|
10610
|
+
const request2 = new import_alidns20150109.AddDomainRecordRequest({
|
|
10585
10611
|
domainName: input.domainName,
|
|
10586
10612
|
RR: input.rr,
|
|
10587
10613
|
type: input.type,
|
|
10588
10614
|
value: input.value,
|
|
10589
10615
|
TTL: input.ttl ?? 600
|
|
10590
10616
|
});
|
|
10591
|
-
await client.addDomainRecord(
|
|
10617
|
+
await client.addDomainRecord(request2);
|
|
10592
10618
|
}
|
|
10593
10619
|
/** Get existing CNAME record value for an RR, if any. */
|
|
10594
10620
|
static async getCnameRecordValue(domainName, rr) {
|
|
@@ -10603,14 +10629,14 @@ var AliyunService = class {
|
|
|
10603
10629
|
regionId: userConfig.aliyun?.region?.trim() || "cn-hangzhou"
|
|
10604
10630
|
});
|
|
10605
10631
|
const client = new import_alidns20150109.default(sdkConfig);
|
|
10606
|
-
const
|
|
10632
|
+
const request2 = new import_alidns20150109.DescribeDomainRecordsRequest({
|
|
10607
10633
|
domainName,
|
|
10608
10634
|
RRKeyWord: rr,
|
|
10609
10635
|
type: "CNAME",
|
|
10610
10636
|
searchMode: "ADVANCED",
|
|
10611
10637
|
pageSize: 500
|
|
10612
10638
|
});
|
|
10613
|
-
const response = await client.describeDomainRecords(
|
|
10639
|
+
const response = await client.describeDomainRecords(request2);
|
|
10614
10640
|
const records = response.body?.domainRecords?.record ?? [];
|
|
10615
10641
|
const normalizedRr = rr.toLowerCase();
|
|
10616
10642
|
const match = records.find(
|
|
@@ -10631,14 +10657,14 @@ var AliyunService = class {
|
|
|
10631
10657
|
regionId: userConfig.aliyun?.region?.trim() || "cn-hangzhou"
|
|
10632
10658
|
});
|
|
10633
10659
|
const client = new import_alidns20150109.default(sdkConfig);
|
|
10634
|
-
const
|
|
10660
|
+
const request2 = new import_alidns20150109.DescribeDomainRecordsRequest({
|
|
10635
10661
|
domainName,
|
|
10636
10662
|
RRKeyWord: rr,
|
|
10637
10663
|
type: "A",
|
|
10638
10664
|
searchMode: "ADVANCED",
|
|
10639
10665
|
pageSize: 500
|
|
10640
10666
|
});
|
|
10641
|
-
const response = await client.describeDomainRecords(
|
|
10667
|
+
const response = await client.describeDomainRecords(request2);
|
|
10642
10668
|
const records = response.body?.domainRecords?.record ?? [];
|
|
10643
10669
|
const normalizedRr = rr.toLowerCase();
|
|
10644
10670
|
const match = records.find(
|
|
@@ -10659,14 +10685,14 @@ var AliyunService = class {
|
|
|
10659
10685
|
regionId: userConfig.aliyun?.region?.trim() || "cn-hangzhou"
|
|
10660
10686
|
});
|
|
10661
10687
|
const client = new import_alidns20150109.default(sdkConfig);
|
|
10662
|
-
const
|
|
10688
|
+
const request2 = new import_alidns20150109.DescribeDomainRecordsRequest({
|
|
10663
10689
|
domainName: input.domainName,
|
|
10664
10690
|
RRKeyWord: input.rr,
|
|
10665
10691
|
type: input.type,
|
|
10666
10692
|
searchMode: "ADVANCED",
|
|
10667
10693
|
pageSize: 500
|
|
10668
10694
|
});
|
|
10669
|
-
const response = await client.describeDomainRecords(
|
|
10695
|
+
const response = await client.describeDomainRecords(request2);
|
|
10670
10696
|
const records = response.body?.domainRecords?.record ?? [];
|
|
10671
10697
|
const normalizedRr = input.rr.toLowerCase();
|
|
10672
10698
|
const normalizedType = input.type.toUpperCase();
|
|
@@ -10893,19 +10919,19 @@ var AliyunService = class {
|
|
|
10893
10919
|
weight: "10"
|
|
10894
10920
|
}
|
|
10895
10921
|
]);
|
|
10896
|
-
const
|
|
10922
|
+
const request2 = new import_cdn20180510.AddCdnDomainRequest({
|
|
10897
10923
|
domainName,
|
|
10898
10924
|
cdnType: "web",
|
|
10899
10925
|
sources
|
|
10900
10926
|
});
|
|
10901
|
-
await client.addCdnDomain(
|
|
10927
|
+
await client.addCdnDomain(request2);
|
|
10902
10928
|
ui.success(`CDN domain created: ${domainName}`);
|
|
10903
10929
|
}
|
|
10904
10930
|
/** Fetch the CDN CNAME for a domain. */
|
|
10905
10931
|
static async getCdnCname(domainName) {
|
|
10906
10932
|
const client = this.createCdnClient();
|
|
10907
|
-
const
|
|
10908
|
-
const response = await client.describeDomainCname(
|
|
10933
|
+
const request2 = new import_cdn20180510.DescribeDomainCnameRequest({ domainName });
|
|
10934
|
+
const response = await client.describeDomainCname(request2);
|
|
10909
10935
|
const data = response.body?.cnameDatas?.data ?? [];
|
|
10910
10936
|
const match = data.find((item) => item?.domain === domainName) ?? data[0];
|
|
10911
10937
|
return match?.cname;
|
|
@@ -10936,7 +10962,7 @@ var AliyunService = class {
|
|
|
10936
10962
|
static async refreshCdnSslCertificate(domainName, certKey = DEFAULT_SSL_CERT_KEY) {
|
|
10937
10963
|
const client = this.createCdnClient();
|
|
10938
10964
|
const cert = resolveSslCert(certKey);
|
|
10939
|
-
const
|
|
10965
|
+
const request2 = new import_cdn20180510.SetCdnDomainSSLCertificateRequest({
|
|
10940
10966
|
domainName,
|
|
10941
10967
|
certType: "cas",
|
|
10942
10968
|
certName: cert.certName,
|
|
@@ -10944,7 +10970,7 @@ var AliyunService = class {
|
|
|
10944
10970
|
certRegion: cert.certRegion,
|
|
10945
10971
|
SSLProtocol: "on"
|
|
10946
10972
|
});
|
|
10947
|
-
await client.setCdnDomainSSLCertificate(
|
|
10973
|
+
await client.setCdnDomainSSLCertificate(request2);
|
|
10948
10974
|
}
|
|
10949
10975
|
/** Configure a CDN 403 error page for SPA fallback. */
|
|
10950
10976
|
static async enableSpa404Fallback(domainName) {
|
|
@@ -10961,11 +10987,11 @@ var AliyunService = class {
|
|
|
10961
10987
|
]
|
|
10962
10988
|
}
|
|
10963
10989
|
]);
|
|
10964
|
-
const
|
|
10990
|
+
const request2 = new import_cdn20180510.BatchSetCdnDomainConfigRequest({
|
|
10965
10991
|
domainNames: domainName,
|
|
10966
10992
|
functions
|
|
10967
10993
|
});
|
|
10968
|
-
await client.batchSetCdnDomainConfig(
|
|
10994
|
+
await client.batchSetCdnDomainConfig(request2);
|
|
10969
10995
|
}
|
|
10970
10996
|
/** Enable SPA rewrite rule for CDN. */
|
|
10971
10997
|
static async enableSpaRewriteRule(domainName) {
|
|
@@ -10983,11 +11009,11 @@ var AliyunService = class {
|
|
|
10983
11009
|
]
|
|
10984
11010
|
}
|
|
10985
11011
|
]);
|
|
10986
|
-
const
|
|
11012
|
+
const request2 = new import_cdn20180510.BatchSetCdnDomainConfigRequest({
|
|
10987
11013
|
domainNames: domainName,
|
|
10988
11014
|
functions
|
|
10989
11015
|
});
|
|
10990
|
-
await client.batchSetCdnDomainConfig(
|
|
11016
|
+
await client.batchSetCdnDomainConfig(request2);
|
|
10991
11017
|
}
|
|
10992
11018
|
/** Enable SSG rewrite rule for CDN. */
|
|
10993
11019
|
static async enableSsgRewriteRule(domainName) {
|
|
@@ -11005,11 +11031,11 @@ var AliyunService = class {
|
|
|
11005
11031
|
]
|
|
11006
11032
|
}
|
|
11007
11033
|
]);
|
|
11008
|
-
const
|
|
11034
|
+
const request2 = new import_cdn20180510.BatchSetCdnDomainConfigRequest({
|
|
11009
11035
|
domainNames: domainName,
|
|
11010
11036
|
functions
|
|
11011
11037
|
});
|
|
11012
|
-
await client.batchSetCdnDomainConfig(
|
|
11038
|
+
await client.batchSetCdnDomainConfig(request2);
|
|
11013
11039
|
}
|
|
11014
11040
|
/** Enable OSS private bucket origin auth for CDN. */
|
|
11015
11041
|
static async enableOssPrivateBucketOrigin(domainName) {
|
|
@@ -11020,11 +11046,11 @@ var AliyunService = class {
|
|
|
11020
11046
|
functionArgs: [{ argName: "private_oss_auth", argValue: "on" }]
|
|
11021
11047
|
}
|
|
11022
11048
|
]);
|
|
11023
|
-
const
|
|
11049
|
+
const request2 = new import_cdn20180510.BatchSetCdnDomainConfigRequest({
|
|
11024
11050
|
domainNames: domainName,
|
|
11025
11051
|
functions
|
|
11026
11052
|
});
|
|
11027
|
-
await client.batchSetCdnDomainConfig(
|
|
11053
|
+
await client.batchSetCdnDomainConfig(request2);
|
|
11028
11054
|
}
|
|
11029
11055
|
/** Configure default cache rules for CDN. */
|
|
11030
11056
|
static async setDefaultCacheRules(domainName) {
|
|
@@ -11071,11 +11097,11 @@ var AliyunService = class {
|
|
|
11071
11097
|
]
|
|
11072
11098
|
}
|
|
11073
11099
|
]);
|
|
11074
|
-
const
|
|
11100
|
+
const request2 = new import_cdn20180510.BatchSetCdnDomainConfigRequest({
|
|
11075
11101
|
domainNames: domainName,
|
|
11076
11102
|
functions
|
|
11077
11103
|
});
|
|
11078
|
-
await client.batchSetCdnDomainConfig(
|
|
11104
|
+
await client.batchSetCdnDomainConfig(request2);
|
|
11079
11105
|
}
|
|
11080
11106
|
/** Check if an OSS bucket exists. */
|
|
11081
11107
|
static async bucketExists(client, bucketName) {
|
|
@@ -11103,8 +11129,8 @@ var AliyunService = class {
|
|
|
11103
11129
|
}
|
|
11104
11130
|
/** Check CDN domain status. */
|
|
11105
11131
|
static async getCdnDomainStatus(client, domainName) {
|
|
11106
|
-
const
|
|
11107
|
-
const response = await client.checkCdnDomainExist(
|
|
11132
|
+
const request2 = new import_cdn20180510.CheckCdnDomainExistRequest({ domainName });
|
|
11133
|
+
const response = await client.checkCdnDomainExist(request2);
|
|
11108
11134
|
return response.body?.status;
|
|
11109
11135
|
}
|
|
11110
11136
|
/** Build the OSS regional domain for a bucket. */
|
|
@@ -14896,9 +14922,9 @@ ${indent}\`\`\``;
|
|
|
14896
14922
|
static richTextToPlain(richText) {
|
|
14897
14923
|
return richText.map((item) => item.plain_text ?? item.text?.content ?? "").join("").trim();
|
|
14898
14924
|
}
|
|
14899
|
-
static async requestJson(
|
|
14925
|
+
static async requestJson(path34, init) {
|
|
14900
14926
|
const token = this.getToken();
|
|
14901
|
-
const response = await fetch(`${this.baseUrl}${
|
|
14927
|
+
const response = await fetch(`${this.baseUrl}${path34}`, {
|
|
14902
14928
|
method: init.method,
|
|
14903
14929
|
headers: {
|
|
14904
14930
|
Authorization: `Bearer ${token}`,
|
|
@@ -17494,8 +17520,8 @@ function descriptorPathSegments(descriptor) {
|
|
|
17494
17520
|
return ["chains", normalized.chain, "namespaces", normalized.ns, normalized.kind, normalized.name];
|
|
17495
17521
|
}
|
|
17496
17522
|
function buildPathUrl(baseUrl, pathSegments, query) {
|
|
17497
|
-
const
|
|
17498
|
-
const url = new URL(
|
|
17523
|
+
const path34 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
|
|
17524
|
+
const url = new URL(path34, baseUrl);
|
|
17499
17525
|
if (query) {
|
|
17500
17526
|
for (const [key, value] of Object.entries(query)) {
|
|
17501
17527
|
url.searchParams.set(key, String(value));
|
|
@@ -18237,6 +18263,284 @@ var RunnerCommandHandler = class {
|
|
|
18237
18263
|
}
|
|
18238
18264
|
};
|
|
18239
18265
|
|
|
18266
|
+
// src/commands/RegistryResourceCommandHandler.ts
|
|
18267
|
+
var import_node_fs17 = require("fs");
|
|
18268
|
+
var import_node_path22 = __toESM(require("path"));
|
|
18269
|
+
init_sessionStore();
|
|
18270
|
+
var RegistryResourceCommandHandler = class {
|
|
18271
|
+
async handle(args) {
|
|
18272
|
+
const resource = args.type === "function" ? "functions" : "workers";
|
|
18273
|
+
const singular = args.type === "function" ? "Function" : "Worker";
|
|
18274
|
+
const baseUrl = (args.baseUrl || process.env.PMATE_AGENT_API_BASE_URL || "https://agent-api.pmate.chat").replace(/\/+$/, "");
|
|
18275
|
+
const token = readRequiredSession({ preferredApp: DEFAULT_APP_ID }).token;
|
|
18276
|
+
if (args.action === "list") {
|
|
18277
|
+
const query = args.namespace ? `?namespace=${encodeURIComponent(args.namespace)}` : "";
|
|
18278
|
+
const { items } = await request(baseUrl, token, "GET", `/v1/${resource}${query}`);
|
|
18279
|
+
if (args.json) ui.plain(JSON.stringify(items, null, 2));
|
|
18280
|
+
else if (!items.length) ui.warn(`No ${resource} found.`);
|
|
18281
|
+
else for (const item of items) ui.info(item.id, { status: item.status, ...item.payload });
|
|
18282
|
+
return;
|
|
18283
|
+
}
|
|
18284
|
+
const resourcePath = `/v1/${resource}/${encodeURIComponent(args.namespace)}${args.action === "create" ? "" : `/${encodeURIComponent(args.name)}`}`;
|
|
18285
|
+
if (args.action === "get" || args.action === "view") {
|
|
18286
|
+
const record2 = await request(baseUrl, token, "GET", resourcePath);
|
|
18287
|
+
ui.plain(JSON.stringify(record2, null, 2));
|
|
18288
|
+
return;
|
|
18289
|
+
}
|
|
18290
|
+
if (args.action === "create" || args.action === "update") {
|
|
18291
|
+
const payload = readJson(args.filePath);
|
|
18292
|
+
const record2 = await request(baseUrl, token, args.action === "create" ? "POST" : "PUT", resourcePath, payload);
|
|
18293
|
+
ui.success(`${args.action === "create" ? "Created" : "Updated"} ${singular.toLowerCase()} ${record2.id}`);
|
|
18294
|
+
if (args.json) ui.plain(JSON.stringify(record2, null, 2));
|
|
18295
|
+
return;
|
|
18296
|
+
}
|
|
18297
|
+
const record = await request(baseUrl, token, "DELETE", resourcePath);
|
|
18298
|
+
ui.success(`Disabled ${singular.toLowerCase()} ${record.id}`);
|
|
18299
|
+
if (args.json) ui.plain(JSON.stringify(record, null, 2));
|
|
18300
|
+
}
|
|
18301
|
+
};
|
|
18302
|
+
function readJson(filePath) {
|
|
18303
|
+
const absolutePath = import_node_path22.default.resolve(process.cwd(), filePath);
|
|
18304
|
+
if (!(0, import_node_fs17.existsSync)(absolutePath)) throw new Error(`JSON file not found: ${absolutePath}`);
|
|
18305
|
+
return JSON.parse((0, import_node_fs17.readFileSync)(absolutePath, "utf8"));
|
|
18306
|
+
}
|
|
18307
|
+
async function request(baseUrl, token, method, pathname, body) {
|
|
18308
|
+
const response = await fetch(`${baseUrl}${pathname}`, {
|
|
18309
|
+
method,
|
|
18310
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
18311
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
18312
|
+
});
|
|
18313
|
+
const payload = await response.json();
|
|
18314
|
+
if (!response.ok || !payload.success) throw new Error(payload.message || `Request failed with status ${response.status}`);
|
|
18315
|
+
return payload.data;
|
|
18316
|
+
}
|
|
18317
|
+
|
|
18318
|
+
// src/commands/CallCommandHandler.ts
|
|
18319
|
+
var import_node_fs18 = require("fs");
|
|
18320
|
+
var import_node_path23 = __toESM(require("path"));
|
|
18321
|
+
|
|
18322
|
+
// node_modules/.pnpm/@pmate+hub-sdk@0.2.1/node_modules/@pmate/hub-sdk/dist/HubClient.js
|
|
18323
|
+
init_src();
|
|
18324
|
+
init_src3();
|
|
18325
|
+
var DEFAULT_TIMEOUT_MS2 = 4e4;
|
|
18326
|
+
var HubClient = class {
|
|
18327
|
+
options;
|
|
18328
|
+
ws;
|
|
18329
|
+
profileId;
|
|
18330
|
+
token;
|
|
18331
|
+
authenticated = false;
|
|
18332
|
+
calls = /* @__PURE__ */ new Map();
|
|
18333
|
+
timeoutMs;
|
|
18334
|
+
connectWaiter;
|
|
18335
|
+
authWaiter;
|
|
18336
|
+
constructor(options) {
|
|
18337
|
+
this.options = options;
|
|
18338
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
|
|
18339
|
+
}
|
|
18340
|
+
async login(options) {
|
|
18341
|
+
this.close();
|
|
18342
|
+
this.profileId = options.profileId;
|
|
18343
|
+
this.token = options.token;
|
|
18344
|
+
this.connectWaiter = deferred();
|
|
18345
|
+
this.authWaiter = deferred();
|
|
18346
|
+
const ws = new WebsocketClientV2(ensureWsProtocol(this.options.baseUrl));
|
|
18347
|
+
this.ws = ws;
|
|
18348
|
+
const stream = ws.getStream();
|
|
18349
|
+
void this.consume(stream);
|
|
18350
|
+
const timeoutMs = options.timeoutMs ?? this.timeoutMs;
|
|
18351
|
+
await withTimeout(this.connectWaiter.promise, timeoutMs, "Hub connection timed out");
|
|
18352
|
+
await ws.sendMsg(Msg.create(options.profileId, "@hub", 4 /* AUTH */, {
|
|
18353
|
+
token: options.token,
|
|
18354
|
+
as: "user",
|
|
18355
|
+
profileId: options.profileId
|
|
18356
|
+
}, 0 /* PIPELINE */));
|
|
18357
|
+
await withTimeout(this.authWaiter.promise, timeoutMs, "Hub authentication timed out");
|
|
18358
|
+
this.authenticated = true;
|
|
18359
|
+
}
|
|
18360
|
+
async call(request2) {
|
|
18361
|
+
if (!this.ws || !this.profileId || !this.token || !this.authenticated) {
|
|
18362
|
+
throw new Error("HubClient is not logged in");
|
|
18363
|
+
}
|
|
18364
|
+
const callId = createCallId(request2.functionId);
|
|
18365
|
+
const timeoutMs = request2.timeoutMs ?? this.timeoutMs;
|
|
18366
|
+
const result = new Promise((resolve, reject) => {
|
|
18367
|
+
const timer = setTimeout(() => {
|
|
18368
|
+
this.calls.delete(callId);
|
|
18369
|
+
reject(new Error(`Function call timed out: ${request2.functionId}`));
|
|
18370
|
+
}, timeoutMs);
|
|
18371
|
+
this.calls.set(callId, {
|
|
18372
|
+
resolve,
|
|
18373
|
+
reject,
|
|
18374
|
+
timer
|
|
18375
|
+
});
|
|
18376
|
+
});
|
|
18377
|
+
const body = {
|
|
18378
|
+
kind: "request",
|
|
18379
|
+
callId,
|
|
18380
|
+
functionId: request2.functionId,
|
|
18381
|
+
input: request2.input,
|
|
18382
|
+
auth: { token: this.token, profileId: this.profileId },
|
|
18383
|
+
idempotencyKey: request2.idempotencyKey,
|
|
18384
|
+
timeoutMs
|
|
18385
|
+
};
|
|
18386
|
+
try {
|
|
18387
|
+
await this.ws.sendMsg(Msg.create(this.profileId, "@hub", MsgOp.CALL, body, 0 /* PIPELINE */));
|
|
18388
|
+
} catch (error) {
|
|
18389
|
+
this.rejectCall(callId, error instanceof Error ? error : new Error(String(error)));
|
|
18390
|
+
}
|
|
18391
|
+
return result;
|
|
18392
|
+
}
|
|
18393
|
+
close() {
|
|
18394
|
+
this.ws?.close();
|
|
18395
|
+
this.ws = void 0;
|
|
18396
|
+
this.authenticated = false;
|
|
18397
|
+
this.token = void 0;
|
|
18398
|
+
this.connectWaiter?.reject(new Error("HubClient closed before connection completed"));
|
|
18399
|
+
this.authWaiter?.reject(new Error("HubClient closed before authentication completed"));
|
|
18400
|
+
this.connectWaiter = void 0;
|
|
18401
|
+
this.authWaiter = void 0;
|
|
18402
|
+
for (const callId of this.calls.keys()) {
|
|
18403
|
+
this.rejectCall(callId, new Error("HubClient closed before call completed"));
|
|
18404
|
+
}
|
|
18405
|
+
}
|
|
18406
|
+
async consume(stream) {
|
|
18407
|
+
try {
|
|
18408
|
+
for await (const event of stream) {
|
|
18409
|
+
this.handleEvent(event);
|
|
18410
|
+
}
|
|
18411
|
+
} catch (error) {
|
|
18412
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
18413
|
+
this.connectWaiter?.reject(failure);
|
|
18414
|
+
this.authWaiter?.reject(failure);
|
|
18415
|
+
for (const callId of this.calls.keys()) {
|
|
18416
|
+
this.rejectCall(callId, failure);
|
|
18417
|
+
}
|
|
18418
|
+
}
|
|
18419
|
+
}
|
|
18420
|
+
handleEvent(event) {
|
|
18421
|
+
if (event.type === "connected") {
|
|
18422
|
+
if (event.data)
|
|
18423
|
+
this.connectWaiter?.resolve();
|
|
18424
|
+
else
|
|
18425
|
+
this.authenticated = false;
|
|
18426
|
+
return;
|
|
18427
|
+
}
|
|
18428
|
+
if (event.type === "error") {
|
|
18429
|
+
const failure = new Error("Hub websocket connection failed");
|
|
18430
|
+
this.connectWaiter?.reject(failure);
|
|
18431
|
+
this.authWaiter?.reject(failure);
|
|
18432
|
+
return;
|
|
18433
|
+
}
|
|
18434
|
+
if (event.type === "message")
|
|
18435
|
+
this.handleMessage(event.data);
|
|
18436
|
+
}
|
|
18437
|
+
handleMessage(message) {
|
|
18438
|
+
if (message.opcode === 3 /* ACK */) {
|
|
18439
|
+
const ack = message.body;
|
|
18440
|
+
if (ack.status === "ok")
|
|
18441
|
+
this.authWaiter?.resolve();
|
|
18442
|
+
else
|
|
18443
|
+
this.authWaiter?.reject(new Error(ack.message ?? ack.code ?? "Hub authentication failed"));
|
|
18444
|
+
return;
|
|
18445
|
+
}
|
|
18446
|
+
if (message.opcode !== MsgOp.CALL)
|
|
18447
|
+
return;
|
|
18448
|
+
const body = message.body;
|
|
18449
|
+
if (body?.kind !== "response")
|
|
18450
|
+
return;
|
|
18451
|
+
this.handleResponse(body);
|
|
18452
|
+
}
|
|
18453
|
+
handleResponse(body) {
|
|
18454
|
+
if (body.status === "pending" || body.status === "running")
|
|
18455
|
+
return;
|
|
18456
|
+
const call = this.calls.get(body.callId);
|
|
18457
|
+
if (!call)
|
|
18458
|
+
return;
|
|
18459
|
+
clearTimeout(call.timer);
|
|
18460
|
+
this.calls.delete(body.callId);
|
|
18461
|
+
if (body.status === "completed") {
|
|
18462
|
+
call.resolve(body.output);
|
|
18463
|
+
return;
|
|
18464
|
+
}
|
|
18465
|
+
call.reject(new Error(body.error?.message ?? `Function call ${body.status}`));
|
|
18466
|
+
}
|
|
18467
|
+
rejectCall(callId, error) {
|
|
18468
|
+
const call = this.calls.get(callId);
|
|
18469
|
+
if (!call)
|
|
18470
|
+
return;
|
|
18471
|
+
clearTimeout(call.timer);
|
|
18472
|
+
this.calls.delete(callId);
|
|
18473
|
+
call.reject(error);
|
|
18474
|
+
}
|
|
18475
|
+
};
|
|
18476
|
+
function createCallId(functionId) {
|
|
18477
|
+
return uniqHash(`${functionId}-${Date.now()}-${Math.random()}`, "task-v1" /* Task */);
|
|
18478
|
+
}
|
|
18479
|
+
function ensureWsProtocol(baseUrl) {
|
|
18480
|
+
if (/^wss?:\/\//i.test(baseUrl))
|
|
18481
|
+
return baseUrl;
|
|
18482
|
+
if (/^https:\/\//i.test(baseUrl))
|
|
18483
|
+
return baseUrl.replace(/^https:/i, "wss:");
|
|
18484
|
+
if (/^http:\/\//i.test(baseUrl))
|
|
18485
|
+
return baseUrl.replace(/^http:/i, "ws:");
|
|
18486
|
+
return `wss://${baseUrl}`;
|
|
18487
|
+
}
|
|
18488
|
+
function deferred() {
|
|
18489
|
+
let resolve;
|
|
18490
|
+
let reject;
|
|
18491
|
+
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
18492
|
+
resolve = resolvePromise;
|
|
18493
|
+
reject = rejectPromise;
|
|
18494
|
+
});
|
|
18495
|
+
return { promise, resolve, reject };
|
|
18496
|
+
}
|
|
18497
|
+
function withTimeout(promise, timeoutMs, message) {
|
|
18498
|
+
return new Promise((resolve, reject) => {
|
|
18499
|
+
const timer = setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
18500
|
+
promise.then((value) => {
|
|
18501
|
+
clearTimeout(timer);
|
|
18502
|
+
resolve(value);
|
|
18503
|
+
}, (error) => {
|
|
18504
|
+
clearTimeout(timer);
|
|
18505
|
+
reject(error);
|
|
18506
|
+
});
|
|
18507
|
+
});
|
|
18508
|
+
}
|
|
18509
|
+
|
|
18510
|
+
// src/commands/CallCommandHandler.ts
|
|
18511
|
+
init_sessionStore();
|
|
18512
|
+
var CallCommandHandler = class {
|
|
18513
|
+
async handle(args) {
|
|
18514
|
+
const session = readRequiredSession({ preferredApp: DEFAULT_APP_ID });
|
|
18515
|
+
const hub = new HubClient({
|
|
18516
|
+
baseUrl: args.hubBaseUrl || process.env.PMATE_HUB_BASE_URL || "https://hub.pmate.chat",
|
|
18517
|
+
timeoutMs: args.timeoutMs
|
|
18518
|
+
});
|
|
18519
|
+
const input = args.filePath ? readJson2(args.filePath) : args.payload;
|
|
18520
|
+
try {
|
|
18521
|
+
await hub.login({ token: session.token, profileId: session.profileId, timeoutMs: args.timeoutMs });
|
|
18522
|
+
const output = await hub.call({
|
|
18523
|
+
functionId: `${args.namespace}:${args.name}`,
|
|
18524
|
+
input,
|
|
18525
|
+
timeoutMs: args.timeoutMs
|
|
18526
|
+
});
|
|
18527
|
+
if (args.json || typeof output !== "string") ui.plain(JSON.stringify(output ?? null, null, 2));
|
|
18528
|
+
else ui.plain(output);
|
|
18529
|
+
} finally {
|
|
18530
|
+
hub.close();
|
|
18531
|
+
}
|
|
18532
|
+
}
|
|
18533
|
+
};
|
|
18534
|
+
function readJson2(filePath) {
|
|
18535
|
+
const absolutePath = import_node_path23.default.resolve(process.cwd(), filePath);
|
|
18536
|
+
if (!(0, import_node_fs18.existsSync)(absolutePath)) throw new Error(`JSON file not found: ${absolutePath}`);
|
|
18537
|
+
const decoded = JSON.parse((0, import_node_fs18.readFileSync)(absolutePath, "utf8"));
|
|
18538
|
+
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) {
|
|
18539
|
+
throw new Error("Call input file must contain a JSON object");
|
|
18540
|
+
}
|
|
18541
|
+
return decoded;
|
|
18542
|
+
}
|
|
18543
|
+
|
|
18240
18544
|
// src/commands/NsCommandHandler.ts
|
|
18241
18545
|
init_sessionStore();
|
|
18242
18546
|
var NsCommandHandler = class {
|
|
@@ -18303,8 +18607,8 @@ var NsCommandHandler = class {
|
|
|
18303
18607
|
};
|
|
18304
18608
|
|
|
18305
18609
|
// src/commands/StoreCommandHandler.ts
|
|
18306
|
-
var
|
|
18307
|
-
var
|
|
18610
|
+
var import_node_fs19 = require("fs");
|
|
18611
|
+
var import_node_path24 = __toESM(require("path"));
|
|
18308
18612
|
init_sessionStore();
|
|
18309
18613
|
var StoreCommandHandler = class {
|
|
18310
18614
|
async handle(args) {
|
|
@@ -18458,11 +18762,11 @@ var StoreCommandHandler = class {
|
|
|
18458
18762
|
return payload.data ?? [];
|
|
18459
18763
|
}
|
|
18460
18764
|
readJsonFile(filePath) {
|
|
18461
|
-
const absolutePath =
|
|
18462
|
-
if (!(0,
|
|
18765
|
+
const absolutePath = import_node_path24.default.resolve(process.cwd(), filePath);
|
|
18766
|
+
if (!(0, import_node_fs19.existsSync)(absolutePath)) {
|
|
18463
18767
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
18464
18768
|
}
|
|
18465
|
-
const raw = (0,
|
|
18769
|
+
const raw = (0, import_node_fs19.readFileSync)(absolutePath, "utf8");
|
|
18466
18770
|
try {
|
|
18467
18771
|
return JSON.parse(raw);
|
|
18468
18772
|
} catch (error) {
|
|
@@ -18514,14 +18818,14 @@ var StoreCommandHandler = class {
|
|
|
18514
18818
|
};
|
|
18515
18819
|
|
|
18516
18820
|
// src/commands/AppCommandHandler.ts
|
|
18517
|
-
var
|
|
18518
|
-
var
|
|
18821
|
+
var import_node_fs21 = require("fs");
|
|
18822
|
+
var import_node_path26 = __toESM(require("path"));
|
|
18519
18823
|
init_sessionStore();
|
|
18520
18824
|
|
|
18521
18825
|
// src/appIcon.ts
|
|
18522
|
-
var
|
|
18826
|
+
var import_node_fs20 = require("fs");
|
|
18523
18827
|
var import_node_os8 = __toESM(require("os"));
|
|
18524
|
-
var
|
|
18828
|
+
var import_node_path25 = __toESM(require("path"));
|
|
18525
18829
|
var import_sharp = __toESM(require("sharp"));
|
|
18526
18830
|
init_namespacedRef();
|
|
18527
18831
|
var ANDROID_ICON_SPECS = [
|
|
@@ -18626,13 +18930,13 @@ function createAppIconExportPlans(input) {
|
|
|
18626
18930
|
if (!input.outDir) {
|
|
18627
18931
|
throw new Error("App icon preset export requires --out-dir.");
|
|
18628
18932
|
}
|
|
18629
|
-
const outDir =
|
|
18630
|
-
(0,
|
|
18933
|
+
const outDir = import_node_path25.default.resolve(input.cwd, input.outDir);
|
|
18934
|
+
(0, import_node_fs20.mkdirSync)(outDir, { recursive: true });
|
|
18631
18935
|
return specs.map((spec) => ({
|
|
18632
18936
|
width: spec.width,
|
|
18633
18937
|
height: spec.height,
|
|
18634
18938
|
format: "png",
|
|
18635
|
-
outputPath:
|
|
18939
|
+
outputPath: import_node_path25.default.join(
|
|
18636
18940
|
outDir,
|
|
18637
18941
|
`${namespace}-${objectId}-${spec.name}-${spec.width}x${spec.height}.png`
|
|
18638
18942
|
)
|
|
@@ -18645,8 +18949,8 @@ function createAppIconExportPlans(input) {
|
|
|
18645
18949
|
if (!input.output) {
|
|
18646
18950
|
throw new Error("Single-size app icon export requires --output.");
|
|
18647
18951
|
}
|
|
18648
|
-
const resolvedOutput =
|
|
18649
|
-
(0,
|
|
18952
|
+
const resolvedOutput = import_node_path25.default.resolve(input.cwd, input.output);
|
|
18953
|
+
(0, import_node_fs20.mkdirSync)(import_node_path25.default.dirname(resolvedOutput), { recursive: true });
|
|
18650
18954
|
return [
|
|
18651
18955
|
{
|
|
18652
18956
|
width: input.width,
|
|
@@ -18660,7 +18964,7 @@ async function exportAppIcon(icon, plans) {
|
|
|
18660
18964
|
const svg = await resolveAppIconSvg(icon);
|
|
18661
18965
|
for (const plan of plans) {
|
|
18662
18966
|
const bytes = await renderAppIcon(svg, plan.width, plan.height, plan.format);
|
|
18663
|
-
(0,
|
|
18967
|
+
(0, import_node_fs20.writeFileSync)(plan.outputPath, bytes);
|
|
18664
18968
|
}
|
|
18665
18969
|
}
|
|
18666
18970
|
async function renderAppIconVariant(input) {
|
|
@@ -18668,9 +18972,9 @@ async function renderAppIconVariant(input) {
|
|
|
18668
18972
|
const bytes = await renderAppIcon(svg, input.width, input.height, input.format);
|
|
18669
18973
|
let outputPath;
|
|
18670
18974
|
if (input.output) {
|
|
18671
|
-
outputPath =
|
|
18672
|
-
(0,
|
|
18673
|
-
(0,
|
|
18975
|
+
outputPath = import_node_path25.default.resolve(input.cwd, input.output);
|
|
18976
|
+
(0, import_node_fs20.mkdirSync)(import_node_path25.default.dirname(outputPath), { recursive: true });
|
|
18977
|
+
(0, import_node_fs20.writeFileSync)(outputPath, bytes);
|
|
18674
18978
|
}
|
|
18675
18979
|
if (input.name) {
|
|
18676
18980
|
return {
|
|
@@ -18691,7 +18995,7 @@ async function renderAppIconVariant(input) {
|
|
|
18691
18995
|
};
|
|
18692
18996
|
}
|
|
18693
18997
|
async function loadAppIconVariantFile(input) {
|
|
18694
|
-
const absolutePath =
|
|
18998
|
+
const absolutePath = import_node_path25.default.resolve(input.cwd, input.filePath);
|
|
18695
18999
|
const format = inferVariantFormatFromPath(absolutePath);
|
|
18696
19000
|
return {
|
|
18697
19001
|
value: input.name ? await uploadAppIconVariantAsset({
|
|
@@ -18700,7 +19004,7 @@ async function loadAppIconVariantFile(input) {
|
|
|
18700
19004
|
name: input.name,
|
|
18701
19005
|
format,
|
|
18702
19006
|
sourcePath: absolutePath
|
|
18703
|
-
}) : createImageDataUrl((0,
|
|
19007
|
+
}) : createImageDataUrl((0, import_node_fs20.readFileSync)(absolutePath), format),
|
|
18704
19008
|
format,
|
|
18705
19009
|
absolutePath
|
|
18706
19010
|
};
|
|
@@ -18759,7 +19063,7 @@ function shouldAutoGenerateDefaultVariant(icon) {
|
|
|
18759
19063
|
return looksLikeSvgMarkup(icon) || looksLikeSvgUrl(icon);
|
|
18760
19064
|
}
|
|
18761
19065
|
function inferVariantFormatFromPath(filePath) {
|
|
18762
|
-
const ext =
|
|
19066
|
+
const ext = import_node_path25.default.extname(filePath).toLowerCase();
|
|
18763
19067
|
switch (ext) {
|
|
18764
19068
|
case ".png":
|
|
18765
19069
|
return "png";
|
|
@@ -18830,13 +19134,13 @@ async function uploadAppIconVariantAsset(input) {
|
|
|
18830
19134
|
await AliyunService.uploadFile(sourcePath, DEFAULT_APP_ICON_VARIANT_BUCKET, objectKey);
|
|
18831
19135
|
} finally {
|
|
18832
19136
|
if (shouldCleanup) {
|
|
18833
|
-
(0,
|
|
19137
|
+
(0, import_node_fs20.rmSync)(import_node_path25.default.dirname(sourcePath), { recursive: true, force: true });
|
|
18834
19138
|
}
|
|
18835
19139
|
}
|
|
18836
19140
|
return `${DEFAULT_APP_ICON_VARIANT_PUBLIC_BASE_URL}/${objectKey}`;
|
|
18837
19141
|
}
|
|
18838
19142
|
function buildAppIconVariantObjectKey(input) {
|
|
18839
|
-
return
|
|
19143
|
+
return import_node_path25.default.posix.join(
|
|
18840
19144
|
"apps",
|
|
18841
19145
|
`${resolveAppIconAssetStem(input.icon, input.appRef)}-${input.name}.${extensionForIconFormat(input.format)}`
|
|
18842
19146
|
);
|
|
@@ -18845,8 +19149,8 @@ function resolveAppIconAssetStem(icon, appRef) {
|
|
|
18845
19149
|
if (icon) {
|
|
18846
19150
|
try {
|
|
18847
19151
|
const url = new URL(icon);
|
|
18848
|
-
const ext =
|
|
18849
|
-
const basename =
|
|
19152
|
+
const ext = import_node_path25.default.posix.extname(url.pathname);
|
|
19153
|
+
const basename = import_node_path25.default.posix.basename(url.pathname, ext);
|
|
18850
19154
|
const normalized = sanitizeAppIconAssetStem(basename);
|
|
18851
19155
|
if (normalized) {
|
|
18852
19156
|
return normalized;
|
|
@@ -18875,9 +19179,9 @@ function writeTempAppIconVariantFile(objectKey, format, bytes) {
|
|
|
18875
19179
|
if (!bytes) {
|
|
18876
19180
|
throw new Error("App icon variant upload requires bytes or a source file.");
|
|
18877
19181
|
}
|
|
18878
|
-
const tempDir = (0,
|
|
18879
|
-
const tempPath =
|
|
18880
|
-
(0,
|
|
19182
|
+
const tempDir = (0, import_node_fs20.mkdtempSync)(import_node_path25.default.join(import_node_os8.default.tmpdir(), "pmate-app-icon-"));
|
|
19183
|
+
const tempPath = import_node_path25.default.join(tempDir, import_node_path25.default.basename(objectKey) || `variant.${extensionForIconFormat(format)}`);
|
|
19184
|
+
(0, import_node_fs20.writeFileSync)(tempPath, bytes);
|
|
18881
19185
|
return tempPath;
|
|
18882
19186
|
}
|
|
18883
19187
|
|
|
@@ -19086,10 +19390,10 @@ var AppCommandHandler = class {
|
|
|
19086
19390
|
}
|
|
19087
19391
|
readJsonFile(filePath) {
|
|
19088
19392
|
const absolutePath = this.resolveFilePath(filePath);
|
|
19089
|
-
if (!(0,
|
|
19393
|
+
if (!(0, import_node_fs21.existsSync)(absolutePath)) {
|
|
19090
19394
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
19091
19395
|
}
|
|
19092
|
-
const raw = (0,
|
|
19396
|
+
const raw = (0, import_node_fs21.readFileSync)(absolutePath, "utf8");
|
|
19093
19397
|
try {
|
|
19094
19398
|
return JSON.parse(raw);
|
|
19095
19399
|
} catch (error) {
|
|
@@ -19099,10 +19403,10 @@ var AppCommandHandler = class {
|
|
|
19099
19403
|
}
|
|
19100
19404
|
async preparePayload(filePath, appRef) {
|
|
19101
19405
|
const absolutePath = this.resolveFilePath(filePath);
|
|
19102
|
-
return prepareAppPayload(this.readJsonFile(filePath),
|
|
19406
|
+
return prepareAppPayload(this.readJsonFile(filePath), import_node_path26.default.dirname(absolutePath), { appRef });
|
|
19103
19407
|
}
|
|
19104
19408
|
resolveFilePath(filePath) {
|
|
19105
|
-
return
|
|
19409
|
+
return import_node_path26.default.resolve(process.cwd(), filePath);
|
|
19106
19410
|
}
|
|
19107
19411
|
async request(baseUrl, token, method, pathname, body) {
|
|
19108
19412
|
const response = await fetch(`${baseUrl}${pathname}`, {
|
|
@@ -19222,18 +19526,18 @@ function readNamespaceFromPayload(payload) {
|
|
|
19222
19526
|
}
|
|
19223
19527
|
|
|
19224
19528
|
// src/commands/ServiceCommandHandler.ts
|
|
19225
|
-
var
|
|
19529
|
+
var import_node_fs24 = require("fs");
|
|
19226
19530
|
var import_promises5 = require("fs/promises");
|
|
19227
|
-
var
|
|
19531
|
+
var import_node_path29 = __toESM(require("path"));
|
|
19228
19532
|
var import_node_child_process11 = require("child_process");
|
|
19229
19533
|
var import_promises6 = require("readline/promises");
|
|
19230
19534
|
|
|
19231
19535
|
// src/services/AndroidApkReleaseService.ts
|
|
19232
19536
|
var import_node_child_process9 = require("child_process");
|
|
19233
19537
|
var import_node_crypto4 = require("crypto");
|
|
19234
|
-
var
|
|
19538
|
+
var import_node_fs22 = require("fs");
|
|
19235
19539
|
var import_node_os9 = __toESM(require("os"));
|
|
19236
|
-
var
|
|
19540
|
+
var import_node_path27 = __toESM(require("path"));
|
|
19237
19541
|
var ANDROID_APK_BUCKET = "parrot-static";
|
|
19238
19542
|
var ANDROID_APK_PUBLIC_BASE_URL = "https://parrot-static.pmate.chat";
|
|
19239
19543
|
var AndroidApkReleaseService = class {
|
|
@@ -19267,7 +19571,7 @@ var AndroidApkReleaseService = class {
|
|
|
19267
19571
|
}
|
|
19268
19572
|
await AliyunService.uploadFile(apkPath, ANDROID_APK_BUCKET, objectKey);
|
|
19269
19573
|
const sha256 = await sha256File(apkPath);
|
|
19270
|
-
const size = (0,
|
|
19574
|
+
const size = (0, import_node_fs22.statSync)(apkPath).size;
|
|
19271
19575
|
const artifact = {
|
|
19272
19576
|
serviceId: service.id,
|
|
19273
19577
|
env: options.env,
|
|
@@ -19301,15 +19605,15 @@ var AndroidApkReleaseService = class {
|
|
|
19301
19605
|
minimumVersionCode: options.minimumVersionCode
|
|
19302
19606
|
});
|
|
19303
19607
|
const objectKey = buildAndroidLatestManifestObjectKey(service.namespace, service.name);
|
|
19304
|
-
const tempDir = (0,
|
|
19305
|
-
const manifestPath =
|
|
19608
|
+
const tempDir = (0, import_node_fs22.mkdtempSync)(import_node_path27.default.join(import_node_os9.default.tmpdir(), "pmate-apk-latest-"));
|
|
19609
|
+
const manifestPath = import_node_path27.default.join(tempDir, "latest.json");
|
|
19306
19610
|
try {
|
|
19307
|
-
(0,
|
|
19611
|
+
(0, import_node_fs22.writeFileSync)(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
19308
19612
|
`);
|
|
19309
19613
|
await AliyunService.uploadFile(manifestPath, ANDROID_APK_BUCKET, objectKey);
|
|
19310
19614
|
ui.success(`Published Android update manifest ${ANDROID_APK_PUBLIC_BASE_URL}/${objectKey}`);
|
|
19311
19615
|
} finally {
|
|
19312
|
-
(0,
|
|
19616
|
+
(0, import_node_fs22.rmSync)(tempDir, { recursive: true, force: true });
|
|
19313
19617
|
}
|
|
19314
19618
|
}
|
|
19315
19619
|
async list(service, options) {
|
|
@@ -19325,7 +19629,7 @@ var AndroidApkReleaseService = class {
|
|
|
19325
19629
|
const prefix = `apks/${service.namespace}/${service.name}`;
|
|
19326
19630
|
const objects = await AliyunService.listObjects(ANDROID_APK_BUCKET, prefix);
|
|
19327
19631
|
return objects.filter((item) => item.name.endsWith(".apk")).map((item) => {
|
|
19328
|
-
const versionName =
|
|
19632
|
+
const versionName = import_node_path27.default.basename(item.name, ".apk");
|
|
19329
19633
|
return {
|
|
19330
19634
|
serviceId,
|
|
19331
19635
|
env: options.env ?? "unknown",
|
|
@@ -19348,7 +19652,7 @@ var AndroidApkReleaseService = class {
|
|
|
19348
19652
|
}
|
|
19349
19653
|
}
|
|
19350
19654
|
resolveRepoRoot(service, cwd) {
|
|
19351
|
-
if (cwd) return
|
|
19655
|
+
if (cwd) return import_node_path27.default.resolve(process.cwd(), cwd);
|
|
19352
19656
|
const repository = this.getRepository(service);
|
|
19353
19657
|
if (repository) {
|
|
19354
19658
|
return resolveRepositoryLocalRoot(repository);
|
|
@@ -19360,8 +19664,8 @@ var AndroidApkReleaseService = class {
|
|
|
19360
19664
|
if (!dir) {
|
|
19361
19665
|
throw new Error(`Missing dir for android service ${service.id}`);
|
|
19362
19666
|
}
|
|
19363
|
-
const appDir =
|
|
19364
|
-
if (!(0,
|
|
19667
|
+
const appDir = import_node_path27.default.resolve(repoRoot, dir);
|
|
19668
|
+
if (!(0, import_node_fs22.existsSync)(appDir)) {
|
|
19365
19669
|
throw new Error(`Android app dir not found: ${appDir}`);
|
|
19366
19670
|
}
|
|
19367
19671
|
return appDir;
|
|
@@ -19377,11 +19681,11 @@ var AndroidApkReleaseService = class {
|
|
|
19377
19681
|
return void 0;
|
|
19378
19682
|
}
|
|
19379
19683
|
async runGradleAssembleAndFindApk(repoRoot, appDir, variant) {
|
|
19380
|
-
const gradlew = [
|
|
19684
|
+
const gradlew = [import_node_path27.default.join(appDir, "gradlew"), import_node_path27.default.join(repoRoot, "gradlew")].find((candidate) => (0, import_node_fs22.existsSync)(candidate));
|
|
19381
19685
|
if (!gradlew) {
|
|
19382
19686
|
throw new Error(`Gradle wrapper not found in ${appDir} or ${repoRoot}`);
|
|
19383
19687
|
}
|
|
19384
|
-
const gradleCwd =
|
|
19688
|
+
const gradleCwd = import_node_path27.default.dirname(gradlew);
|
|
19385
19689
|
const normalizedVariant = variant.toLowerCase();
|
|
19386
19690
|
const taskSuffix = `assemble${capitalize(normalizedVariant)}`;
|
|
19387
19691
|
const tasks = [`:app:${taskSuffix}`, taskSuffix];
|
|
@@ -19469,7 +19773,7 @@ function resolveRepositoryLocalRoot(repository) {
|
|
|
19469
19773
|
if (!repoName) {
|
|
19470
19774
|
throw new Error(`Invalid repository: ${repository}`);
|
|
19471
19775
|
}
|
|
19472
|
-
return
|
|
19776
|
+
return import_node_path27.default.join(import_node_os9.default.homedir(), "dev", "pmate", repoName);
|
|
19473
19777
|
}
|
|
19474
19778
|
function bumpAndroidGradleVersionText(source, bump) {
|
|
19475
19779
|
const versionNameMatch = source.match(/(^\s*versionName\s+["'])([^"']+)(["']\s*$)/m) ?? source.match(/(^\s*versionName\s*=\s*["'])([^"']+)(["']\s*$)/m);
|
|
@@ -19525,42 +19829,42 @@ function parseGradleOutputMetadata(source, apkFileName) {
|
|
|
19525
19829
|
}
|
|
19526
19830
|
function bumpAndroidProjectVersion(appDir, bump) {
|
|
19527
19831
|
const candidates = [
|
|
19528
|
-
|
|
19529
|
-
|
|
19530
|
-
|
|
19531
|
-
|
|
19832
|
+
import_node_path27.default.join(appDir, "app", "build.gradle.kts"),
|
|
19833
|
+
import_node_path27.default.join(appDir, "app", "build.gradle"),
|
|
19834
|
+
import_node_path27.default.join(appDir, "build.gradle.kts"),
|
|
19835
|
+
import_node_path27.default.join(appDir, "build.gradle")
|
|
19532
19836
|
];
|
|
19533
19837
|
for (const candidate of candidates) {
|
|
19534
|
-
if (!(0,
|
|
19535
|
-
const result = bumpAndroidGradleVersionText((0,
|
|
19536
|
-
(0,
|
|
19838
|
+
if (!(0, import_node_fs22.existsSync)(candidate)) continue;
|
|
19839
|
+
const result = bumpAndroidGradleVersionText((0, import_node_fs22.readFileSync)(candidate, "utf8"), bump);
|
|
19840
|
+
(0, import_node_fs22.writeFileSync)(candidate, result.source);
|
|
19537
19841
|
return { filePath: candidate, ...result };
|
|
19538
19842
|
}
|
|
19539
19843
|
throw new Error(`No Android Gradle version file found under ${appDir}`);
|
|
19540
19844
|
}
|
|
19541
19845
|
function findLatestApk(repoRoot, appDir, variant) {
|
|
19542
19846
|
const dirs = [
|
|
19543
|
-
|
|
19544
|
-
|
|
19545
|
-
|
|
19847
|
+
import_node_path27.default.join(appDir, "app", "build", "outputs", "apk", variant),
|
|
19848
|
+
import_node_path27.default.join(appDir, "build", "outputs", "apk", variant),
|
|
19849
|
+
import_node_path27.default.join(repoRoot, "app", "build", "outputs", "apk", variant)
|
|
19546
19850
|
];
|
|
19547
19851
|
const files = dirs.flatMap((dir) => listApks(dir));
|
|
19548
19852
|
if (files.length === 0) {
|
|
19549
19853
|
throw new Error(`Cannot find APK output for variant ${variant}`);
|
|
19550
19854
|
}
|
|
19551
|
-
files.sort((a, b) => (0,
|
|
19855
|
+
files.sort((a, b) => (0, import_node_fs22.statSync)(b).mtimeMs - (0, import_node_fs22.statSync)(a).mtimeMs);
|
|
19552
19856
|
return files[0];
|
|
19553
19857
|
}
|
|
19554
19858
|
function readGradleOutputMetadata(apkPath) {
|
|
19555
|
-
const metadataPath =
|
|
19556
|
-
if (!(0,
|
|
19859
|
+
const metadataPath = import_node_path27.default.join(import_node_path27.default.dirname(apkPath), "output-metadata.json");
|
|
19860
|
+
if (!(0, import_node_fs22.existsSync)(metadataPath)) {
|
|
19557
19861
|
throw new Error(`Gradle output metadata not found: ${metadataPath}`);
|
|
19558
19862
|
}
|
|
19559
|
-
return parseGradleOutputMetadata((0,
|
|
19863
|
+
return parseGradleOutputMetadata((0, import_node_fs22.readFileSync)(metadataPath, "utf8"), import_node_path27.default.basename(apkPath));
|
|
19560
19864
|
}
|
|
19561
19865
|
function listApks(dir) {
|
|
19562
|
-
if (!(0,
|
|
19563
|
-
return (0,
|
|
19866
|
+
if (!(0, import_node_fs22.existsSync)(dir)) return [];
|
|
19867
|
+
return (0, import_node_fs22.readdirSync)(dir).filter((entry) => entry.endsWith(".apk")).map((entry) => import_node_path27.default.join(dir, entry)).filter((entry) => (0, import_node_fs22.statSync)(entry).isFile());
|
|
19564
19868
|
}
|
|
19565
19869
|
function runCommand(command, args, cwd) {
|
|
19566
19870
|
return new Promise((resolve, reject) => {
|
|
@@ -19594,26 +19898,26 @@ async function runAndroidSdkToolCapture(toolName, args) {
|
|
|
19594
19898
|
return runCommandCapture(toolPath, args);
|
|
19595
19899
|
}
|
|
19596
19900
|
function findAndroidSdkTool(toolName) {
|
|
19597
|
-
const sdkRoots = [process.env.ANDROID_HOME, process.env.ANDROID_SDK_ROOT].filter((item) => Boolean(item)).map((item) =>
|
|
19901
|
+
const sdkRoots = [process.env.ANDROID_HOME, process.env.ANDROID_SDK_ROOT].filter((item) => Boolean(item)).map((item) => import_node_path27.default.resolve(item));
|
|
19598
19902
|
for (const sdkRoot of sdkRoots) {
|
|
19599
|
-
const candidates = toolName === "aapt" ? listVersionedToolCandidates(
|
|
19600
|
-
|
|
19601
|
-
...listVersionedToolCandidates(
|
|
19602
|
-
|
|
19903
|
+
const candidates = toolName === "aapt" ? listVersionedToolCandidates(import_node_path27.default.join(sdkRoot, "build-tools"), toolName) : [
|
|
19904
|
+
import_node_path27.default.join(sdkRoot, "cmdline-tools", "latest", "bin", toolName),
|
|
19905
|
+
...listVersionedToolCandidates(import_node_path27.default.join(sdkRoot, "cmdline-tools"), import_node_path27.default.join("bin", toolName)),
|
|
19906
|
+
import_node_path27.default.join(sdkRoot, "tools", "bin", toolName)
|
|
19603
19907
|
];
|
|
19604
|
-
const match = candidates.find((candidate) => (0,
|
|
19908
|
+
const match = candidates.find((candidate) => (0, import_node_fs22.existsSync)(candidate));
|
|
19605
19909
|
if (match) return match;
|
|
19606
19910
|
}
|
|
19607
19911
|
return void 0;
|
|
19608
19912
|
}
|
|
19609
19913
|
function listVersionedToolCandidates(parentDir, relativeToolPath) {
|
|
19610
|
-
if (!(0,
|
|
19611
|
-
return (0,
|
|
19914
|
+
if (!(0, import_node_fs22.existsSync)(parentDir)) return [];
|
|
19915
|
+
return (0, import_node_fs22.readdirSync)(parentDir).map((entry) => import_node_path27.default.join(parentDir, entry)).filter((entry) => (0, import_node_fs22.statSync)(entry).isDirectory()).sort((a, b) => import_node_path27.default.basename(b).localeCompare(import_node_path27.default.basename(a), void 0, { numeric: true })).map((entry) => import_node_path27.default.join(entry, relativeToolPath));
|
|
19612
19916
|
}
|
|
19613
19917
|
function sha256File(filePath) {
|
|
19614
19918
|
return new Promise((resolve, reject) => {
|
|
19615
19919
|
const hash = (0, import_node_crypto4.createHash)("sha256");
|
|
19616
|
-
const stream = (0,
|
|
19920
|
+
const stream = (0, import_node_fs22.createReadStream)(filePath);
|
|
19617
19921
|
stream.on("data", (chunk) => hash.update(chunk));
|
|
19618
19922
|
stream.on("error", reject);
|
|
19619
19923
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -19630,9 +19934,9 @@ function capitalize(value) {
|
|
|
19630
19934
|
}
|
|
19631
19935
|
|
|
19632
19936
|
// src/services/ServiceRuntimeRunner.ts
|
|
19633
|
-
var
|
|
19937
|
+
var import_node_fs23 = require("fs");
|
|
19634
19938
|
var import_node_os10 = __toESM(require("os"));
|
|
19635
|
-
var
|
|
19939
|
+
var import_node_path28 = __toESM(require("path"));
|
|
19636
19940
|
var import_node_child_process10 = require("child_process");
|
|
19637
19941
|
var import_node_readline = require("readline");
|
|
19638
19942
|
var import_chalk3 = __toESM(require("chalk"));
|
|
@@ -20122,14 +20426,14 @@ var ServiceRuntimeRunner = class {
|
|
|
20122
20426
|
}
|
|
20123
20427
|
resolveRepoRoot(service, cwd) {
|
|
20124
20428
|
if (cwd) {
|
|
20125
|
-
return
|
|
20429
|
+
return import_node_path28.default.resolve(process.cwd(), cwd);
|
|
20126
20430
|
}
|
|
20127
20431
|
const repository = this.getType(service) === "vite" || this.getType(service) === "static" ? this.getRepoStaticSite(service).repository.trim() : this.getType(service) === "fc" ? this.getFc(service).repository?.trim() : this.getType(service) === "ios" || this.getType(service) === "android" ? void 0 : this.getNetwork(service).repository?.trim();
|
|
20128
20432
|
if (repository) {
|
|
20129
20433
|
const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
|
|
20130
20434
|
if (repoName) {
|
|
20131
|
-
const candidate =
|
|
20132
|
-
if ((0,
|
|
20435
|
+
const candidate = import_node_path28.default.join(import_node_os10.default.homedir(), "dev", "pmate", repoName);
|
|
20436
|
+
if ((0, import_node_fs23.existsSync)(candidate)) {
|
|
20133
20437
|
return candidate;
|
|
20134
20438
|
}
|
|
20135
20439
|
}
|
|
@@ -20142,13 +20446,13 @@ var ServiceRuntimeRunner = class {
|
|
|
20142
20446
|
if (!dir) {
|
|
20143
20447
|
throw new Error(`Missing service dir for ${service.id}`);
|
|
20144
20448
|
}
|
|
20145
|
-
return
|
|
20449
|
+
return import_node_path28.default.resolve(repoRoot, dir);
|
|
20146
20450
|
}
|
|
20147
20451
|
async deployVite(service, options) {
|
|
20148
20452
|
this.assertDeployableStaticSite(service);
|
|
20149
20453
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20150
|
-
const packageJsonPath =
|
|
20151
|
-
if (!(0,
|
|
20454
|
+
const packageJsonPath = import_node_path28.default.join(appDir, "package.json");
|
|
20455
|
+
if (!(0, import_node_fs23.existsSync)(packageJsonPath)) {
|
|
20152
20456
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20153
20457
|
}
|
|
20154
20458
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -20163,8 +20467,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20163
20467
|
this.resolveRepoRoot(service, options.cwd),
|
|
20164
20468
|
buildEnv
|
|
20165
20469
|
);
|
|
20166
|
-
const distDir =
|
|
20167
|
-
if (!(0,
|
|
20470
|
+
const distDir = import_node_path28.default.join(appDir, "dist");
|
|
20471
|
+
if (!(0, import_node_fs23.existsSync)(distDir)) {
|
|
20168
20472
|
throw new Error(`No dist directory found at ${distDir}`);
|
|
20169
20473
|
}
|
|
20170
20474
|
const site = this.getSite(service);
|
|
@@ -20177,8 +20481,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20177
20481
|
async deployStatic(service, options) {
|
|
20178
20482
|
this.assertDeployableStaticSite(service);
|
|
20179
20483
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20180
|
-
const srcDir =
|
|
20181
|
-
if (!(0,
|
|
20484
|
+
const srcDir = import_node_path28.default.join(appDir, "src");
|
|
20485
|
+
if (!(0, import_node_fs23.existsSync)(srcDir)) {
|
|
20182
20486
|
throw new Error(`No src directory found at ${srcDir}`);
|
|
20183
20487
|
}
|
|
20184
20488
|
const site = this.getSite(service);
|
|
@@ -20212,8 +20516,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20212
20516
|
this.validateFcConfig(service, fc);
|
|
20213
20517
|
const repoRoot = this.resolveRepoRoot(service);
|
|
20214
20518
|
const appDir = this.resolveLocalDir(service);
|
|
20215
|
-
const packageJsonPath =
|
|
20216
|
-
if (!(0,
|
|
20519
|
+
const packageJsonPath = import_node_path28.default.join(appDir, "package.json");
|
|
20520
|
+
if (!(0, import_node_fs23.existsSync)(packageJsonPath)) {
|
|
20217
20521
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20218
20522
|
}
|
|
20219
20523
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -20266,15 +20570,15 @@ var ServiceRuntimeRunner = class {
|
|
|
20266
20570
|
const repoRoot = this.resolveRepoRoot(service, options.cwd);
|
|
20267
20571
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20268
20572
|
await this.ensurePnpmWorkspaceRoot(repoRoot);
|
|
20269
|
-
const configPath =
|
|
20270
|
-
if (!(0,
|
|
20573
|
+
const configPath = import_node_path28.default.join(appDir, fc.configFile ?? "s.yaml");
|
|
20574
|
+
if (!(0, import_node_fs23.existsSync)(configPath)) {
|
|
20271
20575
|
throw new Error(`Missing FC config file at ${configPath}`);
|
|
20272
20576
|
}
|
|
20273
|
-
const packageJsonPath =
|
|
20274
|
-
if (!(0,
|
|
20577
|
+
const packageJsonPath = import_node_path28.default.join(appDir, "package.json");
|
|
20578
|
+
if (!(0, import_node_fs23.existsSync)(packageJsonPath)) {
|
|
20275
20579
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20276
20580
|
}
|
|
20277
|
-
const rawConfig = (0,
|
|
20581
|
+
const rawConfig = (0, import_node_fs23.readFileSync)(configPath, "utf8");
|
|
20278
20582
|
if (!rawConfig.includes(fc.functionName)) {
|
|
20279
20583
|
throw new Error(`FC config ${configPath} does not mention functionName ${fc.functionName}`);
|
|
20280
20584
|
}
|
|
@@ -20552,7 +20856,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20552
20856
|
const serverAddress = await resolveServerAddress(server);
|
|
20553
20857
|
const templateName = exposeType === "websocket" ? "nginx.ws.template" : "nginx.rest.template";
|
|
20554
20858
|
const templatePath = this.resolveTemplatePath(templateName);
|
|
20555
|
-
const template = (0,
|
|
20859
|
+
const template = (0, import_node_fs23.readFileSync)(templatePath, "utf8");
|
|
20556
20860
|
const host = `${subdomain}.${("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat"}`;
|
|
20557
20861
|
const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
|
|
20558
20862
|
const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
|
|
@@ -20584,11 +20888,11 @@ var ServiceRuntimeRunner = class {
|
|
|
20584
20888
|
}
|
|
20585
20889
|
if (config.ensurePackageJson) {
|
|
20586
20890
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20587
|
-
const packageJsonPath =
|
|
20588
|
-
if (!(0,
|
|
20891
|
+
const packageJsonPath = import_node_path28.default.join(appDir, "package.json");
|
|
20892
|
+
if (!(0, import_node_fs23.existsSync)(packageJsonPath)) {
|
|
20589
20893
|
throw new Error(`Missing package.json at ${packageJsonPath}`);
|
|
20590
20894
|
}
|
|
20591
|
-
const pkgStat = (0,
|
|
20895
|
+
const pkgStat = (0, import_node_fs23.statSync)(packageJsonPath);
|
|
20592
20896
|
if (!pkgStat.isFile()) {
|
|
20593
20897
|
throw new Error(`package.json is not a file at ${packageJsonPath}`);
|
|
20594
20898
|
}
|
|
@@ -21017,9 +21321,9 @@ var ServiceRuntimeRunner = class {
|
|
|
21017
21321
|
return tokens;
|
|
21018
21322
|
}
|
|
21019
21323
|
readPathValue(source, pathExpr) {
|
|
21020
|
-
const
|
|
21324
|
+
const path34 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
|
|
21021
21325
|
let cursor = source;
|
|
21022
|
-
for (const segment of
|
|
21326
|
+
for (const segment of path34) {
|
|
21023
21327
|
if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
|
|
21024
21328
|
return void 0;
|
|
21025
21329
|
}
|
|
@@ -21062,12 +21366,12 @@ var ServiceRuntimeRunner = class {
|
|
|
21062
21366
|
}
|
|
21063
21367
|
resolveTemplatePath(templateName) {
|
|
21064
21368
|
const candidates = [
|
|
21065
|
-
|
|
21066
|
-
|
|
21067
|
-
|
|
21369
|
+
import_node_path28.default.join(__dirname, "..", "templates", templateName),
|
|
21370
|
+
import_node_path28.default.join(__dirname, "..", "src", "templates", templateName),
|
|
21371
|
+
import_node_path28.default.join(__dirname, "templates", templateName)
|
|
21068
21372
|
];
|
|
21069
21373
|
for (const candidate of candidates) {
|
|
21070
|
-
if ((0,
|
|
21374
|
+
if ((0, import_node_fs23.existsSync)(candidate)) {
|
|
21071
21375
|
return candidate;
|
|
21072
21376
|
}
|
|
21073
21377
|
}
|
|
@@ -21099,7 +21403,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21099
21403
|
});
|
|
21100
21404
|
}
|
|
21101
21405
|
loadPackageJson(packageJsonPath) {
|
|
21102
|
-
const raw = (0,
|
|
21406
|
+
const raw = (0, import_node_fs23.readFileSync)(packageJsonPath, "utf8");
|
|
21103
21407
|
const parsed = JSON.parse(raw);
|
|
21104
21408
|
if (!parsed || typeof parsed !== "object") {
|
|
21105
21409
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -21108,7 +21412,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21108
21412
|
}
|
|
21109
21413
|
writePackageJson(packageJsonPath, data) {
|
|
21110
21414
|
const serialized = JSON.stringify(data, null, 2);
|
|
21111
|
-
(0,
|
|
21415
|
+
(0, import_node_fs23.writeFileSync)(packageJsonPath, `${serialized}
|
|
21112
21416
|
`, "utf8");
|
|
21113
21417
|
}
|
|
21114
21418
|
validateFcConfig(service, fc) {
|
|
@@ -21135,8 +21439,8 @@ var ServiceRuntimeRunner = class {
|
|
|
21135
21439
|
}
|
|
21136
21440
|
}
|
|
21137
21441
|
async ensurePnpmWorkspaceRoot(repoRoot) {
|
|
21138
|
-
const workspacePath =
|
|
21139
|
-
if (!(0,
|
|
21442
|
+
const workspacePath = import_node_path28.default.join(repoRoot, "pnpm-workspace.yaml");
|
|
21443
|
+
if (!(0, import_node_fs23.existsSync)(workspacePath)) {
|
|
21140
21444
|
throw new Error(`Missing pnpm-workspace.yaml at ${workspacePath}`);
|
|
21141
21445
|
}
|
|
21142
21446
|
}
|
|
@@ -21210,16 +21514,16 @@ var ServiceRuntimeRunner = class {
|
|
|
21210
21514
|
if (!privateKeyPath) {
|
|
21211
21515
|
throw new Error("Missing ssl.prv in ~/.pmate/config.yaml.");
|
|
21212
21516
|
}
|
|
21213
|
-
if (!(0,
|
|
21517
|
+
if (!(0, import_node_fs23.existsSync)(certificatePath)) {
|
|
21214
21518
|
throw new Error(`SSL certificate file not found: ${certificatePath}`);
|
|
21215
21519
|
}
|
|
21216
|
-
if (!(0,
|
|
21520
|
+
if (!(0, import_node_fs23.existsSync)(privateKeyPath)) {
|
|
21217
21521
|
throw new Error(`SSL private key file not found: ${privateKeyPath}`);
|
|
21218
21522
|
}
|
|
21219
21523
|
return {
|
|
21220
21524
|
certName: host,
|
|
21221
|
-
certificate: (0,
|
|
21222
|
-
privateKey: (0,
|
|
21525
|
+
certificate: (0, import_node_fs23.readFileSync)(certificatePath, "utf8"),
|
|
21526
|
+
privateKey: (0, import_node_fs23.readFileSync)(privateKeyPath, "utf8")
|
|
21223
21527
|
};
|
|
21224
21528
|
}
|
|
21225
21529
|
resolveFcProtocol(fc, certConfig) {
|
|
@@ -21678,7 +21982,7 @@ var ServiceCommandHandler = class {
|
|
|
21678
21982
|
format: "dotenv"
|
|
21679
21983
|
}
|
|
21680
21984
|
);
|
|
21681
|
-
const outputPath =
|
|
21985
|
+
const outputPath = import_node_path29.default.resolve(process.cwd(), args.output);
|
|
21682
21986
|
await (0, import_promises5.writeFile)(outputPath, payload.content, "utf8");
|
|
21683
21987
|
ui.success(`Wrote env file for ${args.appId} to ${outputPath}`);
|
|
21684
21988
|
this.renderJson({ ...payload, output: outputPath }, args.json);
|
|
@@ -21904,11 +22208,11 @@ var ServiceCommandHandler = class {
|
|
|
21904
22208
|
return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
21905
22209
|
}
|
|
21906
22210
|
readJsonFile(filePath) {
|
|
21907
|
-
const absolutePath =
|
|
21908
|
-
if (!(0,
|
|
22211
|
+
const absolutePath = import_node_path29.default.resolve(process.cwd(), filePath);
|
|
22212
|
+
if (!(0, import_node_fs24.existsSync)(absolutePath)) {
|
|
21909
22213
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
21910
22214
|
}
|
|
21911
|
-
const raw = (0,
|
|
22215
|
+
const raw = (0, import_node_fs24.readFileSync)(absolutePath, "utf8");
|
|
21912
22216
|
try {
|
|
21913
22217
|
return JSON.parse(raw);
|
|
21914
22218
|
} catch (error) {
|
|
@@ -22716,9 +23020,9 @@ var RoleCommandHandler = class {
|
|
|
22716
23020
|
};
|
|
22717
23021
|
|
|
22718
23022
|
// src/commands/AccountCommandHandler.ts
|
|
22719
|
-
var
|
|
23023
|
+
var import_node_fs25 = require("fs");
|
|
22720
23024
|
var import_node_crypto5 = require("crypto");
|
|
22721
|
-
var
|
|
23025
|
+
var import_node_path30 = __toESM(require("path"));
|
|
22722
23026
|
init_sessionStore();
|
|
22723
23027
|
var AccountCommandHandler = class {
|
|
22724
23028
|
async handle(args) {
|
|
@@ -22726,9 +23030,9 @@ var AccountCommandHandler = class {
|
|
|
22726
23030
|
case "bot-keygen": {
|
|
22727
23031
|
const keyFile = this.generateBotKeyFile(args.app, args.name);
|
|
22728
23032
|
const outPath = args.out ? this.resolveFilePath(args.out) : this.resolveDefaultBotKeyPath(args.app, args.name);
|
|
22729
|
-
(0,
|
|
22730
|
-
(0,
|
|
22731
|
-
(0,
|
|
23033
|
+
(0, import_node_fs25.mkdirSync)(import_node_path30.default.dirname(outPath), { recursive: true });
|
|
23034
|
+
(0, import_node_fs25.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
23035
|
+
(0, import_node_fs25.chmodSync)(outPath, 384);
|
|
22732
23036
|
if (!args.json) {
|
|
22733
23037
|
ui.success(`Bot key saved to ${outPath}`);
|
|
22734
23038
|
}
|
|
@@ -23264,10 +23568,10 @@ var AccountCommandHandler = class {
|
|
|
23264
23568
|
throw new Error("Missing visible apps input");
|
|
23265
23569
|
}
|
|
23266
23570
|
const absolutePath = this.resolveFilePath(args.filePath);
|
|
23267
|
-
if (!(0,
|
|
23571
|
+
if (!(0, import_node_fs25.existsSync)(absolutePath)) {
|
|
23268
23572
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23269
23573
|
}
|
|
23270
|
-
const raw = (0,
|
|
23574
|
+
const raw = (0, import_node_fs25.readFileSync)(absolutePath, "utf8");
|
|
23271
23575
|
let parsed;
|
|
23272
23576
|
try {
|
|
23273
23577
|
parsed = JSON.parse(raw);
|
|
@@ -23281,13 +23585,13 @@ var AccountCommandHandler = class {
|
|
|
23281
23585
|
return parsed;
|
|
23282
23586
|
}
|
|
23283
23587
|
resolveFilePath(filePath) {
|
|
23284
|
-
return
|
|
23588
|
+
return import_node_path30.default.resolve(process.cwd(), filePath);
|
|
23285
23589
|
}
|
|
23286
23590
|
resolveDefaultBotKeyPath(app, name) {
|
|
23287
|
-
return
|
|
23591
|
+
return import_node_path30.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
|
|
23288
23592
|
}
|
|
23289
23593
|
resolveDefaultAccessKeyPath(app, name) {
|
|
23290
|
-
return
|
|
23594
|
+
return import_node_path30.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
|
|
23291
23595
|
}
|
|
23292
23596
|
homeDir() {
|
|
23293
23597
|
return process.env.HOME || process.env.USERPROFILE || process.cwd();
|
|
@@ -23310,10 +23614,10 @@ var AccountCommandHandler = class {
|
|
|
23310
23614
|
throw new Error("Missing bot key file");
|
|
23311
23615
|
}
|
|
23312
23616
|
const absolutePath = this.resolveFilePath(filePath);
|
|
23313
|
-
if (!(0,
|
|
23617
|
+
if (!(0, import_node_fs25.existsSync)(absolutePath)) {
|
|
23314
23618
|
throw new Error(`Bot key file not found: ${absolutePath}`);
|
|
23315
23619
|
}
|
|
23316
|
-
const parsed = JSON.parse((0,
|
|
23620
|
+
const parsed = JSON.parse((0, import_node_fs25.readFileSync)(absolutePath, "utf8"));
|
|
23317
23621
|
if (parsed.type !== "pmate-bot-key" || parsed.version !== 1 || parsed.algorithm !== "ed25519" || !parsed.publicKey || !parsed.privateKey) {
|
|
23318
23622
|
throw new Error(`Invalid PMate bot key file: ${absolutePath}`);
|
|
23319
23623
|
}
|
|
@@ -23330,10 +23634,10 @@ var AccountCommandHandler = class {
|
|
|
23330
23634
|
throw new Error("Missing access key file");
|
|
23331
23635
|
}
|
|
23332
23636
|
const absolutePath = this.resolveFilePath(filePath);
|
|
23333
|
-
if (!(0,
|
|
23637
|
+
if (!(0, import_node_fs25.existsSync)(absolutePath)) {
|
|
23334
23638
|
throw new Error(`Access key file not found: ${absolutePath}`);
|
|
23335
23639
|
}
|
|
23336
|
-
const parsed = JSON.parse((0,
|
|
23640
|
+
const parsed = JSON.parse((0, import_node_fs25.readFileSync)(absolutePath, "utf8"));
|
|
23337
23641
|
if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
|
|
23338
23642
|
throw new Error(`Invalid PMate access key file: ${absolutePath}`);
|
|
23339
23643
|
}
|
|
@@ -23355,9 +23659,9 @@ var AccountCommandHandler = class {
|
|
|
23355
23659
|
createdAt: result.key.createdAt
|
|
23356
23660
|
};
|
|
23357
23661
|
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
|
|
23358
|
-
(0,
|
|
23359
|
-
(0,
|
|
23360
|
-
(0,
|
|
23662
|
+
(0, import_node_fs25.mkdirSync)(import_node_path30.default.dirname(outPath), { recursive: true });
|
|
23663
|
+
(0, import_node_fs25.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
23664
|
+
(0, import_node_fs25.chmodSync)(outPath, 384);
|
|
23361
23665
|
}
|
|
23362
23666
|
renderAccessKeyCreateResult(result, asJson, out) {
|
|
23363
23667
|
if (asJson) {
|
|
@@ -23442,8 +23746,8 @@ function encodePathSegment2(value) {
|
|
|
23442
23746
|
}
|
|
23443
23747
|
|
|
23444
23748
|
// src/commands/OrgCommandHandler.ts
|
|
23445
|
-
var
|
|
23446
|
-
var
|
|
23749
|
+
var import_node_fs26 = require("fs");
|
|
23750
|
+
var import_node_path31 = __toESM(require("path"));
|
|
23447
23751
|
init_sessionStore();
|
|
23448
23752
|
var OrgCommandHandler = class {
|
|
23449
23753
|
async handle(args) {
|
|
@@ -23613,11 +23917,11 @@ var OrgCommandHandler = class {
|
|
|
23613
23917
|
if (!filePath) {
|
|
23614
23918
|
throw new Error(`Missing ${itemLabel} input`);
|
|
23615
23919
|
}
|
|
23616
|
-
const absolutePath =
|
|
23617
|
-
if (!(0,
|
|
23920
|
+
const absolutePath = import_node_path31.default.resolve(process.cwd(), filePath);
|
|
23921
|
+
if (!(0, import_node_fs26.existsSync)(absolutePath)) {
|
|
23618
23922
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23619
23923
|
}
|
|
23620
|
-
const raw = (0,
|
|
23924
|
+
const raw = (0, import_node_fs26.readFileSync)(absolutePath, "utf8");
|
|
23621
23925
|
let parsed;
|
|
23622
23926
|
try {
|
|
23623
23927
|
parsed = JSON.parse(raw);
|
|
@@ -23688,9 +23992,9 @@ function encodePathSegment3(value) {
|
|
|
23688
23992
|
}
|
|
23689
23993
|
|
|
23690
23994
|
// src/commands/HostCommandHandler.ts
|
|
23691
|
-
var
|
|
23995
|
+
var import_node_fs27 = require("fs");
|
|
23692
23996
|
var import_node_os11 = require("os");
|
|
23693
|
-
var
|
|
23997
|
+
var import_node_path32 = __toESM(require("path"));
|
|
23694
23998
|
var import_node_child_process13 = require("child_process");
|
|
23695
23999
|
var BLOCK_START = "# >>> pmate host env >>>";
|
|
23696
24000
|
var BLOCK_END = "# <<< pmate host env <<<";
|
|
@@ -24322,6 +24626,101 @@ function requireValue2(tokens, optionName) {
|
|
|
24322
24626
|
return value;
|
|
24323
24627
|
}
|
|
24324
24628
|
|
|
24629
|
+
// src/registryResourceCommandParser.ts
|
|
24630
|
+
init_namespacedRef();
|
|
24631
|
+
function parseFunctionArgs(tokens) {
|
|
24632
|
+
return parseRegistryArgs(tokens, "function" /* Function */, "function");
|
|
24633
|
+
}
|
|
24634
|
+
function parseWorkerArgs(tokens) {
|
|
24635
|
+
return parseRegistryArgs(tokens, "worker" /* Worker */, "worker");
|
|
24636
|
+
}
|
|
24637
|
+
function parseRegistryArgs(tokens, type, label) {
|
|
24638
|
+
const rest = [...tokens];
|
|
24639
|
+
const action = rest.shift();
|
|
24640
|
+
if (!action || !["list", "get", "view", "create", "update", "delete"].includes(action)) {
|
|
24641
|
+
throw new Error(`Use: ${label} list|get|view|create|update|delete`);
|
|
24642
|
+
}
|
|
24643
|
+
let baseUrl;
|
|
24644
|
+
let json = false;
|
|
24645
|
+
let namespace;
|
|
24646
|
+
let name;
|
|
24647
|
+
let filePath;
|
|
24648
|
+
if (["get", "view", "update", "delete"].includes(action)) {
|
|
24649
|
+
const ref = rest.shift();
|
|
24650
|
+
if (!ref) throw new Error(`Missing ${label} ref`);
|
|
24651
|
+
const parsed = parseNamespacedRef(ref, { entityLabel: `${label} ref` });
|
|
24652
|
+
namespace = parsed.namespace;
|
|
24653
|
+
name = parsed.objectId;
|
|
24654
|
+
} else if (action === "create" && rest[0] && !rest[0].startsWith("-")) {
|
|
24655
|
+
namespace = rest.shift();
|
|
24656
|
+
}
|
|
24657
|
+
namespace ??= "pmate";
|
|
24658
|
+
while (rest.length) {
|
|
24659
|
+
const option = rest.shift();
|
|
24660
|
+
const value = () => {
|
|
24661
|
+
const next = rest.shift();
|
|
24662
|
+
if (!next || next.startsWith("-")) throw new Error(`Missing value for ${option}`);
|
|
24663
|
+
return next;
|
|
24664
|
+
};
|
|
24665
|
+
if (option === "--namespace" || option === "--ns") namespace = value();
|
|
24666
|
+
else if (option === "--base-url") baseUrl = value();
|
|
24667
|
+
else if (option === "--file") filePath = value();
|
|
24668
|
+
else if (option === "--json") json = true;
|
|
24669
|
+
else throw new Error(`Unknown ${label} option: ${option}`);
|
|
24670
|
+
}
|
|
24671
|
+
if ((action === "create" || action === "update") && !filePath) {
|
|
24672
|
+
throw new Error(`Missing required option --file for ${label} ${action}`);
|
|
24673
|
+
}
|
|
24674
|
+
return { type, action, namespace, name, filePath, baseUrl, json };
|
|
24675
|
+
}
|
|
24676
|
+
|
|
24677
|
+
// src/callCommandParser.ts
|
|
24678
|
+
init_namespacedRef();
|
|
24679
|
+
function parseCallArgs(tokens) {
|
|
24680
|
+
const rest = [...tokens];
|
|
24681
|
+
const ref = rest.shift();
|
|
24682
|
+
if (!ref) throw new Error("Usage: call <namespace:functionId> [--payload <json>|--file <path>]");
|
|
24683
|
+
const parsed = parseNamespacedRef(ref, { entityLabel: "function ref" });
|
|
24684
|
+
let payload;
|
|
24685
|
+
let filePath;
|
|
24686
|
+
let hubBaseUrl;
|
|
24687
|
+
let timeoutMs;
|
|
24688
|
+
let json = false;
|
|
24689
|
+
while (rest.length) {
|
|
24690
|
+
const option = rest.shift();
|
|
24691
|
+
const value = () => {
|
|
24692
|
+
const next = rest.shift();
|
|
24693
|
+
if (!next || next.startsWith("-")) throw new Error(`Missing value for ${option}`);
|
|
24694
|
+
return next;
|
|
24695
|
+
};
|
|
24696
|
+
if (option === "--payload") {
|
|
24697
|
+
const decoded = JSON.parse(value());
|
|
24698
|
+
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) {
|
|
24699
|
+
throw new Error("--payload must be a JSON object");
|
|
24700
|
+
}
|
|
24701
|
+
payload = decoded;
|
|
24702
|
+
} else if (option === "--file") filePath = value();
|
|
24703
|
+
else if (option === "--hub-base-url") hubBaseUrl = value();
|
|
24704
|
+
else if (option === "--timeout-ms") timeoutMs = Number.parseInt(value(), 10);
|
|
24705
|
+
else if (option === "--json") json = true;
|
|
24706
|
+
else throw new Error(`Unknown call option: ${option}`);
|
|
24707
|
+
}
|
|
24708
|
+
if (payload && filePath) throw new Error("Provide only one of --payload or --file");
|
|
24709
|
+
if (timeoutMs !== void 0 && (!Number.isInteger(timeoutMs) || timeoutMs < 1)) {
|
|
24710
|
+
throw new Error("--timeout-ms must be a positive integer");
|
|
24711
|
+
}
|
|
24712
|
+
return {
|
|
24713
|
+
type: "call" /* Call */,
|
|
24714
|
+
namespace: parsed.namespace,
|
|
24715
|
+
name: parsed.objectId,
|
|
24716
|
+
payload,
|
|
24717
|
+
filePath,
|
|
24718
|
+
hubBaseUrl,
|
|
24719
|
+
timeoutMs,
|
|
24720
|
+
json
|
|
24721
|
+
};
|
|
24722
|
+
}
|
|
24723
|
+
|
|
24325
24724
|
// src/nsCommandParser.ts
|
|
24326
24725
|
var DEFAULT_CHAIN = "pmate";
|
|
24327
24726
|
function parseNsArgs(tokens) {
|
|
@@ -27286,7 +27685,7 @@ function requireValue13(tokens, option) {
|
|
|
27286
27685
|
|
|
27287
27686
|
// src/index.ts
|
|
27288
27687
|
var pkg = JSON.parse(
|
|
27289
|
-
(0,
|
|
27688
|
+
(0, import_node_fs28.readFileSync)(import_node_path33.default.resolve(__dirname, "..", "package.json"), "utf8")
|
|
27290
27689
|
);
|
|
27291
27690
|
var HELP_TEXT = [
|
|
27292
27691
|
import_chalk4.default.bold(`pmate v${pkg.version}`),
|
|
@@ -27398,6 +27797,12 @@ var HELP_TEXT = [
|
|
|
27398
27797
|
` ${import_chalk4.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
|
|
27399
27798
|
` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
27400
27799
|
` ${import_chalk4.default.gray(" list defaults to all namespaces; create defaults to namespace: pmate; default base URL: https://agent-api.pmate.chat")}`,
|
|
27800
|
+
` ${import_chalk4.default.cyan("function")} Manage Function Registry entries`,
|
|
27801
|
+
` ${import_chalk4.default.gray(" list|get|view|create|update|delete [--base-url <url>] [--json]")}`,
|
|
27802
|
+
` ${import_chalk4.default.cyan("worker")} Manage Worker Registry entries`,
|
|
27803
|
+
` ${import_chalk4.default.gray(" list|get|view|create|update|delete [--base-url <url>] [--json]")}`,
|
|
27804
|
+
` ${import_chalk4.default.cyan("call")} Call a Function through Hub`,
|
|
27805
|
+
` ${import_chalk4.default.gray(" <namespace:functionId> [--payload <json>|--file <path>] [--timeout-ms <n>] [--json]")}`,
|
|
27401
27806
|
` ${import_chalk4.default.cyan("ns")} Manage registered namespaces`,
|
|
27402
27807
|
` ${import_chalk4.default.gray(" list [--chain <chain>] [--base-url <url>] [--json]")}`,
|
|
27403
27808
|
` ${import_chalk4.default.gray(" get <namespace> [--chain <chain>] [--base-url <url>] [--json]")}`,
|
|
@@ -27644,6 +28049,15 @@ function parseCommandArgs(args) {
|
|
|
27644
28049
|
if (args.rest[0] === "runner") {
|
|
27645
28050
|
return parseRunnerArgs(args.rest.slice(1));
|
|
27646
28051
|
}
|
|
28052
|
+
if (args.rest[0] === "function") {
|
|
28053
|
+
return parseFunctionArgs(args.rest.slice(1));
|
|
28054
|
+
}
|
|
28055
|
+
if (args.rest[0] === "worker") {
|
|
28056
|
+
return parseWorkerArgs(args.rest.slice(1));
|
|
28057
|
+
}
|
|
28058
|
+
if (args.rest[0] === "call") {
|
|
28059
|
+
return parseCallArgs(args.rest.slice(1));
|
|
28060
|
+
}
|
|
27647
28061
|
if (args.rest[0] === "ns" || args.rest[0] === "namespace") {
|
|
27648
28062
|
return parseNsArgs(args.rest.slice(1));
|
|
27649
28063
|
}
|
|
@@ -29353,6 +29767,17 @@ async function main() {
|
|
|
29353
29767
|
await handler.handle(commandArgs);
|
|
29354
29768
|
return;
|
|
29355
29769
|
}
|
|
29770
|
+
case "function" /* Function */:
|
|
29771
|
+
case "worker" /* Worker */: {
|
|
29772
|
+
const handler = new RegistryResourceCommandHandler();
|
|
29773
|
+
await handler.handle(commandArgs);
|
|
29774
|
+
return;
|
|
29775
|
+
}
|
|
29776
|
+
case "call" /* Call */: {
|
|
29777
|
+
const handler = new CallCommandHandler();
|
|
29778
|
+
await handler.handle(commandArgs);
|
|
29779
|
+
return;
|
|
29780
|
+
}
|
|
29356
29781
|
case "ns" /* Ns */: {
|
|
29357
29782
|
const handler = new NsCommandHandler();
|
|
29358
29783
|
await handler.handle(commandArgs);
|