@pmate/cli 0.28.7 → 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 +685 -235
- 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));
|
|
@@ -17519,8 +17545,9 @@ function normalizeNamespace(value) {
|
|
|
17519
17545
|
return normalized;
|
|
17520
17546
|
}
|
|
17521
17547
|
var IndexerClient = class {
|
|
17522
|
-
constructor(baseUrl) {
|
|
17548
|
+
constructor(baseUrl, headers = {}) {
|
|
17523
17549
|
this.baseUrl = baseUrl;
|
|
17550
|
+
this.headers = headers;
|
|
17524
17551
|
}
|
|
17525
17552
|
async requestByPath(pathSegments, options = {}) {
|
|
17526
17553
|
const method = options.method ?? "GET";
|
|
@@ -17531,6 +17558,7 @@ var IndexerClient = class {
|
|
|
17531
17558
|
method,
|
|
17532
17559
|
headers: {
|
|
17533
17560
|
Accept: "application/json",
|
|
17561
|
+
...this.headers,
|
|
17534
17562
|
...method === "POST" ? { "Content-Type": "application/json" } : {}
|
|
17535
17563
|
},
|
|
17536
17564
|
...method === "POST" ? { body: JSON.stringify(options.query ?? {}) } : {}
|
|
@@ -17541,9 +17569,10 @@ var IndexerClient = class {
|
|
|
17541
17569
|
}
|
|
17542
17570
|
};
|
|
17543
17571
|
var BlockLogAppender = class {
|
|
17544
|
-
constructor(chainId, baseUrl) {
|
|
17572
|
+
constructor(chainId, baseUrl, headers = {}) {
|
|
17545
17573
|
this.chainId = chainId;
|
|
17546
17574
|
this.baseUrl = baseUrl;
|
|
17575
|
+
this.headers = headers;
|
|
17547
17576
|
}
|
|
17548
17577
|
async append(logs) {
|
|
17549
17578
|
if (!logs.length) return;
|
|
@@ -17552,7 +17581,7 @@ var BlockLogAppender = class {
|
|
|
17552
17581
|
method: "POST",
|
|
17553
17582
|
headers: {
|
|
17554
17583
|
"Content-Type": "application/json",
|
|
17555
|
-
...
|
|
17584
|
+
...this.headers
|
|
17556
17585
|
},
|
|
17557
17586
|
body: JSON.stringify({ logs })
|
|
17558
17587
|
}).then(async (response) => {
|
|
@@ -17565,7 +17594,10 @@ var BlockLogAppender = class {
|
|
|
17565
17594
|
var Namespace = class {
|
|
17566
17595
|
constructor(options) {
|
|
17567
17596
|
this.options = options;
|
|
17568
|
-
this.indexerClient = new IndexerClient(
|
|
17597
|
+
this.indexerClient = new IndexerClient(
|
|
17598
|
+
options.indexerBaseUrl.replace(/\/+$/, ""),
|
|
17599
|
+
options.headers
|
|
17600
|
+
);
|
|
17569
17601
|
}
|
|
17570
17602
|
getAppender() {
|
|
17571
17603
|
if (!this.options.baseUrl) {
|
|
@@ -17573,7 +17605,14 @@ var Namespace = class {
|
|
|
17573
17605
|
"Missing store base URL. Provide --base-url or set PMATE_STORE_BASE_URL / BLOCKCHAIN_BASE_URL."
|
|
17574
17606
|
);
|
|
17575
17607
|
}
|
|
17576
|
-
return new BlockLogAppender(
|
|
17608
|
+
return new BlockLogAppender(
|
|
17609
|
+
this.options.chain,
|
|
17610
|
+
this.options.baseUrl.replace(/\/+$/, ""),
|
|
17611
|
+
{
|
|
17612
|
+
...this.options.headers,
|
|
17613
|
+
...this.options.proxyToken ? { "X-Proxy-Token": this.options.proxyToken } : {}
|
|
17614
|
+
}
|
|
17615
|
+
);
|
|
17577
17616
|
}
|
|
17578
17617
|
table(name) {
|
|
17579
17618
|
const descriptor = createDescriptor({
|
|
@@ -18224,6 +18263,284 @@ var RunnerCommandHandler = class {
|
|
|
18224
18263
|
}
|
|
18225
18264
|
};
|
|
18226
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
|
+
|
|
18227
18544
|
// src/commands/NsCommandHandler.ts
|
|
18228
18545
|
init_sessionStore();
|
|
18229
18546
|
var NsCommandHandler = class {
|
|
@@ -18290,8 +18607,9 @@ var NsCommandHandler = class {
|
|
|
18290
18607
|
};
|
|
18291
18608
|
|
|
18292
18609
|
// src/commands/StoreCommandHandler.ts
|
|
18293
|
-
var
|
|
18294
|
-
var
|
|
18610
|
+
var import_node_fs19 = require("fs");
|
|
18611
|
+
var import_node_path24 = __toESM(require("path"));
|
|
18612
|
+
init_sessionStore();
|
|
18295
18613
|
var StoreCommandHandler = class {
|
|
18296
18614
|
async handle(args) {
|
|
18297
18615
|
if (args.scope === "namespace") {
|
|
@@ -18382,13 +18700,21 @@ var StoreCommandHandler = class {
|
|
|
18382
18700
|
}
|
|
18383
18701
|
createNamespace(args) {
|
|
18384
18702
|
const needsWriteBaseUrl = args.scope === "table" && (args.action === "create" || args.action === "update" || args.action === "delete") || args.scope === "kv" && (args.action === "set" || args.action === "delete");
|
|
18703
|
+
const headers = this.resolveMetaAuthHeaders(args.chain);
|
|
18385
18704
|
return new Namespace({
|
|
18386
18705
|
chain: args.chain,
|
|
18387
18706
|
ns: args.namespace,
|
|
18388
18707
|
baseUrl: needsWriteBaseUrl ? this.resolveBaseUrl(args.baseUrl) : args.baseUrl,
|
|
18389
|
-
indexerBaseUrl: this.resolveIndexerBaseUrl(args.indexerBaseUrl)
|
|
18708
|
+
indexerBaseUrl: this.resolveIndexerBaseUrl(args.indexerBaseUrl),
|
|
18709
|
+
headers,
|
|
18710
|
+
proxyToken: process.env.PMATE_CHAIN_PROXY_TOKEN
|
|
18390
18711
|
});
|
|
18391
18712
|
}
|
|
18713
|
+
resolveMetaAuthHeaders(chain) {
|
|
18714
|
+
if (chain !== "meta") return void 0;
|
|
18715
|
+
const token = readRequiredSession({ preferredApp: DEFAULT_APP_ID }).token;
|
|
18716
|
+
return { Authorization: `Bearer ${token}` };
|
|
18717
|
+
}
|
|
18392
18718
|
resolveBaseUrl(baseUrl) {
|
|
18393
18719
|
const resolved = baseUrl || process.env.PMATE_STORE_BASE_URL || process.env.BLOCKCHAIN_BASE_URL;
|
|
18394
18720
|
if (!resolved) {
|
|
@@ -18424,7 +18750,10 @@ var StoreCommandHandler = class {
|
|
|
18424
18750
|
const baseUrl = this.resolveIndexerBaseUrl(args.indexerBaseUrl);
|
|
18425
18751
|
const url = new URL(`/chains/${encodeURIComponent(args.chain)}/namespaces`, `${baseUrl}/`);
|
|
18426
18752
|
const response = await fetch(url.toString(), {
|
|
18427
|
-
headers: {
|
|
18753
|
+
headers: {
|
|
18754
|
+
Accept: "application/json",
|
|
18755
|
+
...this.resolveMetaAuthHeaders(args.chain)
|
|
18756
|
+
}
|
|
18428
18757
|
});
|
|
18429
18758
|
const payload = await response.json();
|
|
18430
18759
|
if (!response.ok || !payload?.success) {
|
|
@@ -18433,11 +18762,11 @@ var StoreCommandHandler = class {
|
|
|
18433
18762
|
return payload.data ?? [];
|
|
18434
18763
|
}
|
|
18435
18764
|
readJsonFile(filePath) {
|
|
18436
|
-
const absolutePath =
|
|
18437
|
-
if (!(0,
|
|
18765
|
+
const absolutePath = import_node_path24.default.resolve(process.cwd(), filePath);
|
|
18766
|
+
if (!(0, import_node_fs19.existsSync)(absolutePath)) {
|
|
18438
18767
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
18439
18768
|
}
|
|
18440
|
-
const raw = (0,
|
|
18769
|
+
const raw = (0, import_node_fs19.readFileSync)(absolutePath, "utf8");
|
|
18441
18770
|
try {
|
|
18442
18771
|
return JSON.parse(raw);
|
|
18443
18772
|
} catch (error) {
|
|
@@ -18489,14 +18818,14 @@ var StoreCommandHandler = class {
|
|
|
18489
18818
|
};
|
|
18490
18819
|
|
|
18491
18820
|
// src/commands/AppCommandHandler.ts
|
|
18492
|
-
var
|
|
18493
|
-
var
|
|
18821
|
+
var import_node_fs21 = require("fs");
|
|
18822
|
+
var import_node_path26 = __toESM(require("path"));
|
|
18494
18823
|
init_sessionStore();
|
|
18495
18824
|
|
|
18496
18825
|
// src/appIcon.ts
|
|
18497
|
-
var
|
|
18826
|
+
var import_node_fs20 = require("fs");
|
|
18498
18827
|
var import_node_os8 = __toESM(require("os"));
|
|
18499
|
-
var
|
|
18828
|
+
var import_node_path25 = __toESM(require("path"));
|
|
18500
18829
|
var import_sharp = __toESM(require("sharp"));
|
|
18501
18830
|
init_namespacedRef();
|
|
18502
18831
|
var ANDROID_ICON_SPECS = [
|
|
@@ -18601,13 +18930,13 @@ function createAppIconExportPlans(input) {
|
|
|
18601
18930
|
if (!input.outDir) {
|
|
18602
18931
|
throw new Error("App icon preset export requires --out-dir.");
|
|
18603
18932
|
}
|
|
18604
|
-
const outDir =
|
|
18605
|
-
(0,
|
|
18933
|
+
const outDir = import_node_path25.default.resolve(input.cwd, input.outDir);
|
|
18934
|
+
(0, import_node_fs20.mkdirSync)(outDir, { recursive: true });
|
|
18606
18935
|
return specs.map((spec) => ({
|
|
18607
18936
|
width: spec.width,
|
|
18608
18937
|
height: spec.height,
|
|
18609
18938
|
format: "png",
|
|
18610
|
-
outputPath:
|
|
18939
|
+
outputPath: import_node_path25.default.join(
|
|
18611
18940
|
outDir,
|
|
18612
18941
|
`${namespace}-${objectId}-${spec.name}-${spec.width}x${spec.height}.png`
|
|
18613
18942
|
)
|
|
@@ -18620,8 +18949,8 @@ function createAppIconExportPlans(input) {
|
|
|
18620
18949
|
if (!input.output) {
|
|
18621
18950
|
throw new Error("Single-size app icon export requires --output.");
|
|
18622
18951
|
}
|
|
18623
|
-
const resolvedOutput =
|
|
18624
|
-
(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 });
|
|
18625
18954
|
return [
|
|
18626
18955
|
{
|
|
18627
18956
|
width: input.width,
|
|
@@ -18635,7 +18964,7 @@ async function exportAppIcon(icon, plans) {
|
|
|
18635
18964
|
const svg = await resolveAppIconSvg(icon);
|
|
18636
18965
|
for (const plan of plans) {
|
|
18637
18966
|
const bytes = await renderAppIcon(svg, plan.width, plan.height, plan.format);
|
|
18638
|
-
(0,
|
|
18967
|
+
(0, import_node_fs20.writeFileSync)(plan.outputPath, bytes);
|
|
18639
18968
|
}
|
|
18640
18969
|
}
|
|
18641
18970
|
async function renderAppIconVariant(input) {
|
|
@@ -18643,9 +18972,9 @@ async function renderAppIconVariant(input) {
|
|
|
18643
18972
|
const bytes = await renderAppIcon(svg, input.width, input.height, input.format);
|
|
18644
18973
|
let outputPath;
|
|
18645
18974
|
if (input.output) {
|
|
18646
|
-
outputPath =
|
|
18647
|
-
(0,
|
|
18648
|
-
(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);
|
|
18649
18978
|
}
|
|
18650
18979
|
if (input.name) {
|
|
18651
18980
|
return {
|
|
@@ -18666,7 +18995,7 @@ async function renderAppIconVariant(input) {
|
|
|
18666
18995
|
};
|
|
18667
18996
|
}
|
|
18668
18997
|
async function loadAppIconVariantFile(input) {
|
|
18669
|
-
const absolutePath =
|
|
18998
|
+
const absolutePath = import_node_path25.default.resolve(input.cwd, input.filePath);
|
|
18670
18999
|
const format = inferVariantFormatFromPath(absolutePath);
|
|
18671
19000
|
return {
|
|
18672
19001
|
value: input.name ? await uploadAppIconVariantAsset({
|
|
@@ -18675,7 +19004,7 @@ async function loadAppIconVariantFile(input) {
|
|
|
18675
19004
|
name: input.name,
|
|
18676
19005
|
format,
|
|
18677
19006
|
sourcePath: absolutePath
|
|
18678
|
-
}) : createImageDataUrl((0,
|
|
19007
|
+
}) : createImageDataUrl((0, import_node_fs20.readFileSync)(absolutePath), format),
|
|
18679
19008
|
format,
|
|
18680
19009
|
absolutePath
|
|
18681
19010
|
};
|
|
@@ -18734,7 +19063,7 @@ function shouldAutoGenerateDefaultVariant(icon) {
|
|
|
18734
19063
|
return looksLikeSvgMarkup(icon) || looksLikeSvgUrl(icon);
|
|
18735
19064
|
}
|
|
18736
19065
|
function inferVariantFormatFromPath(filePath) {
|
|
18737
|
-
const ext =
|
|
19066
|
+
const ext = import_node_path25.default.extname(filePath).toLowerCase();
|
|
18738
19067
|
switch (ext) {
|
|
18739
19068
|
case ".png":
|
|
18740
19069
|
return "png";
|
|
@@ -18805,13 +19134,13 @@ async function uploadAppIconVariantAsset(input) {
|
|
|
18805
19134
|
await AliyunService.uploadFile(sourcePath, DEFAULT_APP_ICON_VARIANT_BUCKET, objectKey);
|
|
18806
19135
|
} finally {
|
|
18807
19136
|
if (shouldCleanup) {
|
|
18808
|
-
(0,
|
|
19137
|
+
(0, import_node_fs20.rmSync)(import_node_path25.default.dirname(sourcePath), { recursive: true, force: true });
|
|
18809
19138
|
}
|
|
18810
19139
|
}
|
|
18811
19140
|
return `${DEFAULT_APP_ICON_VARIANT_PUBLIC_BASE_URL}/${objectKey}`;
|
|
18812
19141
|
}
|
|
18813
19142
|
function buildAppIconVariantObjectKey(input) {
|
|
18814
|
-
return
|
|
19143
|
+
return import_node_path25.default.posix.join(
|
|
18815
19144
|
"apps",
|
|
18816
19145
|
`${resolveAppIconAssetStem(input.icon, input.appRef)}-${input.name}.${extensionForIconFormat(input.format)}`
|
|
18817
19146
|
);
|
|
@@ -18820,8 +19149,8 @@ function resolveAppIconAssetStem(icon, appRef) {
|
|
|
18820
19149
|
if (icon) {
|
|
18821
19150
|
try {
|
|
18822
19151
|
const url = new URL(icon);
|
|
18823
|
-
const ext =
|
|
18824
|
-
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);
|
|
18825
19154
|
const normalized = sanitizeAppIconAssetStem(basename);
|
|
18826
19155
|
if (normalized) {
|
|
18827
19156
|
return normalized;
|
|
@@ -18850,9 +19179,9 @@ function writeTempAppIconVariantFile(objectKey, format, bytes) {
|
|
|
18850
19179
|
if (!bytes) {
|
|
18851
19180
|
throw new Error("App icon variant upload requires bytes or a source file.");
|
|
18852
19181
|
}
|
|
18853
|
-
const tempDir = (0,
|
|
18854
|
-
const tempPath =
|
|
18855
|
-
(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);
|
|
18856
19185
|
return tempPath;
|
|
18857
19186
|
}
|
|
18858
19187
|
|
|
@@ -19061,10 +19390,10 @@ var AppCommandHandler = class {
|
|
|
19061
19390
|
}
|
|
19062
19391
|
readJsonFile(filePath) {
|
|
19063
19392
|
const absolutePath = this.resolveFilePath(filePath);
|
|
19064
|
-
if (!(0,
|
|
19393
|
+
if (!(0, import_node_fs21.existsSync)(absolutePath)) {
|
|
19065
19394
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
19066
19395
|
}
|
|
19067
|
-
const raw = (0,
|
|
19396
|
+
const raw = (0, import_node_fs21.readFileSync)(absolutePath, "utf8");
|
|
19068
19397
|
try {
|
|
19069
19398
|
return JSON.parse(raw);
|
|
19070
19399
|
} catch (error) {
|
|
@@ -19074,10 +19403,10 @@ var AppCommandHandler = class {
|
|
|
19074
19403
|
}
|
|
19075
19404
|
async preparePayload(filePath, appRef) {
|
|
19076
19405
|
const absolutePath = this.resolveFilePath(filePath);
|
|
19077
|
-
return prepareAppPayload(this.readJsonFile(filePath),
|
|
19406
|
+
return prepareAppPayload(this.readJsonFile(filePath), import_node_path26.default.dirname(absolutePath), { appRef });
|
|
19078
19407
|
}
|
|
19079
19408
|
resolveFilePath(filePath) {
|
|
19080
|
-
return
|
|
19409
|
+
return import_node_path26.default.resolve(process.cwd(), filePath);
|
|
19081
19410
|
}
|
|
19082
19411
|
async request(baseUrl, token, method, pathname, body) {
|
|
19083
19412
|
const response = await fetch(`${baseUrl}${pathname}`, {
|
|
@@ -19197,18 +19526,18 @@ function readNamespaceFromPayload(payload) {
|
|
|
19197
19526
|
}
|
|
19198
19527
|
|
|
19199
19528
|
// src/commands/ServiceCommandHandler.ts
|
|
19200
|
-
var
|
|
19529
|
+
var import_node_fs24 = require("fs");
|
|
19201
19530
|
var import_promises5 = require("fs/promises");
|
|
19202
|
-
var
|
|
19531
|
+
var import_node_path29 = __toESM(require("path"));
|
|
19203
19532
|
var import_node_child_process11 = require("child_process");
|
|
19204
19533
|
var import_promises6 = require("readline/promises");
|
|
19205
19534
|
|
|
19206
19535
|
// src/services/AndroidApkReleaseService.ts
|
|
19207
19536
|
var import_node_child_process9 = require("child_process");
|
|
19208
19537
|
var import_node_crypto4 = require("crypto");
|
|
19209
|
-
var
|
|
19538
|
+
var import_node_fs22 = require("fs");
|
|
19210
19539
|
var import_node_os9 = __toESM(require("os"));
|
|
19211
|
-
var
|
|
19540
|
+
var import_node_path27 = __toESM(require("path"));
|
|
19212
19541
|
var ANDROID_APK_BUCKET = "parrot-static";
|
|
19213
19542
|
var ANDROID_APK_PUBLIC_BASE_URL = "https://parrot-static.pmate.chat";
|
|
19214
19543
|
var AndroidApkReleaseService = class {
|
|
@@ -19242,7 +19571,7 @@ var AndroidApkReleaseService = class {
|
|
|
19242
19571
|
}
|
|
19243
19572
|
await AliyunService.uploadFile(apkPath, ANDROID_APK_BUCKET, objectKey);
|
|
19244
19573
|
const sha256 = await sha256File(apkPath);
|
|
19245
|
-
const size = (0,
|
|
19574
|
+
const size = (0, import_node_fs22.statSync)(apkPath).size;
|
|
19246
19575
|
const artifact = {
|
|
19247
19576
|
serviceId: service.id,
|
|
19248
19577
|
env: options.env,
|
|
@@ -19276,15 +19605,15 @@ var AndroidApkReleaseService = class {
|
|
|
19276
19605
|
minimumVersionCode: options.minimumVersionCode
|
|
19277
19606
|
});
|
|
19278
19607
|
const objectKey = buildAndroidLatestManifestObjectKey(service.namespace, service.name);
|
|
19279
|
-
const tempDir = (0,
|
|
19280
|
-
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");
|
|
19281
19610
|
try {
|
|
19282
|
-
(0,
|
|
19611
|
+
(0, import_node_fs22.writeFileSync)(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
19283
19612
|
`);
|
|
19284
19613
|
await AliyunService.uploadFile(manifestPath, ANDROID_APK_BUCKET, objectKey);
|
|
19285
19614
|
ui.success(`Published Android update manifest ${ANDROID_APK_PUBLIC_BASE_URL}/${objectKey}`);
|
|
19286
19615
|
} finally {
|
|
19287
|
-
(0,
|
|
19616
|
+
(0, import_node_fs22.rmSync)(tempDir, { recursive: true, force: true });
|
|
19288
19617
|
}
|
|
19289
19618
|
}
|
|
19290
19619
|
async list(service, options) {
|
|
@@ -19300,7 +19629,7 @@ var AndroidApkReleaseService = class {
|
|
|
19300
19629
|
const prefix = `apks/${service.namespace}/${service.name}`;
|
|
19301
19630
|
const objects = await AliyunService.listObjects(ANDROID_APK_BUCKET, prefix);
|
|
19302
19631
|
return objects.filter((item) => item.name.endsWith(".apk")).map((item) => {
|
|
19303
|
-
const versionName =
|
|
19632
|
+
const versionName = import_node_path27.default.basename(item.name, ".apk");
|
|
19304
19633
|
return {
|
|
19305
19634
|
serviceId,
|
|
19306
19635
|
env: options.env ?? "unknown",
|
|
@@ -19323,7 +19652,7 @@ var AndroidApkReleaseService = class {
|
|
|
19323
19652
|
}
|
|
19324
19653
|
}
|
|
19325
19654
|
resolveRepoRoot(service, cwd) {
|
|
19326
|
-
if (cwd) return
|
|
19655
|
+
if (cwd) return import_node_path27.default.resolve(process.cwd(), cwd);
|
|
19327
19656
|
const repository = this.getRepository(service);
|
|
19328
19657
|
if (repository) {
|
|
19329
19658
|
return resolveRepositoryLocalRoot(repository);
|
|
@@ -19335,8 +19664,8 @@ var AndroidApkReleaseService = class {
|
|
|
19335
19664
|
if (!dir) {
|
|
19336
19665
|
throw new Error(`Missing dir for android service ${service.id}`);
|
|
19337
19666
|
}
|
|
19338
|
-
const appDir =
|
|
19339
|
-
if (!(0,
|
|
19667
|
+
const appDir = import_node_path27.default.resolve(repoRoot, dir);
|
|
19668
|
+
if (!(0, import_node_fs22.existsSync)(appDir)) {
|
|
19340
19669
|
throw new Error(`Android app dir not found: ${appDir}`);
|
|
19341
19670
|
}
|
|
19342
19671
|
return appDir;
|
|
@@ -19352,11 +19681,11 @@ var AndroidApkReleaseService = class {
|
|
|
19352
19681
|
return void 0;
|
|
19353
19682
|
}
|
|
19354
19683
|
async runGradleAssembleAndFindApk(repoRoot, appDir, variant) {
|
|
19355
|
-
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));
|
|
19356
19685
|
if (!gradlew) {
|
|
19357
19686
|
throw new Error(`Gradle wrapper not found in ${appDir} or ${repoRoot}`);
|
|
19358
19687
|
}
|
|
19359
|
-
const gradleCwd =
|
|
19688
|
+
const gradleCwd = import_node_path27.default.dirname(gradlew);
|
|
19360
19689
|
const normalizedVariant = variant.toLowerCase();
|
|
19361
19690
|
const taskSuffix = `assemble${capitalize(normalizedVariant)}`;
|
|
19362
19691
|
const tasks = [`:app:${taskSuffix}`, taskSuffix];
|
|
@@ -19444,7 +19773,7 @@ function resolveRepositoryLocalRoot(repository) {
|
|
|
19444
19773
|
if (!repoName) {
|
|
19445
19774
|
throw new Error(`Invalid repository: ${repository}`);
|
|
19446
19775
|
}
|
|
19447
|
-
return
|
|
19776
|
+
return import_node_path27.default.join(import_node_os9.default.homedir(), "dev", "pmate", repoName);
|
|
19448
19777
|
}
|
|
19449
19778
|
function bumpAndroidGradleVersionText(source, bump) {
|
|
19450
19779
|
const versionNameMatch = source.match(/(^\s*versionName\s+["'])([^"']+)(["']\s*$)/m) ?? source.match(/(^\s*versionName\s*=\s*["'])([^"']+)(["']\s*$)/m);
|
|
@@ -19500,42 +19829,42 @@ function parseGradleOutputMetadata(source, apkFileName) {
|
|
|
19500
19829
|
}
|
|
19501
19830
|
function bumpAndroidProjectVersion(appDir, bump) {
|
|
19502
19831
|
const candidates = [
|
|
19503
|
-
|
|
19504
|
-
|
|
19505
|
-
|
|
19506
|
-
|
|
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")
|
|
19507
19836
|
];
|
|
19508
19837
|
for (const candidate of candidates) {
|
|
19509
|
-
if (!(0,
|
|
19510
|
-
const result = bumpAndroidGradleVersionText((0,
|
|
19511
|
-
(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);
|
|
19512
19841
|
return { filePath: candidate, ...result };
|
|
19513
19842
|
}
|
|
19514
19843
|
throw new Error(`No Android Gradle version file found under ${appDir}`);
|
|
19515
19844
|
}
|
|
19516
19845
|
function findLatestApk(repoRoot, appDir, variant) {
|
|
19517
19846
|
const dirs = [
|
|
19518
|
-
|
|
19519
|
-
|
|
19520
|
-
|
|
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)
|
|
19521
19850
|
];
|
|
19522
19851
|
const files = dirs.flatMap((dir) => listApks(dir));
|
|
19523
19852
|
if (files.length === 0) {
|
|
19524
19853
|
throw new Error(`Cannot find APK output for variant ${variant}`);
|
|
19525
19854
|
}
|
|
19526
|
-
files.sort((a, b) => (0,
|
|
19855
|
+
files.sort((a, b) => (0, import_node_fs22.statSync)(b).mtimeMs - (0, import_node_fs22.statSync)(a).mtimeMs);
|
|
19527
19856
|
return files[0];
|
|
19528
19857
|
}
|
|
19529
19858
|
function readGradleOutputMetadata(apkPath) {
|
|
19530
|
-
const metadataPath =
|
|
19531
|
-
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)) {
|
|
19532
19861
|
throw new Error(`Gradle output metadata not found: ${metadataPath}`);
|
|
19533
19862
|
}
|
|
19534
|
-
return parseGradleOutputMetadata((0,
|
|
19863
|
+
return parseGradleOutputMetadata((0, import_node_fs22.readFileSync)(metadataPath, "utf8"), import_node_path27.default.basename(apkPath));
|
|
19535
19864
|
}
|
|
19536
19865
|
function listApks(dir) {
|
|
19537
|
-
if (!(0,
|
|
19538
|
-
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());
|
|
19539
19868
|
}
|
|
19540
19869
|
function runCommand(command, args, cwd) {
|
|
19541
19870
|
return new Promise((resolve, reject) => {
|
|
@@ -19569,26 +19898,26 @@ async function runAndroidSdkToolCapture(toolName, args) {
|
|
|
19569
19898
|
return runCommandCapture(toolPath, args);
|
|
19570
19899
|
}
|
|
19571
19900
|
function findAndroidSdkTool(toolName) {
|
|
19572
|
-
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));
|
|
19573
19902
|
for (const sdkRoot of sdkRoots) {
|
|
19574
|
-
const candidates = toolName === "aapt" ? listVersionedToolCandidates(
|
|
19575
|
-
|
|
19576
|
-
...listVersionedToolCandidates(
|
|
19577
|
-
|
|
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)
|
|
19578
19907
|
];
|
|
19579
|
-
const match = candidates.find((candidate) => (0,
|
|
19908
|
+
const match = candidates.find((candidate) => (0, import_node_fs22.existsSync)(candidate));
|
|
19580
19909
|
if (match) return match;
|
|
19581
19910
|
}
|
|
19582
19911
|
return void 0;
|
|
19583
19912
|
}
|
|
19584
19913
|
function listVersionedToolCandidates(parentDir, relativeToolPath) {
|
|
19585
|
-
if (!(0,
|
|
19586
|
-
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));
|
|
19587
19916
|
}
|
|
19588
19917
|
function sha256File(filePath) {
|
|
19589
19918
|
return new Promise((resolve, reject) => {
|
|
19590
19919
|
const hash = (0, import_node_crypto4.createHash)("sha256");
|
|
19591
|
-
const stream = (0,
|
|
19920
|
+
const stream = (0, import_node_fs22.createReadStream)(filePath);
|
|
19592
19921
|
stream.on("data", (chunk) => hash.update(chunk));
|
|
19593
19922
|
stream.on("error", reject);
|
|
19594
19923
|
stream.on("end", () => resolve(hash.digest("hex")));
|
|
@@ -19605,9 +19934,9 @@ function capitalize(value) {
|
|
|
19605
19934
|
}
|
|
19606
19935
|
|
|
19607
19936
|
// src/services/ServiceRuntimeRunner.ts
|
|
19608
|
-
var
|
|
19937
|
+
var import_node_fs23 = require("fs");
|
|
19609
19938
|
var import_node_os10 = __toESM(require("os"));
|
|
19610
|
-
var
|
|
19939
|
+
var import_node_path28 = __toESM(require("path"));
|
|
19611
19940
|
var import_node_child_process10 = require("child_process");
|
|
19612
19941
|
var import_node_readline = require("readline");
|
|
19613
19942
|
var import_chalk3 = __toESM(require("chalk"));
|
|
@@ -20097,14 +20426,14 @@ var ServiceRuntimeRunner = class {
|
|
|
20097
20426
|
}
|
|
20098
20427
|
resolveRepoRoot(service, cwd) {
|
|
20099
20428
|
if (cwd) {
|
|
20100
|
-
return
|
|
20429
|
+
return import_node_path28.default.resolve(process.cwd(), cwd);
|
|
20101
20430
|
}
|
|
20102
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();
|
|
20103
20432
|
if (repository) {
|
|
20104
20433
|
const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
|
|
20105
20434
|
if (repoName) {
|
|
20106
|
-
const candidate =
|
|
20107
|
-
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)) {
|
|
20108
20437
|
return candidate;
|
|
20109
20438
|
}
|
|
20110
20439
|
}
|
|
@@ -20117,13 +20446,13 @@ var ServiceRuntimeRunner = class {
|
|
|
20117
20446
|
if (!dir) {
|
|
20118
20447
|
throw new Error(`Missing service dir for ${service.id}`);
|
|
20119
20448
|
}
|
|
20120
|
-
return
|
|
20449
|
+
return import_node_path28.default.resolve(repoRoot, dir);
|
|
20121
20450
|
}
|
|
20122
20451
|
async deployVite(service, options) {
|
|
20123
20452
|
this.assertDeployableStaticSite(service);
|
|
20124
20453
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20125
|
-
const packageJsonPath =
|
|
20126
|
-
if (!(0,
|
|
20454
|
+
const packageJsonPath = import_node_path28.default.join(appDir, "package.json");
|
|
20455
|
+
if (!(0, import_node_fs23.existsSync)(packageJsonPath)) {
|
|
20127
20456
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20128
20457
|
}
|
|
20129
20458
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -20138,8 +20467,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20138
20467
|
this.resolveRepoRoot(service, options.cwd),
|
|
20139
20468
|
buildEnv
|
|
20140
20469
|
);
|
|
20141
|
-
const distDir =
|
|
20142
|
-
if (!(0,
|
|
20470
|
+
const distDir = import_node_path28.default.join(appDir, "dist");
|
|
20471
|
+
if (!(0, import_node_fs23.existsSync)(distDir)) {
|
|
20143
20472
|
throw new Error(`No dist directory found at ${distDir}`);
|
|
20144
20473
|
}
|
|
20145
20474
|
const site = this.getSite(service);
|
|
@@ -20152,8 +20481,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20152
20481
|
async deployStatic(service, options) {
|
|
20153
20482
|
this.assertDeployableStaticSite(service);
|
|
20154
20483
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20155
|
-
const srcDir =
|
|
20156
|
-
if (!(0,
|
|
20484
|
+
const srcDir = import_node_path28.default.join(appDir, "src");
|
|
20485
|
+
if (!(0, import_node_fs23.existsSync)(srcDir)) {
|
|
20157
20486
|
throw new Error(`No src directory found at ${srcDir}`);
|
|
20158
20487
|
}
|
|
20159
20488
|
const site = this.getSite(service);
|
|
@@ -20187,8 +20516,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20187
20516
|
this.validateFcConfig(service, fc);
|
|
20188
20517
|
const repoRoot = this.resolveRepoRoot(service);
|
|
20189
20518
|
const appDir = this.resolveLocalDir(service);
|
|
20190
|
-
const packageJsonPath =
|
|
20191
|
-
if (!(0,
|
|
20519
|
+
const packageJsonPath = import_node_path28.default.join(appDir, "package.json");
|
|
20520
|
+
if (!(0, import_node_fs23.existsSync)(packageJsonPath)) {
|
|
20192
20521
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20193
20522
|
}
|
|
20194
20523
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -20241,15 +20570,15 @@ var ServiceRuntimeRunner = class {
|
|
|
20241
20570
|
const repoRoot = this.resolveRepoRoot(service, options.cwd);
|
|
20242
20571
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20243
20572
|
await this.ensurePnpmWorkspaceRoot(repoRoot);
|
|
20244
|
-
const configPath =
|
|
20245
|
-
if (!(0,
|
|
20573
|
+
const configPath = import_node_path28.default.join(appDir, fc.configFile ?? "s.yaml");
|
|
20574
|
+
if (!(0, import_node_fs23.existsSync)(configPath)) {
|
|
20246
20575
|
throw new Error(`Missing FC config file at ${configPath}`);
|
|
20247
20576
|
}
|
|
20248
|
-
const packageJsonPath =
|
|
20249
|
-
if (!(0,
|
|
20577
|
+
const packageJsonPath = import_node_path28.default.join(appDir, "package.json");
|
|
20578
|
+
if (!(0, import_node_fs23.existsSync)(packageJsonPath)) {
|
|
20250
20579
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
20251
20580
|
}
|
|
20252
|
-
const rawConfig = (0,
|
|
20581
|
+
const rawConfig = (0, import_node_fs23.readFileSync)(configPath, "utf8");
|
|
20253
20582
|
if (!rawConfig.includes(fc.functionName)) {
|
|
20254
20583
|
throw new Error(`FC config ${configPath} does not mention functionName ${fc.functionName}`);
|
|
20255
20584
|
}
|
|
@@ -20527,7 +20856,7 @@ var ServiceRuntimeRunner = class {
|
|
|
20527
20856
|
const serverAddress = await resolveServerAddress(server);
|
|
20528
20857
|
const templateName = exposeType === "websocket" ? "nginx.ws.template" : "nginx.rest.template";
|
|
20529
20858
|
const templatePath = this.resolveTemplatePath(templateName);
|
|
20530
|
-
const template = (0,
|
|
20859
|
+
const template = (0, import_node_fs23.readFileSync)(templatePath, "utf8");
|
|
20531
20860
|
const host = `${subdomain}.${("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat"}`;
|
|
20532
20861
|
const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
|
|
20533
20862
|
const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
|
|
@@ -20559,11 +20888,11 @@ var ServiceRuntimeRunner = class {
|
|
|
20559
20888
|
}
|
|
20560
20889
|
if (config.ensurePackageJson) {
|
|
20561
20890
|
const appDir = this.resolveLocalDir(service, options.cwd);
|
|
20562
|
-
const packageJsonPath =
|
|
20563
|
-
if (!(0,
|
|
20891
|
+
const packageJsonPath = import_node_path28.default.join(appDir, "package.json");
|
|
20892
|
+
if (!(0, import_node_fs23.existsSync)(packageJsonPath)) {
|
|
20564
20893
|
throw new Error(`Missing package.json at ${packageJsonPath}`);
|
|
20565
20894
|
}
|
|
20566
|
-
const pkgStat = (0,
|
|
20895
|
+
const pkgStat = (0, import_node_fs23.statSync)(packageJsonPath);
|
|
20567
20896
|
if (!pkgStat.isFile()) {
|
|
20568
20897
|
throw new Error(`package.json is not a file at ${packageJsonPath}`);
|
|
20569
20898
|
}
|
|
@@ -20992,9 +21321,9 @@ var ServiceRuntimeRunner = class {
|
|
|
20992
21321
|
return tokens;
|
|
20993
21322
|
}
|
|
20994
21323
|
readPathValue(source, pathExpr) {
|
|
20995
|
-
const
|
|
21324
|
+
const path34 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
|
|
20996
21325
|
let cursor = source;
|
|
20997
|
-
for (const segment of
|
|
21326
|
+
for (const segment of path34) {
|
|
20998
21327
|
if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
|
|
20999
21328
|
return void 0;
|
|
21000
21329
|
}
|
|
@@ -21037,12 +21366,12 @@ var ServiceRuntimeRunner = class {
|
|
|
21037
21366
|
}
|
|
21038
21367
|
resolveTemplatePath(templateName) {
|
|
21039
21368
|
const candidates = [
|
|
21040
|
-
|
|
21041
|
-
|
|
21042
|
-
|
|
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)
|
|
21043
21372
|
];
|
|
21044
21373
|
for (const candidate of candidates) {
|
|
21045
|
-
if ((0,
|
|
21374
|
+
if ((0, import_node_fs23.existsSync)(candidate)) {
|
|
21046
21375
|
return candidate;
|
|
21047
21376
|
}
|
|
21048
21377
|
}
|
|
@@ -21074,7 +21403,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21074
21403
|
});
|
|
21075
21404
|
}
|
|
21076
21405
|
loadPackageJson(packageJsonPath) {
|
|
21077
|
-
const raw = (0,
|
|
21406
|
+
const raw = (0, import_node_fs23.readFileSync)(packageJsonPath, "utf8");
|
|
21078
21407
|
const parsed = JSON.parse(raw);
|
|
21079
21408
|
if (!parsed || typeof parsed !== "object") {
|
|
21080
21409
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -21083,7 +21412,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21083
21412
|
}
|
|
21084
21413
|
writePackageJson(packageJsonPath, data) {
|
|
21085
21414
|
const serialized = JSON.stringify(data, null, 2);
|
|
21086
|
-
(0,
|
|
21415
|
+
(0, import_node_fs23.writeFileSync)(packageJsonPath, `${serialized}
|
|
21087
21416
|
`, "utf8");
|
|
21088
21417
|
}
|
|
21089
21418
|
validateFcConfig(service, fc) {
|
|
@@ -21110,8 +21439,8 @@ var ServiceRuntimeRunner = class {
|
|
|
21110
21439
|
}
|
|
21111
21440
|
}
|
|
21112
21441
|
async ensurePnpmWorkspaceRoot(repoRoot) {
|
|
21113
|
-
const workspacePath =
|
|
21114
|
-
if (!(0,
|
|
21442
|
+
const workspacePath = import_node_path28.default.join(repoRoot, "pnpm-workspace.yaml");
|
|
21443
|
+
if (!(0, import_node_fs23.existsSync)(workspacePath)) {
|
|
21115
21444
|
throw new Error(`Missing pnpm-workspace.yaml at ${workspacePath}`);
|
|
21116
21445
|
}
|
|
21117
21446
|
}
|
|
@@ -21185,16 +21514,16 @@ var ServiceRuntimeRunner = class {
|
|
|
21185
21514
|
if (!privateKeyPath) {
|
|
21186
21515
|
throw new Error("Missing ssl.prv in ~/.pmate/config.yaml.");
|
|
21187
21516
|
}
|
|
21188
|
-
if (!(0,
|
|
21517
|
+
if (!(0, import_node_fs23.existsSync)(certificatePath)) {
|
|
21189
21518
|
throw new Error(`SSL certificate file not found: ${certificatePath}`);
|
|
21190
21519
|
}
|
|
21191
|
-
if (!(0,
|
|
21520
|
+
if (!(0, import_node_fs23.existsSync)(privateKeyPath)) {
|
|
21192
21521
|
throw new Error(`SSL private key file not found: ${privateKeyPath}`);
|
|
21193
21522
|
}
|
|
21194
21523
|
return {
|
|
21195
21524
|
certName: host,
|
|
21196
|
-
certificate: (0,
|
|
21197
|
-
privateKey: (0,
|
|
21525
|
+
certificate: (0, import_node_fs23.readFileSync)(certificatePath, "utf8"),
|
|
21526
|
+
privateKey: (0, import_node_fs23.readFileSync)(privateKeyPath, "utf8")
|
|
21198
21527
|
};
|
|
21199
21528
|
}
|
|
21200
21529
|
resolveFcProtocol(fc, certConfig) {
|
|
@@ -21653,7 +21982,7 @@ var ServiceCommandHandler = class {
|
|
|
21653
21982
|
format: "dotenv"
|
|
21654
21983
|
}
|
|
21655
21984
|
);
|
|
21656
|
-
const outputPath =
|
|
21985
|
+
const outputPath = import_node_path29.default.resolve(process.cwd(), args.output);
|
|
21657
21986
|
await (0, import_promises5.writeFile)(outputPath, payload.content, "utf8");
|
|
21658
21987
|
ui.success(`Wrote env file for ${args.appId} to ${outputPath}`);
|
|
21659
21988
|
this.renderJson({ ...payload, output: outputPath }, args.json);
|
|
@@ -21879,11 +22208,11 @@ var ServiceCommandHandler = class {
|
|
|
21879
22208
|
return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
|
|
21880
22209
|
}
|
|
21881
22210
|
readJsonFile(filePath) {
|
|
21882
|
-
const absolutePath =
|
|
21883
|
-
if (!(0,
|
|
22211
|
+
const absolutePath = import_node_path29.default.resolve(process.cwd(), filePath);
|
|
22212
|
+
if (!(0, import_node_fs24.existsSync)(absolutePath)) {
|
|
21884
22213
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
21885
22214
|
}
|
|
21886
|
-
const raw = (0,
|
|
22215
|
+
const raw = (0, import_node_fs24.readFileSync)(absolutePath, "utf8");
|
|
21887
22216
|
try {
|
|
21888
22217
|
return JSON.parse(raw);
|
|
21889
22218
|
} catch (error) {
|
|
@@ -22691,9 +23020,9 @@ var RoleCommandHandler = class {
|
|
|
22691
23020
|
};
|
|
22692
23021
|
|
|
22693
23022
|
// src/commands/AccountCommandHandler.ts
|
|
22694
|
-
var
|
|
23023
|
+
var import_node_fs25 = require("fs");
|
|
22695
23024
|
var import_node_crypto5 = require("crypto");
|
|
22696
|
-
var
|
|
23025
|
+
var import_node_path30 = __toESM(require("path"));
|
|
22697
23026
|
init_sessionStore();
|
|
22698
23027
|
var AccountCommandHandler = class {
|
|
22699
23028
|
async handle(args) {
|
|
@@ -22701,9 +23030,9 @@ var AccountCommandHandler = class {
|
|
|
22701
23030
|
case "bot-keygen": {
|
|
22702
23031
|
const keyFile = this.generateBotKeyFile(args.app, args.name);
|
|
22703
23032
|
const outPath = args.out ? this.resolveFilePath(args.out) : this.resolveDefaultBotKeyPath(args.app, args.name);
|
|
22704
|
-
(0,
|
|
22705
|
-
(0,
|
|
22706
|
-
(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);
|
|
22707
23036
|
if (!args.json) {
|
|
22708
23037
|
ui.success(`Bot key saved to ${outPath}`);
|
|
22709
23038
|
}
|
|
@@ -23239,10 +23568,10 @@ var AccountCommandHandler = class {
|
|
|
23239
23568
|
throw new Error("Missing visible apps input");
|
|
23240
23569
|
}
|
|
23241
23570
|
const absolutePath = this.resolveFilePath(args.filePath);
|
|
23242
|
-
if (!(0,
|
|
23571
|
+
if (!(0, import_node_fs25.existsSync)(absolutePath)) {
|
|
23243
23572
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23244
23573
|
}
|
|
23245
|
-
const raw = (0,
|
|
23574
|
+
const raw = (0, import_node_fs25.readFileSync)(absolutePath, "utf8");
|
|
23246
23575
|
let parsed;
|
|
23247
23576
|
try {
|
|
23248
23577
|
parsed = JSON.parse(raw);
|
|
@@ -23256,13 +23585,13 @@ var AccountCommandHandler = class {
|
|
|
23256
23585
|
return parsed;
|
|
23257
23586
|
}
|
|
23258
23587
|
resolveFilePath(filePath) {
|
|
23259
|
-
return
|
|
23588
|
+
return import_node_path30.default.resolve(process.cwd(), filePath);
|
|
23260
23589
|
}
|
|
23261
23590
|
resolveDefaultBotKeyPath(app, name) {
|
|
23262
|
-
return
|
|
23591
|
+
return import_node_path30.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
|
|
23263
23592
|
}
|
|
23264
23593
|
resolveDefaultAccessKeyPath(app, name) {
|
|
23265
|
-
return
|
|
23594
|
+
return import_node_path30.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
|
|
23266
23595
|
}
|
|
23267
23596
|
homeDir() {
|
|
23268
23597
|
return process.env.HOME || process.env.USERPROFILE || process.cwd();
|
|
@@ -23285,10 +23614,10 @@ var AccountCommandHandler = class {
|
|
|
23285
23614
|
throw new Error("Missing bot key file");
|
|
23286
23615
|
}
|
|
23287
23616
|
const absolutePath = this.resolveFilePath(filePath);
|
|
23288
|
-
if (!(0,
|
|
23617
|
+
if (!(0, import_node_fs25.existsSync)(absolutePath)) {
|
|
23289
23618
|
throw new Error(`Bot key file not found: ${absolutePath}`);
|
|
23290
23619
|
}
|
|
23291
|
-
const parsed = JSON.parse((0,
|
|
23620
|
+
const parsed = JSON.parse((0, import_node_fs25.readFileSync)(absolutePath, "utf8"));
|
|
23292
23621
|
if (parsed.type !== "pmate-bot-key" || parsed.version !== 1 || parsed.algorithm !== "ed25519" || !parsed.publicKey || !parsed.privateKey) {
|
|
23293
23622
|
throw new Error(`Invalid PMate bot key file: ${absolutePath}`);
|
|
23294
23623
|
}
|
|
@@ -23305,10 +23634,10 @@ var AccountCommandHandler = class {
|
|
|
23305
23634
|
throw new Error("Missing access key file");
|
|
23306
23635
|
}
|
|
23307
23636
|
const absolutePath = this.resolveFilePath(filePath);
|
|
23308
|
-
if (!(0,
|
|
23637
|
+
if (!(0, import_node_fs25.existsSync)(absolutePath)) {
|
|
23309
23638
|
throw new Error(`Access key file not found: ${absolutePath}`);
|
|
23310
23639
|
}
|
|
23311
|
-
const parsed = JSON.parse((0,
|
|
23640
|
+
const parsed = JSON.parse((0, import_node_fs25.readFileSync)(absolutePath, "utf8"));
|
|
23312
23641
|
if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
|
|
23313
23642
|
throw new Error(`Invalid PMate access key file: ${absolutePath}`);
|
|
23314
23643
|
}
|
|
@@ -23330,9 +23659,9 @@ var AccountCommandHandler = class {
|
|
|
23330
23659
|
createdAt: result.key.createdAt
|
|
23331
23660
|
};
|
|
23332
23661
|
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
|
|
23333
|
-
(0,
|
|
23334
|
-
(0,
|
|
23335
|
-
(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);
|
|
23336
23665
|
}
|
|
23337
23666
|
renderAccessKeyCreateResult(result, asJson, out) {
|
|
23338
23667
|
if (asJson) {
|
|
@@ -23417,8 +23746,8 @@ function encodePathSegment2(value) {
|
|
|
23417
23746
|
}
|
|
23418
23747
|
|
|
23419
23748
|
// src/commands/OrgCommandHandler.ts
|
|
23420
|
-
var
|
|
23421
|
-
var
|
|
23749
|
+
var import_node_fs26 = require("fs");
|
|
23750
|
+
var import_node_path31 = __toESM(require("path"));
|
|
23422
23751
|
init_sessionStore();
|
|
23423
23752
|
var OrgCommandHandler = class {
|
|
23424
23753
|
async handle(args) {
|
|
@@ -23588,11 +23917,11 @@ var OrgCommandHandler = class {
|
|
|
23588
23917
|
if (!filePath) {
|
|
23589
23918
|
throw new Error(`Missing ${itemLabel} input`);
|
|
23590
23919
|
}
|
|
23591
|
-
const absolutePath =
|
|
23592
|
-
if (!(0,
|
|
23920
|
+
const absolutePath = import_node_path31.default.resolve(process.cwd(), filePath);
|
|
23921
|
+
if (!(0, import_node_fs26.existsSync)(absolutePath)) {
|
|
23593
23922
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
23594
23923
|
}
|
|
23595
|
-
const raw = (0,
|
|
23924
|
+
const raw = (0, import_node_fs26.readFileSync)(absolutePath, "utf8");
|
|
23596
23925
|
let parsed;
|
|
23597
23926
|
try {
|
|
23598
23927
|
parsed = JSON.parse(raw);
|
|
@@ -23663,9 +23992,9 @@ function encodePathSegment3(value) {
|
|
|
23663
23992
|
}
|
|
23664
23993
|
|
|
23665
23994
|
// src/commands/HostCommandHandler.ts
|
|
23666
|
-
var
|
|
23995
|
+
var import_node_fs27 = require("fs");
|
|
23667
23996
|
var import_node_os11 = require("os");
|
|
23668
|
-
var
|
|
23997
|
+
var import_node_path32 = __toESM(require("path"));
|
|
23669
23998
|
var import_node_child_process13 = require("child_process");
|
|
23670
23999
|
var BLOCK_START = "# >>> pmate host env >>>";
|
|
23671
24000
|
var BLOCK_END = "# <<< pmate host env <<<";
|
|
@@ -24297,6 +24626,101 @@ function requireValue2(tokens, optionName) {
|
|
|
24297
24626
|
return value;
|
|
24298
24627
|
}
|
|
24299
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
|
+
|
|
24300
24724
|
// src/nsCommandParser.ts
|
|
24301
24725
|
var DEFAULT_CHAIN = "pmate";
|
|
24302
24726
|
function parseNsArgs(tokens) {
|
|
@@ -27261,7 +27685,7 @@ function requireValue13(tokens, option) {
|
|
|
27261
27685
|
|
|
27262
27686
|
// src/index.ts
|
|
27263
27687
|
var pkg = JSON.parse(
|
|
27264
|
-
(0,
|
|
27688
|
+
(0, import_node_fs28.readFileSync)(import_node_path33.default.resolve(__dirname, "..", "package.json"), "utf8")
|
|
27265
27689
|
);
|
|
27266
27690
|
var HELP_TEXT = [
|
|
27267
27691
|
import_chalk4.default.bold(`pmate v${pkg.version}`),
|
|
@@ -27373,6 +27797,12 @@ var HELP_TEXT = [
|
|
|
27373
27797
|
` ${import_chalk4.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
|
|
27374
27798
|
` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
27375
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]")}`,
|
|
27376
27806
|
` ${import_chalk4.default.cyan("ns")} Manage registered namespaces`,
|
|
27377
27807
|
` ${import_chalk4.default.gray(" list [--chain <chain>] [--base-url <url>] [--json]")}`,
|
|
27378
27808
|
` ${import_chalk4.default.gray(" get <namespace> [--chain <chain>] [--base-url <url>] [--json]")}`,
|
|
@@ -27619,6 +28049,15 @@ function parseCommandArgs(args) {
|
|
|
27619
28049
|
if (args.rest[0] === "runner") {
|
|
27620
28050
|
return parseRunnerArgs(args.rest.slice(1));
|
|
27621
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
|
+
}
|
|
27622
28061
|
if (args.rest[0] === "ns" || args.rest[0] === "namespace") {
|
|
27623
28062
|
return parseNsArgs(args.rest.slice(1));
|
|
27624
28063
|
}
|
|
@@ -29328,6 +29767,17 @@ async function main() {
|
|
|
29328
29767
|
await handler.handle(commandArgs);
|
|
29329
29768
|
return;
|
|
29330
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
|
+
}
|
|
29331
29781
|
case "ns" /* Ns */: {
|
|
29332
29782
|
const handler = new NsCommandHandler();
|
|
29333
29783
|
await handler.handle(commandArgs);
|