evolcore 0.0.42-test.0 → 0.0.43-test.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.
Files changed (187) hide show
  1. package/CHANGELOG.md +31 -2
  2. package/bin/ec-safe-output.js +4 -1
  3. package/dist/ability/application-service.js +882 -0
  4. package/dist/ability/authorization.js +70 -0
  5. package/dist/ability/command-contract.js +105 -0
  6. package/dist/ability/daemon.js +137 -0
  7. package/dist/ability/development.js +450 -0
  8. package/dist/ability/environment.js +75 -0
  9. package/dist/ability/interop-v1.js +547 -0
  10. package/dist/ability/management.js +79 -0
  11. package/dist/ability/package.js +264 -0
  12. package/dist/ability/provider.js +73 -0
  13. package/dist/ability/publication.js +107 -0
  14. package/dist/ability/resources.js +106 -0
  15. package/dist/ability/runtime.js +212 -0
  16. package/dist/ability/secrets.js +47 -0
  17. package/dist/ability/store.js +112 -0
  18. package/dist/ability/toolchain.js +69 -0
  19. package/dist/ability/types.js +14 -0
  20. package/dist/ability/versions.js +32 -0
  21. package/dist/agents/baseagent.js +2 -2
  22. package/dist/agents/claude-runner.js +4 -0
  23. package/dist/agents/codex-runner.js +81 -17
  24. package/dist/agents/ecagent-plugin-lazy.js +41 -0
  25. package/dist/agents/ecagent-runner.js +18 -11
  26. package/dist/aun/ability-device-routing.js +12 -1
  27. package/dist/aun/aid/agentmd.js +2 -2
  28. package/dist/aun/aid/identity.js +45 -0
  29. package/dist/aun/aid/index.js +1 -0
  30. package/dist/aun/aid/managed-operation.js +73 -2
  31. package/dist/channels/aun.js +64 -18
  32. package/dist/channels/builtin-plugins.js +14 -0
  33. package/dist/channels/dingtalk.js +78 -26
  34. package/dist/channels/feishu.js +89 -14
  35. package/dist/channels/qqbot.js +84 -19
  36. package/dist/channels/wechat.js +77 -19
  37. package/dist/channels/wecom.js +67 -22
  38. package/dist/cli/ability-command.js +92 -0
  39. package/dist/cli/aun-commands.js +124 -85
  40. package/dist/cli/daemon-commands.js +37 -85
  41. package/dist/cli/index.js +14 -0
  42. package/dist/cli/init.js +11 -13
  43. package/dist/cli/managed-command-guard.js +6 -0
  44. package/dist/cli/model.js +101 -104
  45. package/dist/cli/provider-command.js +6 -4
  46. package/dist/cli/restart-monitor.js +52 -11
  47. package/dist/cli/upgrade-command.js +102 -0
  48. package/dist/cli/version.js +1 -1
  49. package/dist/config/access-policy.js +4 -2
  50. package/dist/config/builtin-roles.js +1 -0
  51. package/dist/config/config-field-policy.js +4 -0
  52. package/dist/config/config-manager.js +7 -0
  53. package/dist/config/provider-ipc-service.js +10 -0
  54. package/dist/config/providers-config.js +12 -3
  55. package/dist/config/providers-management.js +45 -9
  56. package/dist/config/schema-migration.js +40 -22
  57. package/dist/contracts/ecweb-service-protocol.js +2 -1
  58. package/dist/core/auth/agent-delegation.js +21 -5
  59. package/dist/core/auth/auth-gateway.js +31 -9
  60. package/dist/core/auth/authorization-audit.js +52 -4
  61. package/dist/core/auth/delegation-authorization.js +140 -4
  62. package/dist/core/auth/operation-authorizer.js +114 -13
  63. package/dist/core/auth/operation-catalog.js +118 -4
  64. package/dist/core/baseagent-loader.js +14 -1
  65. package/dist/core/channel-loader.js +47 -9
  66. package/dist/core/channel-runtime.js +1 -1
  67. package/dist/core/command/agent-storage-menu.js +1 -1
  68. package/dist/core/command/cli-intent-parser.js +26 -13
  69. package/dist/core/command/command-handler.js +232 -76
  70. package/dist/core/command/connect-menu.js +10 -4
  71. package/dist/core/command/daemon-diagnostics.js +3 -3
  72. package/dist/core/command/data-root-resolver.js +2 -3
  73. package/dist/core/command/menu-catalog.js +10 -3
  74. package/dist/core/command/menu-handler.js +321 -46
  75. package/dist/core/command/menu-protocol.js +53 -7
  76. package/dist/core/command/pa-workspace-calendar.js +1 -2
  77. package/dist/core/command/pa-workspace-items.js +486 -0
  78. package/dist/core/command/pa-workspace-store.js +10 -1
  79. package/dist/core/command/slash-gate.js +2 -2
  80. package/dist/core/command/slash-handler.js +67 -25
  81. package/dist/core/contact-bind-registry.js +27 -0
  82. package/dist/core/daemon-control.js +3 -3
  83. package/dist/core/daemon-lifecycle.js +2 -1
  84. package/dist/core/event-bus.js +9 -2
  85. package/dist/core/handoff/ipc-registration.js +1 -0
  86. package/dist/core/host-snapshot.js +1 -2
  87. package/dist/core/initialization/service.js +32 -11
  88. package/dist/core/ipc-registration.js +18 -5
  89. package/dist/core/memory/consolidation-context.js +2 -2
  90. package/dist/core/message/aun-request-registry.js +99 -18
  91. package/dist/core/message/im-renderer.js +16 -11
  92. package/dist/core/message/message-admission.js +25 -20
  93. package/dist/core/message/message-bridge.js +21 -47
  94. package/dist/core/message/message-queue.js +3 -0
  95. package/dist/core/message/response-engine.js +7 -5
  96. package/dist/core/model/catalog-service.js +1 -1
  97. package/dist/core/permission/ec-command-parser.js +41 -9
  98. package/dist/core/permission/permission-result.js +1 -0
  99. package/dist/core/permission/protected-paths.js +25 -14
  100. package/dist/core/permission/tool-policy.js +108 -107
  101. package/dist/core/plugin-lifecycle.js +133 -0
  102. package/dist/core/runner-reload-transaction.js +4 -1
  103. package/dist/core/system-session/memory.js +16 -3
  104. package/dist/core/task/task-activity-store.js +50 -0
  105. package/dist/core/task/task-image-resources.js +140 -0
  106. package/dist/core/thread/ipc-operation.js +1 -1
  107. package/dist/core/thread/thread-service.js +0 -1
  108. package/dist/directory/canonical-digest.js +5 -3
  109. package/dist/directory/owner-directory-admission.js +22 -2
  110. package/dist/directory/owner-directory-cache.js +394 -60
  111. package/dist/directory/owner-directory-markdown.js +29 -2
  112. package/dist/directory/owner-directory-scope.js +35 -16
  113. package/dist/ecweb/basic-settings-service.js +4 -1
  114. package/dist/ecweb/pairing.js +41 -0
  115. package/dist/ecweb/providers-service.js +8 -1
  116. package/dist/{utils/ecweb-utils.js → ecweb/runtime/launch.js} +3 -27
  117. package/dist/ecweb/runtime/lifecycle.js +184 -0
  118. package/dist/{utils/ecweb-supervisor.js → ecweb/runtime/supervisor.js} +32 -27
  119. package/dist/index.js +34 -25
  120. package/dist/ipc.js +124 -7
  121. package/dist/response-system/engines/v1/proactive-flow.js +1 -1
  122. package/dist/trigger/authorization.js +2 -2
  123. package/dist/utils/atomic-write.js +24 -0
  124. package/dist/utils/avatar-upload.js +3 -1
  125. package/dist/utils/cross-platform.js +31 -2
  126. package/dist/utils/host-info.js +36 -0
  127. package/dist/utils/instance-registry.js +38 -11
  128. package/dist/utils/logger.js +9 -0
  129. package/dist/utils/{process-tree-stats.js → process-tree.js} +29 -0
  130. package/dist/utils/tool-summary.js +9 -1
  131. package/dist/utils/upgrade-jobs.js +96 -15
  132. package/dist/utils/windows-autostart.js +1 -1
  133. package/ecagent/README.md +19 -0
  134. package/ecagent/dist/harness/agent-harness.js +9 -0
  135. package/ecagent/dist/harness/env/nodejs.js +71 -11
  136. package/ecagent/dist/harness/env/windows-shell.d.ts +7 -0
  137. package/ecagent/dist/harness/env/windows-shell.js +132 -0
  138. package/kits/docs/aun/ABILITY_CALLING.md +38 -9
  139. package/kits/docs/evolcore/INDEX.md +5 -1
  140. package/kits/docs/evolcore/ability.md +181 -0
  141. package/kits/docs/evolcore/aid.md +20 -0
  142. package/kits/docs/evolcore/config.md +10 -6
  143. package/kits/docs/evolcore/menu-protocol.md +40 -1
  144. package/kits/docs/evolcore/provider.md +2 -2
  145. package/kits/docs/evolcore/tool-authorization.md +270 -0
  146. package/kits/runtime/ability-job.ps1 +41 -0
  147. package/kits/runtime/ability-runner.mjs +67 -0
  148. package/kits/runtime/ability-secret.ps1 +59 -0
  149. package/kits/runtime/ability-templates/go/main.go +59 -0
  150. package/kits/runtime/ability-templates/java/Json.java +67 -0
  151. package/kits/runtime/ability-templates/java/Runner.java +42 -0
  152. package/kits/runtime/ability-templates/python/runner.py +48 -0
  153. package/kits/runtime/ability-templates/rust/json.rs +87 -0
  154. package/kits/runtime/ability-templates/rust/runner.rs +35 -0
  155. package/kits/schemas/_meta.json +12 -1
  156. package/kits/schemas/ability-plugin.schema.1.json +107 -0
  157. package/kits/schemas/ability-project.schema.1.json +31 -0
  158. package/kits/schemas/agent-config.schema.16.json +20 -0
  159. package/kits/schemas/agent-config.schema.17.json +20 -0
  160. package/kits/schemas/agent-config.schema.18.json +917 -0
  161. package/kits/skills/.switches.json +4 -0
  162. package/kits/skills/aid-ability/SKILL.md +5 -4
  163. package/kits/skills/ec-ability/SKILL.md +67 -0
  164. package/kits/skills/ec-ability/references/contract-checklist.md +37 -0
  165. package/kits/skills/ec-ability/references/development.md +104 -0
  166. package/kits/skills/ec-ability/references/management.md +117 -0
  167. package/kits/skills/ec-ability/references/recovery.md +27 -0
  168. package/kits/skills/ec-ability/references/runtime-protocol.md +109 -0
  169. package/kits/skills/ec-ability/references/workflows.md +15 -0
  170. package/kits/skills/ec-service-proxy/SKILL.md +12 -0
  171. package/kits/skills/personal-assistant/SKILL.md +240 -6
  172. package/kits/skills/personal-assistant/references/02-bootstrap.md +78 -4
  173. package/kits/skills/personal-assistant/scripts/clean.mjs +397 -0
  174. package/kits/skills/personal-assistant/scripts/init.mjs +113 -25
  175. package/kits/skills/personal-assistant/scripts/lock.mjs +189 -0
  176. package/kits/skills/personal-assistant/scripts/migrate.mjs +35 -10
  177. package/kits/skills/personal-assistant/scripts/verify.mjs +2 -1
  178. package/kits/skills/personal-assistant/templates/persona-section.md +54 -0
  179. package/kits/skills/personal-assistant/triggers/ingest-daily.json +1 -1
  180. package/kits/templates/memory-consolidation/notes.md +1 -1
  181. package/kits/templates/system-fragments/channel.md +2 -1
  182. package/kits/templates/system-fragments/commands.md +1 -0
  183. package/package.json +4 -2
  184. package/dist/core/command/data-root-error.js +0 -10
  185. package/dist/utils/machine-info.js +0 -46
  186. package/dist/utils/process-tree-worker.js +0 -31
  187. package/dist/utils/windows-output.js +0 -36
@@ -0,0 +1,264 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { createHash, randomUUID } from 'node:crypto';
4
+ import { createRequire } from 'node:module';
5
+ import { gunzipSync } from 'node:zlib';
6
+ import Ajv from 'ajv';
7
+ import canonicalize from 'canonicalize';
8
+ import { getPackageRoot } from '../paths.js';
9
+ import { processRuntimeCommand } from './environment.js';
10
+ import { parseAbilityDefinition, sha256Hex } from './interop-v1.js';
11
+ import { abilityAssert } from './types.js';
12
+ const require = createRequire(import.meta.url);
13
+ const semver = require('semver');
14
+ const ajv = new Ajv({ allErrors: true, strict: false, useDefaults: false, addUsedSchema: false });
15
+ const MAX_BYTES = 32 * 1024 * 1024;
16
+ const RESERVED = new Set(['initialize', 'health', 'shutdown', 'invoke', 'cancel', 'log', 'broker', 'constructor', 'prototype', '__proto__']);
17
+ export function abilityTemp(prefix) {
18
+ const root = process.env.TMPDIR;
19
+ abilityAssert(root && path.isAbsolute(root), 'TEMP_UNAVAILABLE', 'Ability requires an absolute trusted TMPDIR', 503);
20
+ fs.mkdirSync(root, { recursive: true });
21
+ return fs.mkdtempSync(path.join(root, prefix));
22
+ }
23
+ export function packageFile(root, ref) {
24
+ abilityAssert(typeof ref === 'string' && /^[A-Za-z0-9._/-]+$/.test(ref) && !ref.split('/').some(part => !part || part === '.' || part === '..'), 'PACKAGE_PATH_INVALID', 'Invalid package path');
25
+ const result = path.resolve(root, ref);
26
+ abilityAssert(result.startsWith(path.resolve(root) + path.sep), 'PACKAGE_PATH_INVALID', 'Package reference leaves package');
27
+ return result;
28
+ }
29
+ function walk(root) {
30
+ const files = [];
31
+ let size = 0;
32
+ let entries = 0;
33
+ const names = new Set();
34
+ const visit = (relative) => {
35
+ for (const entry of fs.readdirSync(path.join(root, relative), { withFileTypes: true })) {
36
+ const name = relative ? relative + '/' + entry.name : entry.name;
37
+ abilityAssert(entry.name === entry.name.normalize('NFC') && !/[. ]$/.test(entry.name) && !/^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\.|$)/i.test(entry.name) && !names.has(name.toLowerCase()), 'PACKAGE_FILE_INVALID', 'Package names must be portable and unique');
38
+ names.add(name.toLowerCase());
39
+ const stat = fs.lstatSync(packageFile(root, name));
40
+ abilityAssert(++entries <= 4096 && !stat.isSymbolicLink() && (stat.isFile() || stat.isDirectory()), 'PACKAGE_FILE_INVALID', 'Package requires at most 4096 regular files/directories');
41
+ if (stat.isDirectory())
42
+ visit(name);
43
+ else {
44
+ size += stat.size;
45
+ abilityAssert(size <= MAX_BYTES, 'PACKAGE_TOO_LARGE', 'Package exceeds 32 MiB');
46
+ files.push(name);
47
+ }
48
+ }
49
+ };
50
+ visit('');
51
+ return files.sort();
52
+ }
53
+ export const abilityPackageFiles = walk;
54
+ export function packageDigest(root) {
55
+ const files = walk(root).map(name => { const bytes = fs.readFileSync(packageFile(root, name)); return { path: name, size: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') }; });
56
+ return sha256Hex(canonicalize(files));
57
+ }
58
+ function json(root, ref) {
59
+ const file = packageFile(root, ref);
60
+ const stat = fs.lstatSync(file);
61
+ abilityAssert(stat.isFile() && !stat.isSymbolicLink() && stat.size <= 1024 * 1024, 'PACKAGE_JSON_INVALID', 'Expected regular JSON under 1 MiB');
62
+ const value = JSON.parse(fs.readFileSync(file, 'utf8'));
63
+ abilityAssert(value && typeof value === 'object' && !Array.isArray(value), 'PACKAGE_JSON_INVALID', 'Expected JSON object');
64
+ return value;
65
+ }
66
+ export function validateAbilityConfig(schema, config) {
67
+ abilityAssert(config && typeof config === 'object' && !Array.isArray(config), 'CONFIG_INVALID', 'Configuration must be an object');
68
+ const validate = ajv.compile(schema);
69
+ abilityAssert(validate(config), 'CONFIG_INVALID', ajv.errorsText(validate.errors));
70
+ }
71
+ export function materializeDefinition(template, semanticRevision) {
72
+ const { summary, ...rest } = template;
73
+ const body = { ...rest, description: summary };
74
+ const definition_id = sha256Hex(canonicalize({ domain: 'evolcore.ability-contract/v1', semanticRevision, body }));
75
+ return parseAbilityDefinition({ ...body, definition_id });
76
+ }
77
+ export function validateAbilityPackage(root, source) {
78
+ const digest = packageDigest(root);
79
+ const manifest = json(root, 'ability-plugin.json');
80
+ const validate = ajv.compile(JSON.parse(fs.readFileSync(path.join(getPackageRoot(), 'kits/schemas/ability-plugin.schema.1.json'), 'utf8')));
81
+ abilityAssert(validate(manifest), 'MANIFEST_INVALID', ajv.errorsText(validate.errors));
82
+ const version = JSON.parse(fs.readFileSync(path.join(getPackageRoot(), 'package.json'), 'utf8')).version;
83
+ const coreRange = manifest.engines.evolcore;
84
+ abilityAssert(semver.validRange(coreRange) && semver.satisfies(version, coreRange, { includePrerelease: true }), 'ENGINE_UNSUPPORTED', `evolcore ${version} does not satisfy ${coreRange}`);
85
+ if (manifest.runtime.kind === 'node-subprocess') {
86
+ const nodeRange = manifest.engines.node;
87
+ abilityAssert(nodeRange && semver.validRange(nodeRange) && semver.satisfies(process.versions.node, nodeRange), 'ENGINE_UNSUPPORTED', `node ${process.versions.node} does not satisfy ${nodeRange ?? '<missing>'}`);
88
+ }
89
+ abilityAssert(manifest.platforms.includes(process.platform), 'PLATFORM_UNSUPPORTED', 'Package does not support this platform');
90
+ abilityAssert(!manifest.architectures || manifest.architectures.includes(process.arch), 'ARCHITECTURE_UNSUPPORTED', 'Package does not support this CPU architecture');
91
+ for (const [engine, range] of Object.entries(manifest.engines))
92
+ abilityAssert(semver.validRange(range), 'ENGINE_UNSUPPORTED', `Invalid ${engine} engine range: ${range}`);
93
+ for (const origin of manifest.permissions.networkOrigins) {
94
+ const url = new URL(origin);
95
+ abilityAssert(url.origin === origin && url.protocol === 'https:' && !url.username && !url.password, 'ORIGIN_INVALID', 'Network permissions require canonical HTTPS origins');
96
+ }
97
+ if (manifest.runtime.kind === 'node-subprocess') {
98
+ const entry = packageFile(root, manifest.runtime.entry);
99
+ abilityAssert(fs.statSync(entry).isFile() && /\.(?:mjs|js)$/.test(manifest.runtime.entry), 'ENTRY_INVALID', 'Prebuilt JavaScript entry required');
100
+ }
101
+ else {
102
+ if (manifest.runtime.entry)
103
+ abilityAssert(fs.existsSync(packageFile(root, manifest.runtime.entry)) && fs.statSync(packageFile(root, manifest.runtime.entry)).isFile(), 'ENTRY_INVALID', 'Runtime entry is missing');
104
+ for (const arg of processRuntimeCommand(manifest.runtime)) {
105
+ abilityAssert(!arg.includes('\0'), 'RUNTIME_COMMAND_INVALID', 'Runtime command contains a NUL byte');
106
+ if (arg.startsWith('package:')) {
107
+ const ref = arg.slice('package:'.length);
108
+ const file = packageFile(root, ref);
109
+ abilityAssert(fs.existsSync(file) && fs.statSync(file).isFile(), 'ENTRY_INVALID', 'Package runtime references a missing file');
110
+ }
111
+ }
112
+ }
113
+ const configSchema = json(root, manifest.configSchema);
114
+ abilityAssert(ajv.validateSchema(configSchema), 'CONFIG_SCHEMA_INVALID', 'Invalid configuration schema');
115
+ const paths = new Set();
116
+ const handlers = new Set();
117
+ const definitions = manifest.abilities.map(item => {
118
+ abilityAssert(!RESERVED.has(item.handler) && !handlers.has(item.handler), 'HANDLER_INVALID', 'Duplicate or reserved handler');
119
+ handlers.add(item.handler);
120
+ const definition = json(root, item.definition);
121
+ const usage = json(root, item.usage);
122
+ abilityAssert(typeof definition.name === 'string' && !!definition.name && typeof definition.summary === 'string' && !('definition_id' in definition), 'DEFINITION_INVALID', 'Template requires name/summary and no definition_id');
123
+ const materialized = materializeDefinition(definition, 'validation');
124
+ abilityAssert(!paths.has(materialized.path), 'PATH_CONFLICT', 'Duplicate ability path');
125
+ paths.add(materialized.path);
126
+ abilityAssert(usage.schema === 'aun.ability.usage.v1' && usage.path === materialized.path && Array.isArray(usage.examples) && usage.examples.length && Array.isArray(usage.result_processing) && usage.result_processing.length && usage.result_processing.every(value => typeof value === 'string' && value.length), 'USAGE_INVALID', 'Usage must match definition');
127
+ const params = ajv.compile(materialized.params_schema);
128
+ for (const example of usage.examples)
129
+ abilityAssert(example && params(example.params), 'USAGE_INVALID', 'Usage example does not match schema');
130
+ return { handler: item.handler, definition, usage };
131
+ });
132
+ return { digest, manifest, configSchema, definitions, source, root, createdAt: Date.now() };
133
+ }
134
+ /** Execute permission is derived from the reviewed Manifest, never from archive metadata. */
135
+ export function abilityExecutableEntry(manifest) {
136
+ if (manifest.runtime.kind !== 'process-rpc')
137
+ return undefined;
138
+ const first = processRuntimeCommand(manifest.runtime)[0];
139
+ return first.startsWith('package:') ? first.slice('package:'.length) : undefined;
140
+ }
141
+ function unpack(bytes, root) {
142
+ const tar = gunzipSync(bytes, { maxOutputLength: MAX_BYTES });
143
+ let count = 0;
144
+ for (let offset = 0; offset + 512 <= tar.length;) {
145
+ const header = tar.subarray(offset, offset + 512);
146
+ offset += 512;
147
+ if (header.every(byte => byte === 0))
148
+ break;
149
+ const text = (start, length) => header.subarray(start, start + length).toString('utf8').replace(/\0.*$/s, '');
150
+ const prefix = text(345, 155);
151
+ const name = (prefix ? prefix + '/' : '') + text(0, 100);
152
+ const size = Number.parseInt(text(124, 12).trim() || '0', 8);
153
+ const type = text(156, 1);
154
+ const checksum = Number.parseInt(text(148, 8).trim(), 8);
155
+ const actual = header.reduce((sum, byte, index) => sum + (index >= 148 && index < 156 ? 32 : byte), 0);
156
+ abilityAssert(checksum === actual && Number.isSafeInteger(size) && size >= 0 && size <= MAX_BYTES && offset + size <= tar.length, 'ARCHIVE_INVALID', 'Invalid archive header/size');
157
+ abilityAssert(++count <= 4096 && ['', '0', '5'].includes(type), 'ARCHIVE_UNSUPPORTED', 'Archive supports regular files and directories only');
158
+ const file = packageFile(root, name.replace(/\/$/, ''));
159
+ if (type === '5')
160
+ fs.mkdirSync(file, { recursive: true });
161
+ else {
162
+ fs.mkdirSync(path.dirname(file), { recursive: true });
163
+ fs.writeFileSync(file, tar.subarray(offset, offset + size), { flag: 'wx' });
164
+ }
165
+ offset += Math.ceil(size / 512) * 512;
166
+ }
167
+ }
168
+ async function download(url, jsonResponse = false) {
169
+ let current = new URL(url);
170
+ for (let redirects = 0; redirects < 6; redirects++) {
171
+ abilityAssert(current.protocol === 'https:' && ['api.github.com', 'github.com', 'release-assets.githubusercontent.com', 'objects.githubusercontent.com'].includes(current.hostname), 'SOURCE_INVALID', 'Only GitHub release downloads supported');
172
+ const response = await fetch(current, { redirect: 'manual', signal: AbortSignal.timeout(30_000), headers: { Accept: jsonResponse ? 'application/vnd.github+json' : 'application/octet-stream' } });
173
+ if (response.status >= 300 && response.status < 400 && response.headers.get('location')) {
174
+ current = new URL(response.headers.get('location'), current);
175
+ continue;
176
+ }
177
+ abilityAssert(response.ok && response.body, 'SOURCE_UNAVAILABLE', 'GitHub release download failed', 502);
178
+ const chunks = [];
179
+ let size = 0;
180
+ for await (const chunk of response.body) {
181
+ size += chunk.length;
182
+ abilityAssert(size <= MAX_BYTES, 'PACKAGE_TOO_LARGE', 'Download exceeds 32 MiB');
183
+ chunks.push(Buffer.from(chunk));
184
+ }
185
+ return Buffer.concat(chunks);
186
+ }
187
+ throw new Error('Too many release redirects');
188
+ }
189
+ export async function acquireAbilityPackage(locator, objectsRoot) {
190
+ const temp = abilityTemp('ability-package-');
191
+ let source;
192
+ let root = temp;
193
+ try {
194
+ if (locator.startsWith('github:')) {
195
+ const match = locator.match(/^github:([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)@([^#]+)#asset=([^/]+\.tgz)$/);
196
+ abilityAssert(match, 'SOURCE_INVALID', 'Use github:owner/repo@tag#asset=prebuilt.tgz');
197
+ const base = `https://api.github.com/repos/${match[1]}/${match[2]}`;
198
+ const release = JSON.parse((await download(`${base}/releases/tags/${encodeURIComponent(match[3])}`, true)).toString('utf8'));
199
+ const commit = JSON.parse((await download(`${base}/commits/${encodeURIComponent(match[3])}`, true)).toString('utf8'));
200
+ const asset = release.assets?.find((value) => value.name === match[4]);
201
+ abilityAssert(asset && /^[a-f0-9]{40}$/.test(commit.sha), 'SOURCE_INVALID', 'Missing release asset or immutable commit');
202
+ const bytes = await download(asset.browser_download_url);
203
+ unpack(bytes, temp);
204
+ source = { kind: 'github', locator, commit: commit.sha, artifactDigest: createHash('sha256').update(bytes).digest('hex') };
205
+ }
206
+ else {
207
+ const local = path.resolve(locator);
208
+ const stat = fs.lstatSync(local);
209
+ abilityAssert(path.isAbsolute(locator) && !stat.isSymbolicLink(), 'SOURCE_INVALID', 'Local source must be an absolute prebuilt directory or tgz');
210
+ if (stat.isFile()) {
211
+ abilityAssert(local.endsWith('.tgz') && stat.size <= MAX_BYTES, 'SOURCE_INVALID', 'Local archive must be a prebuilt tgz under 32 MiB');
212
+ const bytes = fs.readFileSync(local);
213
+ unpack(bytes, temp);
214
+ source = { kind: 'local', locator: local, artifactDigest: createHash('sha256').update(bytes).digest('hex') };
215
+ }
216
+ else {
217
+ abilityAssert(stat.isDirectory(), 'SOURCE_INVALID', 'Expected a prebuilt package directory');
218
+ for (const name of walk(local)) {
219
+ const target = packageFile(temp, name);
220
+ fs.mkdirSync(path.dirname(target), { recursive: true });
221
+ fs.copyFileSync(packageFile(local, name), target, fs.constants.COPYFILE_EXCL);
222
+ }
223
+ source = { kind: 'local', locator: local };
224
+ }
225
+ }
226
+ if (!fs.existsSync(path.join(root, 'ability-plugin.json'))) {
227
+ const dirs = fs.readdirSync(root, { withFileTypes: true });
228
+ if (dirs.length === 1 && dirs[0].isDirectory())
229
+ root = path.join(root, dirs[0].name);
230
+ }
231
+ const pkg = validateAbilityPackage(root, source);
232
+ const destination = path.join(objectsRoot, pkg.digest);
233
+ fs.mkdirSync(objectsRoot, { recursive: true });
234
+ if (!fs.existsSync(destination)) {
235
+ const pending = path.join(objectsRoot, '.pending-' + randomUUID());
236
+ try {
237
+ fs.cpSync(root, pending, { recursive: true, errorOnExist: true, force: false });
238
+ abilityAssert(packageDigest(pending) === pkg.digest, 'PACKAGE_CHANGED', 'Package changed while preparing object');
239
+ for (const name of walk(pending)) {
240
+ const fd = fs.openSync(packageFile(pending, name), 'r+');
241
+ try {
242
+ fs.fsyncSync(fd);
243
+ }
244
+ finally {
245
+ fs.closeSync(fd);
246
+ }
247
+ }
248
+ if (!fs.existsSync(destination))
249
+ fs.renameSync(pending, destination);
250
+ }
251
+ finally {
252
+ fs.rmSync(pending, { recursive: true, force: true });
253
+ }
254
+ }
255
+ abilityAssert(packageDigest(destination) === pkg.digest, 'PACKAGE_CHANGED', 'Stored package integrity mismatch');
256
+ const entry = abilityExecutableEntry(pkg.manifest);
257
+ if (entry && process.platform !== 'win32')
258
+ fs.chmodSync(packageFile(destination, entry), 0o755);
259
+ return { ...pkg, root: destination };
260
+ }
261
+ finally {
262
+ fs.rmSync(temp, { recursive: true, force: true });
263
+ }
264
+ }
@@ -0,0 +1,73 @@
1
+ import { abilitySummary, parseAbilityCall, ABILITY_SPEC_VERSION, AbilityProtocolError } from './interop-v1.js';
2
+ import { AbilityError } from './types.js';
3
+ let provider;
4
+ export function installAbilityProvider(service) {
5
+ const handler = async (input) => handleAbilityInbound(service, input);
6
+ provider = handler;
7
+ return () => { if (provider === handler)
8
+ provider = undefined; };
9
+ }
10
+ export async function dispatchAbilityInbound(input) {
11
+ const payload = input.payload;
12
+ if (!payload || typeof payload !== 'object' || payload.type !== 'ability' || payload.role !== 'call')
13
+ return false;
14
+ if (provider)
15
+ await provider(input);
16
+ return true;
17
+ }
18
+ export async function handleAbilityInbound(service, input) {
19
+ // The channel supplies these values from the authenticated private envelope.
20
+ if (!input.encrypted || !input.callerDeviceId || !input.callerAid)
21
+ return;
22
+ const raw = input.payload;
23
+ let admitted = false;
24
+ try {
25
+ const call = parseAbilityCall(raw);
26
+ const common = { type: 'ability', call_id: call.call_id, operation_id: call.operation_id, ability_path: call.ability_path,
27
+ ...(call.definition_id ? { definition_id: call.definition_id } : {}) };
28
+ if (call.ability_path === 'protocol/discover') {
29
+ const rows = service.published(input.selfAid).filter(row => row.instance.publicationState === 'published');
30
+ await input.send({ ...common, role: 'result', ok: true, execution_state: 'completed', result: {
31
+ protocol: { spec_version: ABILITY_SPEC_VERSION }, capabilities: rows.map(row => abilitySummary(row.definition, input.selfAid, row.releaseId, row.version)),
32
+ } });
33
+ return;
34
+ }
35
+ // Find historical operations through the durable store before requiring a
36
+ // current path, so a completed operation survives a later upgrade/unpublish.
37
+ let historical;
38
+ try {
39
+ historical = await service.remoteResult(input.callerAid, input.selfAid, call.operation_id);
40
+ }
41
+ catch (error) {
42
+ if (!(error instanceof AbilityError) || error.code !== 'RESULT_WITHHELD')
43
+ throw error;
44
+ }
45
+ const pathRow = service.published(input.selfAid).find(item => item.definition.path === call.ability_path && item.instance.publicationState === 'published');
46
+ if (!historical && pathRow && pathRow.definition.definition_id !== call.definition_id)
47
+ throw new AbilityError('CONTRACT_CHANGED', 'Ability contract changed; refresh discovery', 409);
48
+ const row = pathRow?.definition.definition_id === call.definition_id ? pathRow : undefined;
49
+ const instanceId = historical?.instanceId ?? row?.instance.id;
50
+ if (!instanceId)
51
+ throw new AbilityError('ABILITY_NOT_FOUND', 'Published ability is unavailable', 404);
52
+ const flight = service.invoke(input.callerAid, input.selfAid, instanceId, call.ability_path, call.definition_id, call.params, call.operation_id, { remote: true, async: call.async });
53
+ if (call.async)
54
+ await input.send({ ...common, role: 'ack', execution_state: 'pending' }).catch(() => { });
55
+ const operation = await flight;
56
+ admitted = true;
57
+ if (operation.state === 'executing') {
58
+ await input.send({ ...common, role: 'ack', execution_state: 'pending' });
59
+ return;
60
+ }
61
+ const current = await service.remoteResult(input.callerAid, input.selfAid, call.operation_id);
62
+ await input.send({ ...common, role: 'result', ok: current.ok === true, execution_state: current.state,
63
+ ...(current.ok ? { result: current.result } : { error: { code: current.error?.code.toLowerCase() ?? 'execution_unknown', message: 'Execution outcome is unknown; query the original operation' } }) });
64
+ }
65
+ catch (error) {
66
+ if (typeof raw.call_id !== 'string' || raw.call_id.length > 256 || typeof raw.operation_id !== 'string' || raw.operation_id.length > 256)
67
+ return;
68
+ const code = error instanceof AbilityError || error instanceof AbilityProtocolError ? error.code.toLowerCase() : 'provider_unavailable';
69
+ await input.send({ type: 'ability', role: 'result', call_id: raw.call_id, operation_id: raw.operation_id,
70
+ ...(typeof raw.ability_path === 'string' ? { ability_path: raw.ability_path } : {}), ...(typeof raw.definition_id === 'string' ? { definition_id: raw.definition_id } : {}),
71
+ ok: false, execution_state: admitted || code === 'result_withheld' ? 'unknown' : 'not_executed', error: { code, message: 'Ability request could not be completed; refresh discovery or check authorization' } });
72
+ }
73
+ }
@@ -0,0 +1,107 @@
1
+ import { AbilityError } from './types.js';
2
+ const NOT_FOUND_CODES = new Set([404, 4040, '404', 'NOT_FOUND', 'ENOENT', 'not_found', -32008]);
3
+ const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
4
+ function errorCode(error) {
5
+ return error && typeof error === 'object' ? error.code : undefined;
6
+ }
7
+ async function verifyPublicDocument(publisherAid, document) {
8
+ let url = `https://${publisherAid}${document.path.split('/').map(encodeURIComponent).join('/')}`;
9
+ const signal = AbortSignal.timeout(15000);
10
+ for (let redirects = 0;; redirects++) {
11
+ const response = await fetch(url, { redirect: 'manual', credentials: 'omit', cache: 'no-store', signal });
12
+ if (REDIRECT_STATUSES.has(response.status)) {
13
+ const location = response.headers.get('location');
14
+ await response.body?.cancel();
15
+ if (!location || redirects >= 5)
16
+ throw new AbilityError('PUBLICATION_NOT_PUBLIC', `Anonymous contract redirect verification failed: ${document.path}`, 502);
17
+ let next;
18
+ try {
19
+ next = new URL(location, url);
20
+ }
21
+ catch {
22
+ throw new AbilityError('PUBLICATION_NOT_PUBLIC', `Anonymous contract redirect URL is invalid: ${document.path}`, 502);
23
+ }
24
+ if (next.protocol !== 'https:' || next.username || next.password)
25
+ throw new AbilityError('PUBLICATION_NOT_PUBLIC', `Anonymous contract redirect must use HTTPS without credentials: ${document.path}`, 502);
26
+ url = next.href;
27
+ continue;
28
+ }
29
+ if (!response.ok || !response.body)
30
+ throw new AbilityError('PUBLICATION_NOT_PUBLIC', `Anonymous contract read verification failed: ${document.path} (HTTP ${response.status})`, 502);
31
+ const chunks = [];
32
+ let size = 0;
33
+ for await (const chunk of response.body) {
34
+ size += chunk.length;
35
+ if (size > 4 * 1024 * 1024)
36
+ throw new AbilityError('PUBLICATION_NOT_PUBLIC', 'Anonymous contract read exceeds limit', 502);
37
+ chunks.push(chunk);
38
+ }
39
+ if (Buffer.concat(chunks).toString('utf8') !== document.content)
40
+ throw new AbilityError('PUBLICATION_NOT_PUBLIC', `Anonymous contract bytes differ: ${document.path}`, 502);
41
+ return;
42
+ }
43
+ }
44
+ /** Publish through the target AID's authenticated storage, then verify public reads. */
45
+ export async function publishAbilityDocuments(storage, publisherAid, documents, expectedIndexes = []) {
46
+ for (const document of documents) {
47
+ let stage = 'mkdir';
48
+ try {
49
+ const immutable = document.path !== '/ability/index.json';
50
+ const parent = document.path.slice(0, document.path.lastIndexOf('/'));
51
+ try {
52
+ await storage.mkdir(parent, { parents: true });
53
+ }
54
+ catch (error) {
55
+ // AUN can return EEXIST even with parents:true. Only accept an actual
56
+ // directory; files, links, permission failures and other errors remain failures.
57
+ if (errorCode(error) !== 'EEXIST')
58
+ throw error;
59
+ stage = 'lstat-directory';
60
+ const existing = await storage.lstat(parent, { noCache: true });
61
+ if (existing.type !== 'dir')
62
+ throw new AbilityError('PUBLICATION_PATH_CONFLICT', `Ability publication parent is not a directory: ${parent}`, 409);
63
+ }
64
+ let existing;
65
+ let version;
66
+ try {
67
+ stage = 'stat-document';
68
+ version = (await storage.stat(document.path, { noCache: true })).version;
69
+ stage = 'read-document';
70
+ existing = await storage.readBytes(document.path, { noCache: true });
71
+ }
72
+ catch (error) {
73
+ if (!NOT_FOUND_CODES.has(errorCode(error)))
74
+ throw error;
75
+ }
76
+ if (existing && Buffer.from(existing).toString('utf8') !== document.content) {
77
+ if (immutable)
78
+ throw new AbilityError('IMMUTABLE_CONFLICT', 'Immutable ability document differs', 409);
79
+ if (!expectedIndexes.includes(Buffer.from(existing).toString('utf8')))
80
+ throw new AbilityError('PUBLICATION_CONFLICT', 'Existing AID index is not owned by this publication intent', 409);
81
+ }
82
+ if (!existing || Buffer.from(existing).toString('utf8') !== document.content) {
83
+ stage = 'write-document';
84
+ await storage.writeBytes(document.path, Buffer.from(document.content, 'utf8'), {
85
+ contentType: 'application/json', public: true, overwrite: !!existing, ...(existing ? { expectedVersion: version } : {}),
86
+ });
87
+ }
88
+ stage = 'verify-storage';
89
+ const saved = await storage.readBytes(document.path, { noCache: true });
90
+ if (Buffer.from(saved).toString('utf8') !== document.content)
91
+ throw new AbilityError('PUBLICATION_VERIFY_FAILED', `Ability publication storage bytes differ: ${document.path}`, 502);
92
+ stage = 'verify-public';
93
+ await verifyPublicDocument(publisherAid, document);
94
+ }
95
+ catch (error) {
96
+ if (error instanceof AbilityError)
97
+ throw error;
98
+ const code = errorCode(error) ?? errorCode(error instanceof Error ? error.cause : undefined);
99
+ const detail = (typeof code === 'number' && Number.isSafeInteger(code)) || (typeof code === 'string' && /^[A-Z0-9_-]{1,64}$/.test(code))
100
+ ? ` (${code})` : '';
101
+ // Keep actionable context without exposing arbitrary SDK messages or response bodies.
102
+ const failure = new AbilityError('PUBLICATION_FAILED', `Ability publication ${stage} failed for ${document.path}${detail}`, 502);
103
+ failure.cause = error;
104
+ throw failure;
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,106 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import https from 'node:https';
4
+ import { lookup } from 'node:dns/promises';
5
+ import { isIP, BlockList } from 'node:net';
6
+ import { getPackageRoot, resolvePaths } from '../paths.js';
7
+ import { isHClassPath, isLClassPath, isSameOrDescendant } from '../core/permission/protected-paths.js';
8
+ import { AbilityError, abilityAssert } from './types.js';
9
+ export function activeGrants(instance, permission) {
10
+ return instance.grants.filter(value => value.permission === permission && !value.revokedAt && !!value.expiresAt && value.expiresAt > Date.now() && value.issuedByAid === instance.approvedByAid);
11
+ }
12
+ export function validateResourceGrant(permission, value, pkg) {
13
+ if (permission === 'workspace') {
14
+ abilityAssert(value && path.isAbsolute(value.root) && ['read', 'read-write'].includes(value.mode) && pkg.manifest.permissions.workspace !== 'none' && (value.mode !== 'read-write' || pkg.manifest.permissions.workspace === 'read-write'), 'GRANT_INVALID', 'Workspace grant must fit manifest permissions');
15
+ workspacePath(value.root, '', false);
16
+ }
17
+ if (permission === 'http')
18
+ abilityAssert(value && pkg.manifest.permissions.networkOrigins.includes(value.origin) && (value.secretSlots === undefined || Array.isArray(value.secretSlots) && value.secretSlots.every((slot) => typeof slot === 'string' && pkg.manifest.permissions.secretSlots.includes(slot))), 'GRANT_INVALID', 'HTTPS origin and secret slots must be declared by the package');
19
+ }
20
+ function workspacePath(root, relative, write) {
21
+ abilityAssert(typeof relative === 'string' && !path.isAbsolute(relative) && !relative.split(/[\\/]/).includes('..'), 'WORKSPACE_PATH_INVALID', 'Expected a workspace-relative path');
22
+ const canonicalRoot = fs.realpathSync(root);
23
+ const file = path.resolve(canonicalRoot, relative);
24
+ abilityAssert(isSameOrDescendant(file, canonicalRoot), 'RESOURCE_DENIED', 'Path is outside workspace', 403);
25
+ let cursor = file;
26
+ while (!fs.existsSync(cursor) && cursor !== canonicalRoot)
27
+ cursor = path.dirname(cursor);
28
+ abilityAssert(isSameOrDescendant(fs.realpathSync(cursor), canonicalRoot), 'RESOURCE_DENIED', 'Workspace path resolves outside its root', 403);
29
+ for (let current = file; isSameOrDescendant(current, canonicalRoot); current = path.dirname(current)) {
30
+ if (fs.existsSync(current))
31
+ abilityAssert(!fs.lstatSync(current).isSymbolicLink(), 'RESOURCE_DENIED', 'Workspace links are not supported', 403);
32
+ if (current === canonicalRoot)
33
+ break;
34
+ }
35
+ abilityAssert(!isHClassPath(file) && !isLClassPath(file) && !isSameOrDescendant(file, resolvePaths().root) && !isSameOrDescendant(file, getPackageRoot()) && !/(?:^|[\\/])(?:\.env(?:\.[^\\/]*)?|\.ssh|\.aws|\.git)(?:[\\/]|$)/i.test(file), 'RESOURCE_DENIED', 'Protected paths cannot be bound as a workspace', 403);
36
+ if (write)
37
+ abilityAssert(fs.existsSync(path.dirname(file)), 'WORKSPACE_PARENT_MISSING', 'Create workspace parent directories outside the plugin');
38
+ return file;
39
+ }
40
+ const privateNetworks = new BlockList();
41
+ for (const [network, prefix] of [['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8], ['169.254.0.0', 16], ['172.16.0.0', 12], ['192.0.0.0', 24], ['192.0.2.0', 24], ['192.88.99.0', 24], ['192.168.0.0', 16], ['198.18.0.0', 15], ['198.51.100.0', 24], ['203.0.113.0', 24], ['224.0.0.0', 4], ['240.0.0.0', 4]])
42
+ privateNetworks.addSubnet(network, prefix, 'ipv4');
43
+ function publicAddress(address) { return isIP(address) === 4 && !privateNetworks.check(address, 'ipv4'); }
44
+ export async function resourceCall(instance, pkg, secrets, refs, method, args, checkLease) {
45
+ if (method.startsWith('workspace.')) {
46
+ const grant = activeGrants(instance, 'workspace')[0]?.value;
47
+ abilityAssert(grant, 'RESOURCE_DENIED', 'Workspace is not granted', 403);
48
+ const write = method === 'workspace.write';
49
+ abilityAssert(!write || grant.mode === 'read-write', 'RESOURCE_DENIED', 'Workspace write is not granted', 403);
50
+ const file = workspacePath(grant.root, args.file ?? '', write);
51
+ checkLease();
52
+ if (method === 'workspace.list')
53
+ return fs.readdirSync(file).slice(0, 256);
54
+ if (method === 'workspace.read') {
55
+ abilityAssert(fs.statSync(file).isFile() && fs.statSync(file).size <= 1024 * 1024, 'RESOURCE_TOO_LARGE', 'Workspace read exceeds 1 MiB');
56
+ return fs.readFileSync(file, 'utf8');
57
+ }
58
+ abilityAssert(write && typeof args.text === 'string' && Buffer.byteLength(args.text) <= 1024 * 1024, 'RESOURCE_DENIED', 'Unsupported workspace operation', 403);
59
+ fs.writeFileSync(file, args.text, { mode: 0o600 });
60
+ return { ok: true };
61
+ }
62
+ abilityAssert(method === 'http.request', 'METHOD_UNSUPPORTED', 'Resource method unavailable');
63
+ const url = new URL(args.url);
64
+ const origin = url.origin;
65
+ abilityAssert(url.protocol === 'https:' && !url.username && !url.password && pkg.manifest.permissions.networkOrigins.includes(origin) && activeGrants(instance, 'http').some(value => value.value?.origin === origin), 'RESOURCE_DENIED', 'HTTPS origin is not granted', 403);
66
+ const resolved = (await lookup(url.hostname, { all: true })).filter(item => publicAddress(item.address));
67
+ abilityAssert(resolved.length > 0, 'RESOURCE_DENIED', 'HTTPS target must resolve to a public IPv4 address', 403);
68
+ const headers = {};
69
+ const requestMethod = args.method ?? 'GET';
70
+ abilityAssert(['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'].includes(requestMethod), 'METHOD_UNSUPPORTED', 'Unsupported HTTPS method');
71
+ if (args.contentType) {
72
+ abilityAssert(['application/json', 'text/plain'].includes(args.contentType), 'HEADER_INVALID', 'Unsupported content type');
73
+ headers['Content-Type'] = args.contentType;
74
+ }
75
+ if (args.secretSlot) {
76
+ abilityAssert(typeof args.secretSlot === 'string' && pkg.manifest.permissions.secretSlots.includes(args.secretSlot) && refs[args.secretSlot] && activeGrants(instance, 'http').some(grant => grant.value?.origin === origin && grant.value?.secretSlots?.includes(args.secretSlot)), 'SECRET_UNAVAILABLE', 'Secret slot is not configured and granted to this origin');
77
+ headers.Authorization = 'Bearer ' + await secrets.get(instance.id, args.secretSlot, refs[args.secretSlot]);
78
+ }
79
+ abilityAssert(args.body === undefined || typeof args.body === 'string' && Buffer.byteLength(args.body) <= 1024 * 1024, 'RESOURCE_TOO_LARGE', 'HTTPS request exceeds 1 MiB');
80
+ checkLease();
81
+ return new Promise((resolve, reject) => {
82
+ const request = https.request(url, { method: requestMethod, headers, agent: false, family: 4, lookup: (_host, _options, callback) => callback(null, resolved[0].address, 4), timeout: 10000 }, response => {
83
+ const chunks = [];
84
+ let size = 0;
85
+ response.on('data', chunk => { size += chunk.length; if (size > 1024 * 1024)
86
+ response.destroy(new Error('Response too large'));
87
+ else
88
+ chunks.push(chunk); });
89
+ response.on('error', () => reject(new AbilityError('HTTP_UNAVAILABLE', 'HTTPS response unavailable', 502)));
90
+ response.on('end', () => {
91
+ try {
92
+ checkLease();
93
+ const text = Buffer.concat(chunks).toString('utf8');
94
+ abilityAssert(!headers.Authorization || !text.includes(headers.Authorization.slice(7)), 'SECRET_RESPONSE_WITHHELD', 'HTTPS response contains secret material', 502);
95
+ resolve({ status: response.statusCode, body: text });
96
+ }
97
+ catch (error) {
98
+ reject(error);
99
+ }
100
+ });
101
+ });
102
+ request.on('timeout', () => request.destroy());
103
+ request.on('error', () => reject(new AbilityError('HTTP_UNAVAILABLE', 'HTTPS request outcome is unknown', 502)));
104
+ request.end(args.body);
105
+ });
106
+ }