@volter/supercode-orchestrator 0.4.7 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapters/rh2.mjs +9 -2
- package/bin/orchestrator.mjs +2 -2
- package/index.d.ts +2 -0
- package/index.mjs +1 -1
- package/orchestration.mjs +11 -0
- package/package.json +1 -1
package/adapters/rh2.mjs
CHANGED
|
@@ -45,11 +45,12 @@ const CLOCK_SKEW_MS = 60_000;
|
|
|
45
45
|
const ECHO_MEMORY = 500;
|
|
46
46
|
|
|
47
47
|
export class Rh2Adapter {
|
|
48
|
-
constructor({ platform = 'rh2', profile = 'default', channel = null, vault = new Map(), log = () => {}, fetchImpl = globalThis.fetch, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
48
|
+
constructor({ platform = 'rh2', profile = 'default', channel = null, vault = new Map(), refreshVault = () => false, log = () => {}, fetchImpl = globalThis.fetch, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
49
49
|
this.platform = platform;
|
|
50
50
|
this.profile = profile;
|
|
51
51
|
this.channel = channel;
|
|
52
52
|
this.vault = vault;
|
|
53
|
+
this.refreshVault = refreshVault;
|
|
53
54
|
this.log = log;
|
|
54
55
|
this.fetch = fetchImpl;
|
|
55
56
|
this.sleep = sleep;
|
|
@@ -110,7 +111,13 @@ export class Rh2Adapter {
|
|
|
110
111
|
async get(path, params = {}) {
|
|
111
112
|
const url = new URL(`${this.apiUrl()}/api/v3${path}`);
|
|
112
113
|
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, String(v));
|
|
113
|
-
|
|
114
|
+
let res = await this.fetch(url, { headers: this.headers() });
|
|
115
|
+
// A refused credential may have been replaced in the home's `.env` since it was read: read it again and, when
|
|
116
|
+
// it changed, retry with it, so replacing the bot's session never needs a restart.
|
|
117
|
+
if (res.status === 401 && this.refreshVault()) {
|
|
118
|
+
this.log('info', `${this.platform}: credential refused; retrying with the one now in the home's .env`);
|
|
119
|
+
res = await this.fetch(url, { headers: this.headers() });
|
|
120
|
+
}
|
|
114
121
|
if (!res.ok) {
|
|
115
122
|
const error = new Error(`GET ${path} -> HTTP ${res.status}: ${(await res.text()).slice(0, 200)}`);
|
|
116
123
|
error.status = res.status;
|
package/bin/orchestrator.mjs
CHANGED
|
@@ -61,7 +61,7 @@ import { adoptHome } from '../hermes-home.mjs';
|
|
|
61
61
|
import { hermesAccess } from '../hermes-cli.mjs';
|
|
62
62
|
|
|
63
63
|
import {
|
|
64
|
-
load, save, step, importFrom, exportTo, closeWorld, Orchestrator, LoopbackAdapter,
|
|
64
|
+
load, save, refreshVault, step, importFrom, exportTo, closeWorld, Orchestrator, LoopbackAdapter,
|
|
65
65
|
ChatSdkAdapter, ApiServerAdapter, Rh2Adapter,
|
|
66
66
|
TICK_MS, accessPolicy, applyOperator, performRemoveProfileDir, OPERATOR_OPS,
|
|
67
67
|
} from '../index.mjs';
|
|
@@ -80,7 +80,7 @@ const ADAPTERS = {
|
|
|
80
80
|
loopback: (platform, profile) => new LoopbackAdapter({ platform, profile }),
|
|
81
81
|
'chat-sdk': (platform, profile, ctx) => new ChatSdkAdapter({ platform, profile, profileDir: ctx.state.profiles[profile]?.dir ?? null, channel: ctx.channel, vault: ctx.vault, log: ctx.log }),
|
|
82
82
|
api_server: (platform, profile, ctx) => new ApiServerAdapter({ platform, profile, channel: ctx.channel, vault: ctx.vault, state: ctx.state, log: ctx.log }),
|
|
83
|
-
rh2: (platform, profile, ctx) => new Rh2Adapter({ platform, profile, channel: ctx.channel, vault: ctx.vault, log: ctx.log }),
|
|
83
|
+
rh2: (platform, profile, ctx) => new Rh2Adapter({ platform, profile, channel: ctx.channel, vault: ctx.vault, refreshVault: () => refreshVault(ctx.state, ctx.vault), log: ctx.log }),
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
/// The selector a `platforms:` block resolves through: its `extra.adapter`
|
package/index.d.ts
CHANGED
|
@@ -440,6 +440,8 @@ export function emptyRuntime(): RuntimeState;
|
|
|
440
440
|
export function canonicalJson(value: unknown): string;
|
|
441
441
|
export function persistedView(state: OrchestratorState): Omit<OrchestratorState, 'runtime'>;
|
|
442
442
|
export function parseDotenv(text: string): Map<string, string>;
|
|
443
|
+
/** Read every profile's `.env` into `vault` again, in place; true when a value changed. */
|
|
444
|
+
export function refreshVault(state: { profiles: Record<string, { dir: string }> }, vault: Map<string, string>): boolean;
|
|
443
445
|
|
|
444
446
|
export const CHAT_TYPES: Set<ChatType>;
|
|
445
447
|
export const END_REASONS: Set<EndReason>;
|
package/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ export {
|
|
|
3
3
|
renderSurfaceKey, parseSurfaceKey, surfaceKeyString, parseTarget, renderTarget, resolveRoute, routeSpecificity,
|
|
4
4
|
emptyState, emptyProfile, emptyRuntime, canonicalJson, persistedView, decodeContextFrom,
|
|
5
5
|
} from './ir.mjs';
|
|
6
|
-
export { load, save, compile, importFrom, exportTo, closeWorld, retainWorld, releaseWorld, stateOf, parseDotenv, supercodeCommand } from './orchestration.mjs';
|
|
6
|
+
export { load, save, compile, importFrom, exportTo, closeWorld, retainWorld, releaseWorld, stateOf, parseDotenv, supercodeCommand, refreshVault } from './orchestration.mjs';
|
|
7
7
|
export { step, expired, leaseId, accessPolicy, dmBehavior } from './reducer.mjs';
|
|
8
8
|
export * as events from './events.mjs';
|
|
9
9
|
export { parseCommand, frame, COMMANDS, REPLY } from './commands.mjs';
|
package/orchestration.mjs
CHANGED
|
@@ -116,6 +116,17 @@ function readVault(orchestration) {
|
|
|
116
116
|
return vault;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Read every profile's `.env` into `vault` again, in place, so each reader holding it (a channel adapter) sees a
|
|
121
|
+
* credential replaced there without a restart. True when a value changed.
|
|
122
|
+
*/
|
|
123
|
+
export function refreshVault(state, vault) {
|
|
124
|
+
const fresh = readVault(state);
|
|
125
|
+
let changed = false;
|
|
126
|
+
for (const [k, v] of fresh) if (vault.get(k) !== v) { vault.set(k, v); changed = true; }
|
|
127
|
+
return changed;
|
|
128
|
+
}
|
|
129
|
+
|
|
119
130
|
/** An orchestration value as the loop's state: the persisted half plus an empty runtime half. */
|
|
120
131
|
export function stateOf(orchestration) {
|
|
121
132
|
return { ...orchestration, runtime: emptyRuntime() };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/supercode-orchestrator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The orchestrator runtime over the Volter Harness ontology: one typed operational model whose folder is its serialization, read and written through the harness orchestration doors (docs/ORCHESTRATOR-IR.md)",
|
|
6
6
|
"exports": {
|