openmeld 0.3.231 → 0.3.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/{add-me-membership-0KyMk1wi.js → add-me-membership-ChntsjGm.js} +2 -2
  2. package/dist/{add-me-membership-0KyMk1wi.js.map → add-me-membership-ChntsjGm.js.map} +1 -1
  3. package/dist/{agents-Bkx6ldpV.js → agents-DruPcNSg.js} +11 -11
  4. package/dist/{agents-Bkx6ldpV.js.map → agents-DruPcNSg.js.map} +1 -1
  5. package/dist/{api-client-foundation-d4E5XWdJ.js → api-client-foundation-CDj_9Rks.js} +1 -1
  6. package/dist/{api-client-foundation-DgTXf3Gb.js → api-client-foundation-EZpFLGVC.js} +3 -3
  7. package/dist/{api-client-foundation-DgTXf3Gb.js.map → api-client-foundation-EZpFLGVC.js.map} +1 -1
  8. package/dist/auth-session-BOG3gV2K2.js +4 -0
  9. package/dist/{auth-session-pLaN5cnC.js → auth-session-DhSHCYvl.js} +4 -4
  10. package/dist/{auth-session-pLaN5cnC.js.map → auth-session-DhSHCYvl.js.map} +1 -1
  11. package/dist/auth-url-6Bb6YdNm.js +24 -0
  12. package/dist/auth-url-6Bb6YdNm.js.map +1 -0
  13. package/dist/{base-url-eck31vC8.js → base-url-0AoeTi3w.js} +3 -3
  14. package/dist/{base-url-eck31vC8.js.map → base-url-0AoeTi3w.js.map} +1 -1
  15. package/dist/{base-url-B8eWb2md.js → base-url-Bdjp-5vy.js} +1 -1
  16. package/dist/{channel-DppbHxHw.js → channel-tvFZSSVr.js} +24 -4
  17. package/dist/channel-tvFZSSVr.js.map +1 -0
  18. package/dist/{command-CBWv24uj.js → command-0yoZa1GT.js} +18 -18
  19. package/dist/{command-CBWv24uj.js.map → command-0yoZa1GT.js.map} +1 -1
  20. package/dist/{computer-connection-DMkamVpB.js → computer-connection-CoBDorh6.js} +2 -2
  21. package/dist/{computer-connection-DMkamVpB.js.map → computer-connection-CoBDorh6.js.map} +1 -1
  22. package/dist/{computer-connection-review-BSPMGVhN.js → computer-connection-review-Dy7p1LXZ.js} +6 -6
  23. package/dist/{computer-connection-review-BSPMGVhN.js.map → computer-connection-review-Dy7p1LXZ.js.map} +1 -1
  24. package/dist/{computer-disconnect-BQ_MDeeA.js → computer-disconnect-4Ks_DVXV.js} +9 -9
  25. package/dist/{computer-disconnect-BQ_MDeeA.js.map → computer-disconnect-4Ks_DVXV.js.map} +1 -1
  26. package/dist/{computer-setup-continuation-Cd293Yzi.js → computer-setup-continuation-ZcQb7MvI.js} +3 -3
  27. package/dist/{computer-setup-continuation-Cd293Yzi.js.map → computer-setup-continuation-ZcQb7MvI.js.map} +1 -1
  28. package/dist/{context-qbQXVLF5.js → context-BPIoofMa.js} +5 -5
  29. package/dist/{context-qbQXVLF5.js.map → context-BPIoofMa.js.map} +1 -1
  30. package/dist/{daemon-device-id-B6iDyQEs.js → daemon-device-id-DDazRZUV.js} +7 -7
  31. package/dist/{daemon-device-id-B6iDyQEs.js.map → daemon-device-id-DDazRZUV.js.map} +1 -1
  32. package/dist/{daemon-lifecycle-journal-DrwEygzu.js → daemon-lifecycle-journal-CRxQL9m6.js} +7 -7
  33. package/dist/{daemon-lifecycle-journal-DrwEygzu.js.map → daemon-lifecycle-journal-CRxQL9m6.js.map} +1 -1
  34. package/dist/{daemon-runtime-lease-C1wkT4Bi.js → daemon-runtime-lease-Bv6vhqOe.js} +2 -2
  35. package/dist/{daemon-runtime-lease-C1wkT4Bi.js.map → daemon-runtime-lease-Bv6vhqOe.js.map} +1 -1
  36. package/dist/{daemon-runtime-lease-DAQyRUc5.js → daemon-runtime-lease-ZjP0urJt.js} +1 -1
  37. package/dist/{daemon-service-contract-DhEfbzHt.js → daemon-service-contract-COPKbCy_.js} +4 -4
  38. package/dist/{daemon-service-contract-DhEfbzHt.js.map → daemon-service-contract-COPKbCy_.js.map} +1 -1
  39. package/dist/{daemon-service-manager-CRnFxPKA.js → daemon-service-manager-BXAp21GH.js} +6 -6
  40. package/dist/{daemon-service-manager-CRnFxPKA.js.map → daemon-service-manager-BXAp21GH.js.map} +1 -1
  41. package/dist/{daemon-service-manager-l0unaDGa.js → daemon-service-manager-C_ny0JhB.js} +1 -1
  42. package/dist/{daemon-service-runtime-B4nWB2Qx.js → daemon-service-runtime-BTzL0w6s.js} +14 -13
  43. package/dist/{daemon-service-runtime-B4nWB2Qx.js.map → daemon-service-runtime-BTzL0w6s.js.map} +1 -1
  44. package/dist/{daemon-service-update-coordinator-C8cW7Vn_.js → daemon-service-update-coordinator-BDs0p4bA.js} +26 -21
  45. package/dist/daemon-service-update-coordinator-BDs0p4bA.js.map +1 -0
  46. package/dist/{daemon-state-B6G5xe7f.js → daemon-state-Dte9re5V.js} +4 -4
  47. package/dist/{daemon-state-B6G5xe7f.js.map → daemon-state-Dte9re5V.js.map} +1 -1
  48. package/dist/{daemon-frame-transport-xQnNyg6E.js → dispatch-owned-runtime-CK2YJ2Oo.js} +547 -50
  49. package/dist/dispatch-owned-runtime-CK2YJ2Oo.js.map +1 -0
  50. package/dist/{dist-DFhd6JmQ.js → dist--TaSMxQz.js} +2 -2
  51. package/dist/{dist-DFhd6JmQ.js.map → dist--TaSMxQz.js.map} +1 -1
  52. package/dist/{dist-olOaAWkl.js → dist-B12upl5l.js} +1 -1
  53. package/dist/{dist-CAypwFRu.js → dist-Bw6OBFYo.js} +195 -185
  54. package/dist/dist-Bw6OBFYo.js.map +1 -0
  55. package/dist/{elapsed-time-COv3bjEl.js → elapsed-time-C3nfbdd9.js} +5 -5
  56. package/dist/{elapsed-time-COv3bjEl.js.map → elapsed-time-C3nfbdd9.js.map} +1 -1
  57. package/dist/{entry-DIjUKIep.js → entry-De__5RVq.js} +81 -17
  58. package/dist/entry-De__5RVq.js.map +1 -0
  59. package/dist/{installation-inventory-DllgoKT1.js → installation-inventory-Bq8iZfSa.js} +5 -5
  60. package/dist/{installation-inventory-DllgoKT1.js.map → installation-inventory-Bq8iZfSa.js.map} +1 -1
  61. package/dist/{installer-Sc79LhuA.js → installer-C7iSAOSz.js} +2 -2
  62. package/dist/{installer-Sc79LhuA.js.map → installer-C7iSAOSz.js.map} +1 -1
  63. package/dist/{lock-CMH9eoS7.js → lock-BMI00i2F.js} +2 -2
  64. package/dist/{lock-CMH9eoS7.js.map → lock-BMI00i2F.js.map} +1 -1
  65. package/dist/meta-api-BpwJWE22.js +371 -0
  66. package/dist/meta-api-BpwJWE22.js.map +1 -0
  67. package/dist/{openmeld-BUYFXSyY.js → openmeld-C0OSZJtn.js} +40 -38
  68. package/dist/{openmeld-BUYFXSyY.js.map → openmeld-C0OSZJtn.js.map} +1 -1
  69. package/dist/openmeld-dev.js +17 -9
  70. package/dist/openmeld-dev.js.map +1 -1
  71. package/dist/{openmeld-environment-target-Cw3V0WnE.js → openmeld-environment-target-BgYR6ozy.js} +8 -25
  72. package/dist/openmeld-environment-target-BgYR6ozy.js.map +1 -0
  73. package/dist/{openmeld-maintenance-worker-Br6WIhhe.js → openmeld-maintenance-worker-DY90mkWW.js} +14 -14
  74. package/dist/{openmeld-maintenance-worker-Br6WIhhe.js.map → openmeld-maintenance-worker-DY90mkWW.js.map} +1 -1
  75. package/dist/{openmeld-tools-update-join-B1l6RER6.js → openmeld-tools-update-join-DgzNuaDy.js} +4 -4
  76. package/dist/{openmeld-tools-update-join-B1l6RER6.js.map → openmeld-tools-update-join-DgzNuaDy.js.map} +1 -1
  77. package/dist/openmeld.js +5 -5
  78. package/dist/{paths-DSkUuEu3.js → paths-De9xdA2h.js} +11 -6
  79. package/dist/paths-De9xdA2h.js.map +1 -0
  80. package/dist/{prepare-provider-runtime-DfsSj_N_.js → prepare-provider-runtime-BGdfbFyZ.js} +20 -15
  81. package/dist/prepare-provider-runtime-BGdfbFyZ.js.map +1 -0
  82. package/dist/{prepare-session-executor-CrYpWljb.js → prepare-session-executor-CA1gq8dR.js} +25 -25
  83. package/dist/{prepare-session-executor-CrYpWljb.js.map → prepare-session-executor-CA1gq8dR.js.map} +1 -1
  84. package/dist/{process-channel-DmTb_kO4.js → process-channel-C1wRGUmk.js} +2 -2
  85. package/dist/{process-channel-DmTb_kO4.js.map → process-channel-C1wRGUmk.js.map} +1 -1
  86. package/dist/{published-production-safety-CgXxtdMK.js → published-production-safety-zANGAGDI.js} +5 -6
  87. package/dist/published-production-safety-zANGAGDI.js.map +1 -0
  88. package/dist/{runtime-ZLBVtFFY.js → runtime-DFlEdls4.js} +76 -22
  89. package/dist/runtime-DFlEdls4.js.map +1 -0
  90. package/dist/{runtime-agent-controller-reporting-submission-CbaUsNTF.js → runtime-agent-controller-reporting-submission-C_xD2A-P.js} +15 -12
  91. package/dist/runtime-agent-controller-reporting-submission-C_xD2A-P.js.map +1 -0
  92. package/dist/{runtime-reporting-health-state-DOg9iwwO.js → runtime-reporting-health-state-_bvJcV1y.js} +116 -22
  93. package/dist/runtime-reporting-health-state-_bvJcV1y.js.map +1 -0
  94. package/dist/{runtime-transport-D4x8_AmR.js → runtime-transport-DH8Ks-AU.js} +86 -6
  95. package/dist/runtime-transport-DH8Ks-AU.js.map +1 -0
  96. package/dist/{service-B9y1SQlB.js → service-KHA_Yv8q.js} +61 -28
  97. package/dist/service-KHA_Yv8q.js.map +1 -0
  98. package/dist/{service-account-authorization-Di59Cjth.js → service-account-authorization-BHWs8cRP.js} +6 -6
  99. package/dist/{service-account-authorization-Di59Cjth.js.map → service-account-authorization-BHWs8cRP.js.map} +1 -1
  100. package/dist/{service-account-control-DALO1USM.js → service-account-control-BcHjpVid.js} +13 -13
  101. package/dist/{service-account-control-DALO1USM.js.map → service-account-control-BcHjpVid.js.map} +1 -1
  102. package/dist/{service-control-capabilities-CKwU9Er5.js → service-control-capabilities-B4433dGT.js} +5 -5
  103. package/dist/{service-control-capabilities-CKwU9Er5.js.map → service-control-capabilities-B4433dGT.js.map} +1 -1
  104. package/dist/{service-control-capabilities-B9ZxDPOJ.js → service-control-capabilities-DTKD2-o0.js} +1 -1
  105. package/dist/{state-CdSbKM0J.js → state-iJqU2XWw.js} +3 -3
  106. package/dist/{state-CdSbKM0J.js.map → state-iJqU2XWw.js.map} +1 -1
  107. package/dist/upgrade-CuzsgsKh.js +4 -0
  108. package/dist/{upgrade-DLJJlkbf.js → upgrade-DlBDEvs4.js} +8 -8
  109. package/dist/{upgrade-DLJJlkbf.js.map → upgrade-DlBDEvs4.js.map} +1 -1
  110. package/dist/{windows-preview-channel-DPrYuLyY.js → windows-preview-channel-BPhfSwji.js} +2 -2
  111. package/dist/{windows-preview-channel-DPrYuLyY.js.map → windows-preview-channel-BPhfSwji.js.map} +1 -1
  112. package/dist/{windows-user-task-BR-WB7hr.js → windows-user-task-CTsMnmD4.js} +3 -3
  113. package/dist/{windows-user-task-BR-WB7hr.js.map → windows-user-task-CTsMnmD4.js.map} +1 -1
  114. package/dist/{windows-user-task-m9eMEUEq.js → windows-user-task-DnxKO3oB.js} +1 -1
  115. package/package.json +11 -11
  116. package/dist/auth-session-DExyUwLo.js +0 -4
  117. package/dist/channel-DppbHxHw.js.map +0 -1
  118. package/dist/daemon-frame-transport-xQnNyg6E.js.map +0 -1
  119. package/dist/daemon-service-update-coordinator-C8cW7Vn_.js.map +0 -1
  120. package/dist/dist-CAypwFRu.js.map +0 -1
  121. package/dist/entry-DIjUKIep.js.map +0 -1
  122. package/dist/meta-api-CEw8eOeN.js +0 -845
  123. package/dist/meta-api-CEw8eOeN.js.map +0 -1
  124. package/dist/openmeld-environment-target-Cw3V0WnE.js.map +0 -1
  125. package/dist/paths-DSkUuEu3.js.map +0 -1
  126. package/dist/prepare-provider-runtime-DfsSj_N_.js.map +0 -1
  127. package/dist/published-production-safety-CgXxtdMK.js.map +0 -1
  128. package/dist/runtime-ZLBVtFFY.js.map +0 -1
  129. package/dist/runtime-agent-controller-reporting-submission-CbaUsNTF.js.map +0 -1
  130. package/dist/runtime-reporting-health-state-DOg9iwwO.js.map +0 -1
  131. package/dist/runtime-transport-D4x8_AmR.js.map +0 -1
  132. package/dist/service-B9y1SQlB.js.map +0 -1
  133. package/dist/upgrade-BFWUxFpJ.js +0 -4
@@ -1,845 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { f as toSpaceMetaUrl } from "./urls-CY2uzH2-.js";
4
- import { F as resolveOpenMeldEnvPreset, w as openMeldManagedBinaryPath } from "./paths-DSkUuEu3.js";
5
- import { Bn as toStructuredApiClientFailure, ei as spaceMemberDirectoryEntrySchema, gi as spaceMetaSchema, mn as createSpaceApi, nr as OPENMELD_HEADER_REQUEST_ID, t as OpenMeldApiClientHttpError, yr as gatewayErrorEnvelopeSchema } from "./dist-CAypwFRu.js";
6
- import { Jt as SPACE_FILE_MAX_SIZE_BYTES, Q as openMeldSpaceEgressActionSchema, _n as spaceFileNameSchema, in as resolveSpaceFileMimeType, rr as executionContextAssignmentSchema } from "./runtime-transport-D4x8_AmR.js";
7
- import { _n as OPENMELD_DISPATCH_RUNTIME_TARGET_PROFILE_ID_ENV, gn as OPENMELD_DISPATCH_RUNTIME_MODE_ENV, hn as OPENMELD_DISPATCH_RUNTIME_DISPATCH_ID_ENV, pn as DISPATCH_OWNED_RUNTIME_MODE, vn as OPENMELD_SPACE_ACTION_TOOL_COMMAND_PATH_ENV, yn as OPENMELD_USER_FACING_CLI_COMMAND_ENV } from "./daemon-frame-transport-xQnNyg6E.js";
8
- import { h as isSelfWakeSpaceAction } from "./dist-DFhd6JmQ.js";
9
- import { n as resolveOpenMeldDistribution } from "./distribution-BDQT2ilb.js";
10
- import { h as daemonRuntimeRootPath } from "./daemon-state-B6G5xe7f.js";
11
- import { n as fetchSpaceRequestWithTimeout, s as buildOpenMeldRequestContextHeadersWithAuth, t as createCliApiClientFoundation } from "./api-client-foundation-DgTXf3Gb.js";
12
- import { randomUUID } from "node:crypto";
13
- import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
14
- import { access } from "node:fs/promises";
15
- import { chmodSync, existsSync, mkdirSync, openAsBlob, readFileSync, renameSync, writeFileSync } from "node:fs";
16
- import { isDeepStrictEqual } from "node:util";
17
- //#region src/runtime/dispatch-space-action-context.ts
18
- const OPENMELD_SPACE_ACTION_CONTEXT_PATH_ENV = "OPENMELD_SPACE_ACTION_CONTEXT_PATH";
19
- /** The local action context is known expired/closed/mismatched: a new ordinary action must be rejected, never recorded. */
20
- var DispatchSpaceActionClosedError = class extends Error {
21
- receipt = "rejected_closed";
22
- reasonCode;
23
- constructor(reasonCode, message) {
24
- super(message);
25
- this.name = "DispatchSpaceActionClosedError";
26
- this.reasonCode = reasonCode;
27
- }
28
- };
29
- /** Use only at a boundary that has positively rejected this call before recording. */
30
- var DispatchSpaceActionRejectedError = class extends Error {
31
- reasonCode;
32
- constructor(reasonCode, message) {
33
- super(message);
34
- this.name = "DispatchSpaceActionRejectedError";
35
- this.reasonCode = reasonCode;
36
- }
37
- };
38
- const DISPATCH_SPACE_ACTION_CONTEXT_VERSION = 1;
39
- const DISPATCH_SPACE_ACTION_RECORD_VERSION = 1;
40
- const DEFAULT_CONTEXT_TTL_MS = 720 * 60 * 1e3;
41
- function createDispatchSpaceActionContext(input) {
42
- const contextId = randomUUID();
43
- const nonce = randomUUID();
44
- const contextDir = join(daemonRuntimeRootPath(input.pathInput ?? { env: input.env }), "dispatch-space-actions", `${Date.now().toString(36)}-${contextId}`);
45
- mkdirSync(contextDir, {
46
- recursive: true,
47
- mode: 448
48
- });
49
- chmodSync(contextDir, 448);
50
- const contextPath = join(contextDir, "context.json");
51
- const actionRecordPath = join(contextDir, "action.json");
52
- const context = {
53
- ...input.projectShell ? { projectShell: input.projectShell } : {},
54
- ...input.workingCopyId ? { workingCopyId: input.workingCopyId } : {},
55
- version: DISPATCH_SPACE_ACTION_CONTEXT_VERSION,
56
- actionRecordPath,
57
- attemptId: input.attemptId,
58
- contextId,
59
- dispatchId: input.dispatchId,
60
- expiresAtMs: Date.now() + (input.ttlMs ?? DEFAULT_CONTEXT_TTL_MS),
61
- nonce,
62
- replyToSignalId: normalizeOptionalText$2(input.replyToSignalId),
63
- sendTargetReference: input.sendTargetReference,
64
- sourceEventId: input.sourceEventId,
65
- spaceContractSnapshot: input.spaceContractSnapshot ? {
66
- allowedActions: input.spaceContractSnapshot.allowedActions,
67
- publicationMode: input.spaceContractSnapshot.publicationMode
68
- } : null,
69
- spaceId: input.spaceId,
70
- targetProfileId: input.targetProfileId,
71
- taskId: input.taskId
72
- };
73
- writeJsonFileExclusive(contextPath, context);
74
- return {
75
- context,
76
- contextPath
77
- };
78
- }
79
- function readDispatchSpaceActionContextFromEnv(env = process.env) {
80
- const context = readDispatchSpaceActionContextForReceiptFromEnv(env);
81
- assertContextActive(context, Date.now());
82
- return context;
83
- }
84
- function readDispatchSpaceActionContextForReceiptFromEnv(env = process.env) {
85
- const contextPath = normalizeOptionalText$2(env[OPENMELD_SPACE_ACTION_CONTEXT_PATH_ENV]);
86
- if (!contextPath) throw new Error("No active OpenMeld Space Action dispatch context was found. Use this command inside an OpenMeld Space Wake dispatch.");
87
- const context = readDispatchSpaceActionContext(contextPath);
88
- assertDispatchRuntimeEnvMatchesContext({
89
- context,
90
- env
91
- });
92
- return context;
93
- }
94
- function readDispatchSpaceActionContext(contextPath) {
95
- return parseDispatchSpaceActionContext(readJsonFile(contextPath));
96
- }
97
- function writeDispatchSpaceActionRecord(input) {
98
- const parsedAction = openMeldSpaceEgressActionSchema.safeParse(input.action);
99
- if (!parsedAction.success) throw new DispatchSpaceActionRejectedError("space_action.invalid_input", parsedAction.error.message);
100
- if (isSelfWakeSpaceAction(parsedAction.data, input.context.targetProfileId)) throw new DispatchSpaceActionRejectedError("space_action.invalid_input", "An Agent cannot Wake itself. To reply to the current message, omit wakeTargets (CLI: --wake) and submit the reply again. No action was recorded.");
101
- const existing = readDispatchSpaceActionRecord({ context: input.context });
102
- if (existing.status === "invalid") throw new Error(existing.errorMessage);
103
- if (existing.status === "loaded" && isDeepStrictEqual(existing.record.action, parsedAction.data)) return existing.record;
104
- assertContextActive(input.context, input.nowMs ?? Date.now());
105
- const record = {
106
- version: DISPATCH_SPACE_ACTION_RECORD_VERSION,
107
- action: parsedAction.data,
108
- command: input.command,
109
- contextId: input.context.contextId,
110
- createdAtMs: input.nowMs ?? Date.now(),
111
- nonce: input.context.nonce
112
- };
113
- try {
114
- writeJsonFileExclusive(input.context.actionRecordPath, record);
115
- } catch (error) {
116
- if (isNodeErrorCode(error, "EEXIST")) {
117
- const existing = readDispatchSpaceActionRecord({ context: input.context });
118
- if (existing.status === "loaded" && isDeepStrictEqual(existing.record.action, parsedAction.data)) return existing.record;
119
- throw new DispatchSpaceActionRejectedError("space_action.already_recorded", "An OpenMeld Space Action has already been recorded for this dispatch. A Wake can only have one final Space action. Recover its receipt with the exact original arguments; do not replace it with a different action.");
120
- }
121
- throw error;
122
- }
123
- return record;
124
- }
125
- function readDispatchSpaceActionRecord(input) {
126
- if (!existsSync(input.context.actionRecordPath)) return { status: "missing" };
127
- try {
128
- const record = parseDispatchSpaceActionRecord(readJsonFile(input.context.actionRecordPath));
129
- if (record.contextId !== input.context.contextId || record.nonce !== input.context.nonce) return {
130
- status: "invalid",
131
- errorMessage: "OpenMeld Space Action record does not match the active dispatch context."
132
- };
133
- if (record.createdAtMs > input.context.expiresAtMs) return {
134
- status: "invalid",
135
- errorMessage: "OpenMeld Space Action record was created after the active dispatch context expired."
136
- };
137
- return {
138
- status: "loaded",
139
- record
140
- };
141
- } catch (error) {
142
- return {
143
- status: "invalid",
144
- errorMessage: error instanceof Error ? error.message : String(error)
145
- };
146
- }
147
- }
148
- function supersedeDispatchSpaceActionRecordForReconsideration(input) {
149
- const readResult = readDispatchSpaceActionRecord(input);
150
- if (readResult.status === "missing") return null;
151
- if (readResult.status === "invalid") throw new Error(readResult.errorMessage);
152
- const archivedPath = `${input.context.actionRecordPath}.superseded-${String(input.nowMs ?? Date.now())}-${randomUUID()}`;
153
- renameSync(input.context.actionRecordPath, archivedPath);
154
- return {
155
- archivedPath,
156
- record: readResult.record
157
- };
158
- }
159
- function parseDispatchSpaceActionContext(value) {
160
- const record = toRecord(value, "OpenMeld Space Action context");
161
- const version = record.version;
162
- if (version !== DISPATCH_SPACE_ACTION_CONTEXT_VERSION) throw new Error("Unsupported OpenMeld Space Action context version.");
163
- const sendTargetReference = parseSendTargetReference(record.sendTargetReference);
164
- return {
165
- ...record.projectShell ? { projectShell: parseProjectShell(record.projectShell) } : {},
166
- version,
167
- actionRecordPath: requiredString(record.actionRecordPath, "actionRecordPath"),
168
- attemptId: requiredString(record.attemptId, "attemptId"),
169
- contextId: requiredString(record.contextId, "contextId"),
170
- dispatchId: requiredString(record.dispatchId, "dispatchId"),
171
- expiresAtMs: requiredFiniteNumber(record.expiresAtMs, "expiresAtMs"),
172
- nonce: requiredString(record.nonce, "nonce"),
173
- replyToSignalId: optionalString(record.replyToSignalId),
174
- sendTargetReference,
175
- sourceEventId: requiredString(record.sourceEventId, "sourceEventId"),
176
- spaceContractSnapshot: parseSpaceContractSnapshot(record.spaceContractSnapshot),
177
- spaceId: requiredString(record.spaceId, "spaceId"),
178
- targetProfileId: requiredString(record.targetProfileId, "targetProfileId"),
179
- taskId: requiredString(record.taskId, "taskId"),
180
- ...record.workingCopyId ? { workingCopyId: requiredString(record.workingCopyId, "workingCopyId") } : {}
181
- };
182
- }
183
- function parseProjectShell(value) {
184
- const record = toRecord(value, "OpenMeld project shell context");
185
- const runtime = toRecord(record.runtime, "OpenMeld project shell runtime");
186
- const kind = runtime.kind;
187
- if (kind !== "docker" && kind !== "podman") throw new Error("OpenMeld project shell runtime is invalid.");
188
- const executionContextId = requiredString(record.executionContextId, "executionContextId");
189
- const workspacePath = requiredString(record.workspacePath, "workspacePath");
190
- const boundaryRoot = requiredString(record.boundaryRoot, "boundaryRoot");
191
- const ledgerRootPath = requiredString(record.ledgerRootPath, "ledgerRootPath");
192
- const binary = requiredString(runtime.binary, "binary");
193
- const validContextId = executionContextAssignmentSchema.shape.id.safeParse(executionContextId).success;
194
- const validPaths = [
195
- workspacePath,
196
- boundaryRoot,
197
- ledgerRootPath,
198
- binary
199
- ].every(isAbsolute);
200
- if (!(validContextId && validPaths)) throw new Error("OpenMeld project shell context is invalid.");
201
- return {
202
- boundaryRoot,
203
- executionContextId,
204
- ledgerRootPath,
205
- workspacePath,
206
- runtime: {
207
- binary,
208
- engineIdentity: requiredString(runtime.engineIdentity, "engineIdentity"),
209
- kind
210
- }
211
- };
212
- }
213
- function assertDispatchRuntimeEnvMatchesContext(input) {
214
- if (normalizeOptionalText$2(input.env["OPENMELD_DISPATCH_RUNTIME_MODE"]) !== "dispatch-owned-runtime") return;
215
- const envDispatchId = normalizeOptionalText$2(input.env[OPENMELD_DISPATCH_RUNTIME_DISPATCH_ID_ENV]);
216
- if (!envDispatchId) throw new Error("OpenMeld Space Action dispatch runtime is missing the active dispatch ID.");
217
- if (envDispatchId !== input.context.dispatchId) throw new DispatchSpaceActionClosedError("space_action.context_mismatch", "OpenMeld Space Action dispatch context does not match the active dispatch runtime.");
218
- const envTargetProfileId = normalizeOptionalText$2(input.env[OPENMELD_DISPATCH_RUNTIME_TARGET_PROFILE_ID_ENV]);
219
- if (!envTargetProfileId) throw new Error("OpenMeld Space Action dispatch runtime is missing the active target profile ID.");
220
- if (envTargetProfileId !== input.context.targetProfileId) throw new DispatchSpaceActionClosedError("space_action.context_mismatch", "OpenMeld Space Action target profile does not match the active dispatch runtime.");
221
- }
222
- function parseDispatchSpaceActionRecord(value) {
223
- const record = toRecord(value, "OpenMeld Space Action record");
224
- const version = record.version;
225
- if (version !== DISPATCH_SPACE_ACTION_RECORD_VERSION) throw new Error("Unsupported OpenMeld Space Action record version.");
226
- const parsedAction = openMeldSpaceEgressActionSchema.safeParse(record.action);
227
- if (!parsedAction.success) throw parsedAction.error;
228
- return {
229
- version,
230
- action: parsedAction.data,
231
- command: requiredString(record.command, "command"),
232
- contextId: requiredString(record.contextId, "contextId"),
233
- createdAtMs: requiredFiniteNumber(record.createdAtMs, "createdAtMs"),
234
- nonce: requiredString(record.nonce, "nonce")
235
- };
236
- }
237
- function parseSendTargetReference(value) {
238
- const record = toRecord(value, "sendTargetReference");
239
- if (record.status === "loaded") {
240
- if (!Array.isArray(record.projection)) throw new Error("OpenMeld Space Action send target projection must be an array.");
241
- return {
242
- status: "loaded",
243
- projection: record.projection.map(parseSendTargetProjectionEntry),
244
- referenceLines: parseStringArray(record.referenceLines)
245
- };
246
- }
247
- if (record.status === "failed") return {
248
- status: "failed",
249
- errorMessage: requiredString(record.errorMessage, "errorMessage"),
250
- projection: null,
251
- referenceLines: []
252
- };
253
- throw new Error("Invalid OpenMeld Space Action send target reference status.");
254
- }
255
- function parseSendTargetProjectionEntry(value, index) {
256
- const parsed = spaceMemberDirectoryEntrySchema.safeParse(value);
257
- if (!parsed.success) throw new Error(`OpenMeld Space Action target projection entry ${index} is not a valid Space member directory entry.`);
258
- return parsed.data;
259
- }
260
- function parseSpaceContractSnapshot(value) {
261
- if (value === null || value === void 0) return null;
262
- const record = toRecord(value, "spaceContractSnapshot");
263
- return {
264
- allowedActions: Array.isArray(record.allowedActions) ? record.allowedActions : [],
265
- publicationMode: record.publicationMode === "raw_context_sharing" ? "raw_context_sharing" : "collaboration"
266
- };
267
- }
268
- function assertContextActive(context, nowMs) {
269
- if (nowMs > context.expiresAtMs) throw new DispatchSpaceActionClosedError("space_action.context_expired", "The OpenMeld Space Action dispatch context has expired.");
270
- }
271
- function readJsonFile(path) {
272
- return JSON.parse(readFileSync(path, "utf8"));
273
- }
274
- function writeJsonFileExclusive(path, value) {
275
- writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`, {
276
- encoding: "utf8",
277
- flag: "wx",
278
- mode: 384
279
- });
280
- chmodSync(path, 384);
281
- }
282
- function toRecord(value, label) {
283
- if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be a JSON object.`);
284
- return value;
285
- }
286
- function requiredString(value, fieldName) {
287
- const normalized = normalizeOptionalText$2(value);
288
- if (!normalized) throw new Error(`${fieldName} must be a non-empty string.`);
289
- return normalized;
290
- }
291
- function requiredFiniteNumber(value, fieldName) {
292
- if (typeof value !== "number" || !Number.isFinite(value)) throw new Error(`${fieldName} must be a finite number.`);
293
- return value;
294
- }
295
- function optionalString(value) {
296
- if (value === null || value === void 0) return null;
297
- return normalizeOptionalText$2(value);
298
- }
299
- function parseStringArray(value) {
300
- if (!Array.isArray(value)) return [];
301
- return value.map((item) => normalizeOptionalText$2(item)).filter((item) => Boolean(item));
302
- }
303
- function normalizeOptionalText$2(value) {
304
- const normalized = String(value ?? "").trim();
305
- return normalized.length > 0 ? normalized : null;
306
- }
307
- function isNodeErrorCode(error, code) {
308
- return typeof error === "object" && error !== null && "code" in error && error.code === code;
309
- }
310
- //#endregion
311
- //#region src/runtime/dispatch-owned-runtime.ts
312
- const DISPATCH_OWNED_RUNTIME_CLI_SHIM_DIRNAME = "dispatch-owned-cli";
313
- const DISPATCH_SPACE_ACTION_CLI_SHIM_DIRNAME = "bin";
314
- const OPENMELD_ENV_PRESET_ENV = "OPENMELD_ENV_PRESET";
315
- const DISPATCH_OWNED_RUNTIME_CLI_COMMAND_NAMES = [
316
- "openmeld",
317
- "openmeld-dev",
318
- "openmeld-canary"
319
- ];
320
- function buildDispatchOwnedRuntimeEnv(input) {
321
- const env = {
322
- OPENMELD_HOME: process.env.OPENMELD_HOME,
323
- OPENMELD_ENV_PRESET: process.env.OPENMELD_ENV_PRESET,
324
- ...input.env ?? {}
325
- };
326
- const currentPath = normalizeOptionalText$1(input.env?.PATH ?? process.env.PATH);
327
- const actionCommand = resolveDispatchOwnedRuntimeActionCliEntryCommand({ env });
328
- const actionCommandPath = (input.platform ?? process.platform) === "win32" && (input.distribution ?? resolveOpenMeldDistribution()) === "binary" ? resolveDispatchOwnedRuntimeBinaryCliEntryPath({
329
- cliEntryPath: input.cliEntryPath,
330
- env
331
- }) : join(ensureDispatchOwnedRuntimeCliShims({
332
- cliEntryPath: input.cliEntryPath,
333
- dispatchId: input.dispatchId,
334
- distribution: input.distribution,
335
- env,
336
- spaceActionContextPath: input.spaceActionContextPath,
337
- targetProfileId: input.targetProfileId
338
- }), actionCommand);
339
- return {
340
- ...env,
341
- PATH: prependPathEntry({
342
- currentPath,
343
- nextEntry: dirname(actionCommandPath)
344
- }),
345
- [OPENMELD_DISPATCH_RUNTIME_MODE_ENV]: DISPATCH_OWNED_RUNTIME_MODE,
346
- [OPENMELD_DISPATCH_RUNTIME_DISPATCH_ID_ENV]: input.dispatchId,
347
- [OPENMELD_DISPATCH_RUNTIME_TARGET_PROFILE_ID_ENV]: input.targetProfileId,
348
- [OPENMELD_USER_FACING_CLI_COMMAND_ENV]: actionCommand,
349
- [OPENMELD_SPACE_ACTION_TOOL_COMMAND_PATH_ENV]: actionCommandPath,
350
- [OPENMELD_ENV_PRESET_ENV]: resolveDispatchOwnedRuntimeEnvPreset({ env }),
351
- ...input.spaceActionContextPath ? { [OPENMELD_SPACE_ACTION_CONTEXT_PATH_ENV]: input.spaceActionContextPath } : {}
352
- };
353
- }
354
- function resolveDispatchOwnedRuntimeActionCliEntryCommand(input = {}) {
355
- const preset = resolveOpenMeldEnvPreset(input);
356
- if (preset === "dev-local") return "openmeld-dev";
357
- if (preset === "canary") return "openmeld-canary";
358
- return "openmeld";
359
- }
360
- function resolveDispatchOwnedRuntimeCliShimDir(input = {}) {
361
- const spaceActionContextPath = normalizeOptionalText$1(input.spaceActionContextPath);
362
- if (spaceActionContextPath) return join(dirname(spaceActionContextPath), DISPATCH_SPACE_ACTION_CLI_SHIM_DIRNAME);
363
- return join(daemonRuntimeRootPath(input), "bin", DISPATCH_OWNED_RUNTIME_CLI_SHIM_DIRNAME);
364
- }
365
- function ensureDispatchOwnedRuntimeCliShims(input) {
366
- const distribution = input?.distribution ?? resolveOpenMeldDistribution();
367
- const cliEntryPath = distribution === "binary" ? resolveDispatchOwnedRuntimeBinaryCliEntryPath({
368
- cliEntryPath: input?.cliEntryPath,
369
- env: input?.env
370
- }) : resolveDispatchOwnedRuntimeCliEntryPath(input?.cliEntryPath);
371
- const shimDir = resolveDispatchOwnedRuntimeCliShimDir({
372
- env: input?.env,
373
- spaceActionContextPath: input?.spaceActionContextPath
374
- });
375
- mkdirSync(shimDir, { recursive: true });
376
- for (const commandName of DISPATCH_OWNED_RUNTIME_CLI_COMMAND_NAMES) {
377
- const shimPath = join(shimDir, commandName);
378
- const shimSource = buildDispatchOwnedRuntimeCliShimSource({
379
- cliEntryPath,
380
- commandName,
381
- dispatchId: input?.dispatchId,
382
- distribution,
383
- nodePath: process.execPath,
384
- spaceActionContextPath: input?.spaceActionContextPath,
385
- targetProfileId: input?.targetProfileId
386
- });
387
- if (existsSync(shimPath)) {
388
- if (safeReadTextFile(shimPath) === shimSource) {
389
- chmodSync(shimPath, 493);
390
- continue;
391
- }
392
- }
393
- writeFileSync(shimPath, shimSource, {
394
- encoding: "utf8",
395
- mode: 493
396
- });
397
- chmodSync(shimPath, 493);
398
- }
399
- return shimDir;
400
- }
401
- function readDispatchOwnedRuntimeGuard(env = process.env) {
402
- if (normalizeOptionalText$1(env["OPENMELD_DISPATCH_RUNTIME_MODE"]) !== "dispatch-owned-runtime") return {
403
- active: false,
404
- dispatchId: null,
405
- targetProfileId: null
406
- };
407
- return {
408
- active: true,
409
- dispatchId: normalizeOptionalText$1(env[OPENMELD_DISPATCH_RUNTIME_DISPATCH_ID_ENV]),
410
- targetProfileId: normalizeOptionalText$1(env[OPENMELD_DISPATCH_RUNTIME_TARGET_PROFILE_ID_ENV])
411
- };
412
- }
413
- function assertDispatchOwnedRuntimePublicWriteAllowed(input) {
414
- const guard = readDispatchOwnedRuntimeGuard(input.env);
415
- if (!guard.active) return;
416
- const dispatchIdSuffix = guard.dispatchId ? ` (dispatch ${guard.dispatchId})` : "";
417
- throw new Error(`${input.commandLabel} is blocked inside a dispatch-owned runtime${dispatchIdSuffix}. Public space writes must be returned through OpenMeld Space structured actions: post_message, post_status, or stay_silent.`);
418
- }
419
- function normalizeOptionalText$1(value) {
420
- const normalized = String(value ?? "").trim();
421
- return normalized.length > 0 ? normalized : null;
422
- }
423
- function resolveDispatchOwnedRuntimeCliEntryPath(cliEntryPath) {
424
- const normalizedCliEntryPath = normalizeOptionalText$1(cliEntryPath) ?? normalizeOptionalText$1(process.argv[1]) ?? null;
425
- if (!normalizedCliEntryPath) throw new Error("dispatch-owned runtime CLI shim requires a current CLI entry path");
426
- return resolve(normalizedCliEntryPath);
427
- }
428
- function resolveDispatchOwnedRuntimeBinaryCliEntryPath(input) {
429
- const normalizedCliEntryPath = normalizeOptionalText$1(input.cliEntryPath) ?? normalizeOptionalText$1(openMeldManagedBinaryPath({ env: input.env })) ?? null;
430
- if (!normalizedCliEntryPath) throw new Error("dispatch-owned runtime CLI shim requires a current binary CLI path");
431
- return resolve(normalizedCliEntryPath);
432
- }
433
- function buildDispatchOwnedRuntimeCliShimSource(input) {
434
- const embeddedEnv = {
435
- [OPENMELD_DISPATCH_RUNTIME_MODE_ENV]: DISPATCH_OWNED_RUNTIME_MODE,
436
- [OPENMELD_ENV_PRESET_ENV]: resolveEnvPresetForCommandName(input.commandName),
437
- [OPENMELD_USER_FACING_CLI_COMMAND_ENV]: input.commandName,
438
- ...normalizeOptionalText$1(input.dispatchId) ? { [OPENMELD_DISPATCH_RUNTIME_DISPATCH_ID_ENV]: normalizeOptionalText$1(input.dispatchId) } : {},
439
- ...normalizeOptionalText$1(input.targetProfileId) ? { [OPENMELD_DISPATCH_RUNTIME_TARGET_PROFILE_ID_ENV]: normalizeOptionalText$1(input.targetProfileId) } : {},
440
- ...normalizeOptionalText$1(input.spaceActionContextPath) ? { [OPENMELD_SPACE_ACTION_CONTEXT_PATH_ENV]: normalizeOptionalText$1(input.spaceActionContextPath) } : {}
441
- };
442
- if (input.distribution === "binary") return `#!/bin/sh
443
- ${Object.entries(embeddedEnv).map(([key, value]) => `export ${key}=${quoteShellValue(value)}`).join("\n")}
444
- exec ${quoteShellValue(input.cliEntryPath)} "$@"
445
- `;
446
- return `#!/usr/bin/env node
447
- import { spawnSync } from "node:child_process";
448
-
449
- const result = spawnSync(${JSON.stringify(input.nodePath)}, [${JSON.stringify(input.cliEntryPath)}, ...process.argv.slice(2)], {
450
- env: { ...process.env, ...${JSON.stringify(embeddedEnv)} },
451
- stdio: "inherit",
452
- });
453
-
454
- if (result.error) {
455
- throw result.error;
456
- }
457
-
458
- process.exit(result.status ?? 1);
459
- `;
460
- }
461
- function resolveDispatchOwnedRuntimeEnvPreset(input) {
462
- return resolveEnvPresetForCommandName(resolveDispatchOwnedRuntimeActionCliEntryCommand({ env: input.env }));
463
- }
464
- function resolveEnvPresetForCommandName(commandName) {
465
- if (commandName === "openmeld-dev") return "dev-local";
466
- if (commandName === "openmeld-canary") return "canary";
467
- return "prod";
468
- }
469
- function quoteShellValue(value) {
470
- return `'${value.replaceAll("'", "'\\''")}'`;
471
- }
472
- function safeReadTextFile(path) {
473
- try {
474
- return readFileSync(path, "utf8");
475
- } catch {
476
- return null;
477
- }
478
- }
479
- function prependPathEntry(input) {
480
- const dedupedEntries = (input.currentPath ?? "").split(delimiter).map((entry) => entry.trim()).filter((entry) => entry.length > 0).filter((entry) => entry !== input.nextEntry);
481
- return [input.nextEntry, ...dedupedEntries].join(delimiter);
482
- }
483
- //#endregion
484
- //#region src/space/cli-space-api.ts
485
- function createCliSpaceApi(baseUrl, options = {}) {
486
- return createSpaceApi(createCliApiClientFoundation(baseUrl, options));
487
- }
488
- //#endregion
489
- //#region src/space/send-files.ts
490
- var SpaceSendFileError = class extends Error {
491
- code;
492
- requestId;
493
- status;
494
- upstreamCode;
495
- constructor(input) {
496
- super(input.message, { cause: input.cause });
497
- this.name = "SpaceSendFileError";
498
- this.code = input.code;
499
- if (input.requestId) this.requestId = input.requestId;
500
- if (input.status !== null && input.status !== void 0) this.status = input.status;
501
- if (input.upstreamCode) this.upstreamCode = input.upstreamCode;
502
- }
503
- };
504
- async function prepareRequestedSpaceSendFiles(input) {
505
- if (input.filePaths.length > 10) throw new SpaceSendFileError({
506
- code: "space.file.too_many",
507
- message: `A Space message can include at most 10 files. The message was not sent.`
508
- });
509
- const prepared = [];
510
- for (const rawPath of input.filePaths) {
511
- if (!rawPath.trim()) throw new SpaceSendFileError({
512
- code: "space.file.invalid_path",
513
- message: "File paths cannot be empty. The message was not sent."
514
- });
515
- prepared.push(await prepareSpaceSendFile(rawPath));
516
- }
517
- return prepared;
518
- }
519
- async function uploadPreparedSpaceFiles(input) {
520
- const uploaded = [];
521
- for (const file of input.files) try {
522
- const descriptor = await input.spaceApi.uploadFile({
523
- bytes: file.bytes,
524
- clientMutationId: crypto.randomUUID(),
525
- mimeType: file.mimeType,
526
- name: file.name,
527
- origin: "chat_upload",
528
- parentId: null,
529
- requestContext: input.requestContext,
530
- spaceId: input.spaceId,
531
- ...input.password === void 0 ? {} : { spacePassword: input.password }
532
- });
533
- uploaded.push({
534
- fileId: descriptor.id,
535
- revision: descriptor.latestRevision.revision,
536
- name: descriptor.name,
537
- mimeType: descriptor.latestRevision.mimeType,
538
- sizeBytes: descriptor.latestRevision.sizeBytes
539
- });
540
- } catch (error) {
541
- const failure = toStructuredApiClientFailure(error);
542
- const cleanupFailures = await moveUploadedFilesToTrash({
543
- files: uploaded,
544
- password: input.password,
545
- requestContext: input.requestContext,
546
- spaceApi: input.spaceApi,
547
- spaceId: input.spaceId
548
- });
549
- let cleanupMessage = "";
550
- if (uploaded.length > 0) cleanupMessage = cleanupFailures.length === 0 ? " Files added earlier in this send were moved to Trash." : ` ${formatCleanupFailures({
551
- failures: cleanupFailures,
552
- passwordProtected: input.password !== void 0,
553
- profileId: input.requestContext.actorContext.openMeldProfileId,
554
- spaceId: input.spaceId
555
- })}`;
556
- throw new SpaceSendFileError({
557
- code: failure.code ?? "space.file.upload_failed",
558
- message: `Could not add file "${file.name}" to this Space. The message was not sent. ${failure.message}${cleanupMessage}`,
559
- cause: error,
560
- requestId: failure.requestId,
561
- status: failure.status,
562
- upstreamCode: failure.upstreamCode
563
- });
564
- }
565
- return uploaded;
566
- }
567
- async function moveUploadedFilesToTrash(input) {
568
- const failures = [];
569
- for (const file of input.files) try {
570
- await input.spaceApi.trashFileEntry({
571
- clientMutationId: crypto.randomUUID(),
572
- entryId: file.fileId,
573
- requestContext: input.requestContext,
574
- spaceId: input.spaceId,
575
- ...input.password === void 0 ? {} : { spacePassword: input.password }
576
- });
577
- } catch (error) {
578
- failures.push({
579
- failure: toStructuredApiClientFailure(error),
580
- fileId: file.fileId
581
- });
582
- }
583
- return failures;
584
- }
585
- function formatCleanupFailures(input) {
586
- return `${input.failures.map(({ failure, fileId }) => {
587
- const evidence = [failure.code ? `code ${failure.code}` : null, failure.requestId ? `request ${failure.requestId}` : null].filter((value) => value !== null).join(", ");
588
- return `Could not move file ${fileId} to Trash${evidence ? ` (${evidence})` : ""}: ${failure.message} Run \`openmeld space files trash ${input.spaceId} ${fileId} --profile ${input.profileId}\` to finish cleanup.`;
589
- }).join(" ")}${input.passwordProtected ? " This Space is password protected. Add `--password` with the same Space password you used for this send; OpenMeld does not include the password in this message." : ""}`;
590
- }
591
- async function prepareSpaceSendFile(sourcePath) {
592
- let bytes;
593
- try {
594
- await access(sourcePath);
595
- bytes = await openAsBlob(sourcePath);
596
- } catch (error) {
597
- if (readNodeErrorCode(error) === "ENOENT") throw new SpaceSendFileError({
598
- code: "space.file.file_not_found",
599
- message: `File not found: ${sourcePath}. The message was not sent.`,
600
- cause: error
601
- });
602
- throw new SpaceSendFileError({
603
- code: "space.file.file_unreadable",
604
- message: `Could not read file: ${sourcePath}. The message was not sent.`,
605
- cause: error
606
- });
607
- }
608
- if (bytes.size > 1073741824) throw new SpaceSendFileError({
609
- code: "space.file.too_large",
610
- message: `File exceeds the ${formatFileSizeLimit()} limit: ${sourcePath}. The message was not sent.`
611
- });
612
- const parsedName = spaceFileNameSchema.safeParse(basename(sourcePath));
613
- if (!parsedName.success) throw new SpaceSendFileError({
614
- code: "space.file.invalid_file_name",
615
- message: `File name is invalid: ${sourcePath}. The message was not sent.`
616
- });
617
- return {
618
- bytes,
619
- name: parsedName.data,
620
- mimeType: resolveSpaceFileMimeType({ fileName: parsedName.data })
621
- };
622
- }
623
- function readNodeErrorCode(error) {
624
- if (!(error && typeof error === "object" && "code" in error)) return null;
625
- return typeof error.code === "string" ? error.code : null;
626
- }
627
- function formatFileSizeLimit() {
628
- return `${SPACE_FILE_MAX_SIZE_BYTES / (1024 * 1024)} MiB`;
629
- }
630
- //#endregion
631
- //#region src/space/api-json.ts
632
- function parseJsonResponse(raw) {
633
- if (!raw.trim()) return null;
634
- try {
635
- return JSON.parse(raw);
636
- } catch {
637
- return null;
638
- }
639
- }
640
- //#endregion
641
- //#region src/space/gateway-response.ts
642
- const FALLBACK_GATEWAY_HTTP_ERROR_CODE = "gateway.http_error";
643
- var GatewayHttpError = class extends Error {
644
- code;
645
- requestId;
646
- status;
647
- rawBody;
648
- upstreamCode;
649
- constructor(input) {
650
- super(input.message);
651
- this.name = "GatewayHttpError";
652
- this.code = input.code;
653
- this.requestId = normalizeOptionalText(input.requestId);
654
- this.status = input.status;
655
- this.rawBody = input.rawBody;
656
- this.upstreamCode = normalizeOptionalText(input.upstreamCode);
657
- }
658
- };
659
- async function readGatewayJsonResponse(input) {
660
- const raw = await input.response.text();
661
- assertGatewayResponseOk({
662
- response: input.response,
663
- raw
664
- });
665
- const parsed = input.schema.safeParse(parseJsonResponse(raw));
666
- if (!parsed.success) throw new Error(input.invalidMessage);
667
- return parsed.data;
668
- }
669
- async function readGatewayTextResponse(input) {
670
- const raw = await input.response.text();
671
- assertGatewayResponseOk({
672
- response: input.response,
673
- raw
674
- });
675
- return raw;
676
- }
677
- function assertGatewayResponseOk(input) {
678
- if (input.response.ok) return;
679
- throw parseGatewayErrorResponse(input);
680
- }
681
- function parseGatewayErrorResponse(input) {
682
- const payload = parseJsonResponse(input.raw);
683
- const parsed = gatewayErrorEnvelopeSchema.safeParse(payload);
684
- const headerRequestId = normalizeOptionalText(input.response.headers.get(OPENMELD_HEADER_REQUEST_ID));
685
- if (parsed.success) return new GatewayHttpError({
686
- code: parsed.data.error.code,
687
- message: parsed.data.error.message,
688
- requestId: parsed.data.error.requestId || headerRequestId,
689
- status: input.response.status,
690
- rawBody: input.raw,
691
- upstreamCode: parsed.data.error.upstreamCode ?? null
692
- });
693
- const looseEnvelope = readLooseGatewayErrorEnvelope(payload);
694
- if (looseEnvelope) return new GatewayHttpError({
695
- code: looseEnvelope.code ?? FALLBACK_GATEWAY_HTTP_ERROR_CODE,
696
- message: looseEnvelope.message ?? `Gateway request failed with HTTP ${input.response.status}.`,
697
- requestId: looseEnvelope.requestId ?? headerRequestId,
698
- status: input.response.status,
699
- rawBody: input.raw,
700
- upstreamCode: looseEnvelope.upstreamCode
701
- });
702
- return new GatewayHttpError({
703
- code: FALLBACK_GATEWAY_HTTP_ERROR_CODE,
704
- message: normalizeOptionalText(input.raw) ?? `Gateway request failed with HTTP ${input.response.status}.`,
705
- requestId: headerRequestId,
706
- status: input.response.status,
707
- rawBody: input.raw,
708
- upstreamCode: null
709
- });
710
- }
711
- function toStructuredGatewayFailure(error) {
712
- if (error instanceof OpenMeldApiClientHttpError) return {
713
- code: error.code,
714
- message: normalizeFailureMessage(error.message),
715
- requestId: error.requestId,
716
- status: error.status,
717
- upstreamCode: error.upstreamCode
718
- };
719
- if (error instanceof GatewayHttpError) return {
720
- code: error.code,
721
- message: normalizeFailureMessage(error.message),
722
- requestId: error.requestId,
723
- status: error.status,
724
- upstreamCode: error.upstreamCode
725
- };
726
- const genericErrorCode = readGenericErrorCode(error);
727
- if (genericErrorCode) return {
728
- code: genericErrorCode,
729
- message: normalizeFailureMessage(error instanceof Error ? error.message : String(error)),
730
- requestId: null,
731
- status: null,
732
- upstreamCode: null
733
- };
734
- return {
735
- code: null,
736
- message: normalizeFailureMessage(error instanceof Error ? error.message : String(error)),
737
- requestId: null,
738
- status: null,
739
- upstreamCode: null
740
- };
741
- }
742
- function normalizeOptionalText(value) {
743
- const normalized = String(value ?? "").trim();
744
- return normalized.length > 0 ? normalized : null;
745
- }
746
- function normalizeFailureMessage(value) {
747
- return normalizeOptionalText(value) ?? "Unknown error.";
748
- }
749
- function readGenericErrorCode(value) {
750
- if (!value || typeof value !== "object" || !("code" in value)) return null;
751
- return normalizeOptionalText(value.code ?? null);
752
- }
753
- function readLooseGatewayErrorEnvelope(value) {
754
- if (!value || typeof value !== "object") return null;
755
- const error = value.error;
756
- if (!error || typeof error !== "object") return null;
757
- const code = normalizeOptionalText(error.code);
758
- const message = normalizeOptionalText(error.message);
759
- const requestId = normalizeOptionalText(error.requestId);
760
- const upstreamCode = normalizeOptionalText(error.upstreamCode);
761
- if (!(code || message || requestId || upstreamCode)) return null;
762
- return {
763
- code,
764
- message,
765
- requestId,
766
- upstreamCode
767
- };
768
- }
769
- //#endregion
770
- //#region src/space/space-meta-response.ts
771
- function parseSpaceMetaPayload(input) {
772
- try {
773
- const validation = spaceMetaSchema.safeParse(input.data);
774
- if (!validation.success) {
775
- const reason = validation.error.issues[0]?.message ?? "space meta payload does not match schema";
776
- throw new Error(reason);
777
- }
778
- return validation.data;
779
- } catch (error) {
780
- const reason = error instanceof Error ? error.message : String(error);
781
- throw new Error(`${input.operation} received invalid response payload from ${input.endpoint}: ${reason}; raw=${JSON.stringify(input.data)}`);
782
- }
783
- }
784
- function parseSpaceMetaResponse(input) {
785
- try {
786
- return parseSpaceMetaPayload({
787
- data: JSON.parse(input.raw),
788
- endpoint: input.endpoint,
789
- operation: input.operation
790
- });
791
- } catch (error) {
792
- const reason = error instanceof Error ? error.message : String(error);
793
- throw new Error(`${input.operation} received invalid response payload from ${input.endpoint}: ${reason}; raw=${input.raw}`);
794
- }
795
- }
796
- //#endregion
797
- //#region src/space/meta-api.ts
798
- async function fetchSpaceMeta(input) {
799
- const endpoint = toSpaceMetaUrl(input.baseUrl, input.space);
800
- return parseSpaceMetaResponse({
801
- raw: await readGatewayTextResponse({ response: await fetchSpaceRequestWithTimeout({
802
- url: endpoint,
803
- operation: "space.fetch_meta",
804
- init: {
805
- method: "GET",
806
- headers: await buildOpenMeldRequestContextHeadersWithAuth({
807
- requestUrl: endpoint,
808
- requestContext: input.requestContext,
809
- spacePassword: input.password
810
- })
811
- }
812
- }) }),
813
- endpoint,
814
- operation: "fetchSpaceMeta"
815
- });
816
- }
817
- async function updateSpaceMeta(input) {
818
- const endpoint = toSpaceMetaUrl(input.baseUrl, input.space);
819
- const headers = await buildOpenMeldRequestContextHeadersWithAuth({
820
- requestUrl: endpoint,
821
- requestContext: input.requestContext,
822
- spacePassword: input.password
823
- });
824
- headers["content-type"] = "application/json";
825
- return parseSpaceMetaResponse({
826
- raw: await readGatewayTextResponse({ response: await fetchSpaceRequestWithTimeout({
827
- url: endpoint,
828
- operation: "space.update_meta",
829
- init: {
830
- method: "PATCH",
831
- headers,
832
- body: JSON.stringify({
833
- ...input.purpose === void 0 ? {} : { purpose: input.purpose },
834
- ...input.guide === void 0 ? {} : { guide: input.guide }
835
- })
836
- }
837
- }) }),
838
- endpoint,
839
- operation: "updateSpaceMeta"
840
- });
841
- }
842
- //#endregion
843
- export { supersedeDispatchSpaceActionRecordForReconsideration as C, readDispatchSpaceActionRecord as S, DispatchSpaceActionRejectedError as _, GatewayHttpError as a, readDispatchSpaceActionContextForReceiptFromEnv as b, toStructuredGatewayFailure as c, uploadPreparedSpaceFiles as d, createCliSpaceApi as f, DispatchSpaceActionClosedError as g, readDispatchOwnedRuntimeGuard as h, parseSpaceMetaResponse as i, parseJsonResponse as l, buildDispatchOwnedRuntimeEnv as m, updateSpaceMeta as n, readGatewayJsonResponse as o, assertDispatchOwnedRuntimePublicWriteAllowed as p, parseSpaceMetaPayload as r, readGatewayTextResponse as s, fetchSpaceMeta as t, prepareRequestedSpaceSendFiles as u, OPENMELD_SPACE_ACTION_CONTEXT_PATH_ENV as v, writeDispatchSpaceActionRecord as w, readDispatchSpaceActionContextFromEnv as x, createDispatchSpaceActionContext as y };
844
-
845
- //# sourceMappingURL=meta-api-CEw8eOeN.js.map