@kabmo-labs/kabmo 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +679 -679
- package/dist/client/static/js/{index-ph0q59rs.js → index-jcr5twtp.js} +769 -767
- package/dist/client/static/js/index-z3w7n85q.css +1 -0
- package/package.json +1 -1
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +23 -7
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +27 -11
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/index.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- package/src/client/data/settings/omp-schema.json +4 -4
- package/src/client/hooks/chat/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +17 -0
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -3
- package/src/client/hooks/chat/timeline/send.test-util.ts +1 -1
- package/src/client/hooks/chat/timeline/send.test.ts +1 -3
- package/src/client/hooks/chat/timeline/send.ts +8 -3
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +10 -3
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/tailwind.css +9 -1
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- package/src/server/lib/harness/acp/mapper.ts +6 -4
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-handshake.ts +9 -2
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session.test-util.ts +31 -2
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +20 -20
- package/src/server/lib/harness/acp/turn.ts +31 -7
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +13 -115
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/session/delete-flow.server.ts +15 -8
- package/src/server/lib/omp/session/delete.server.ts +12 -0
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/import-action.ts +18 -4
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update.ts +49 -7
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/harness/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +32 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +9 -0
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-plan.test.ts +51 -1
- package/src/shared/lib/harness/update-plan.ts +47 -7
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +25 -9
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +6 -3
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
|
@@ -15,31 +15,43 @@
|
|
|
15
15
|
|
|
16
16
|
import { useMemo } from 'preact/hooks';
|
|
17
17
|
import type { WorkspaceFolderData } from '@/shared/types';
|
|
18
|
-
import type { SessionDataShape } from '@/client/hooks/chat/timeline/session-
|
|
18
|
+
import type { SessionDataShape } from '@/client/hooks/chat/timeline/session-shapes';
|
|
19
19
|
|
|
20
20
|
export interface RunIdentity {
|
|
21
21
|
sessionProvider?: string;
|
|
22
22
|
sessionModelName?: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export
|
|
25
|
+
export interface RunIdentityInput {
|
|
26
26
|
folders: WorkspaceFolderData[];
|
|
27
27
|
sessionId: string | null;
|
|
28
28
|
sessionData: SessionDataShape | null | undefined;
|
|
29
29
|
modelNames: Record<string, string>;
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function runIdentityFor(input: RunIdentityInput): RunIdentity {
|
|
31
33
|
const { folders, sessionId, sessionData, modelNames } = input;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
34
|
+
const sidebar = folders.flatMap((f) => f.sessions ?? []).find((s) => String(s.id) === String(sessionId)) ?? null;
|
|
35
|
+
const runModel = sidebar?.runModel ?? null;
|
|
36
|
+
// The sidebar's model describes the RUN row beside it. While a run is live it
|
|
37
|
+
// is the freshest identity (it is renamed from `get_state` mid-run), but for
|
|
38
|
+
// an idle chat it is the model of the LAST run — a `set_model` after that run
|
|
39
|
+
// never reached it, so the footer and the composer kept naming the first
|
|
40
|
+
// model the chat ever picked. An idle chat reads the session's own metadata,
|
|
41
|
+
// which `/api/chat/:id` re-reads from the live agent on a `model_changed`.
|
|
42
|
+
const liveRun = sidebar?.streamStatus === 'stream';
|
|
36
43
|
const fallback = sessionData?.model;
|
|
37
44
|
const fallbackModel = typeof fallback === 'object' ? fallback : null;
|
|
38
|
-
const
|
|
45
|
+
const chosen = liveRun ? runModel : (fallbackModel ?? runModel);
|
|
39
46
|
return {
|
|
40
|
-
sessionProvider:
|
|
41
|
-
sessionModelName:
|
|
42
|
-
? (modelNames[
|
|
47
|
+
sessionProvider: chosen?.provider,
|
|
48
|
+
sessionModelName: chosen?.modelId
|
|
49
|
+
? (modelNames[chosen.modelId] ?? chosen.modelId)
|
|
43
50
|
: (typeof fallback === 'string' ? fallback : undefined),
|
|
44
51
|
};
|
|
45
52
|
}
|
|
53
|
+
|
|
54
|
+
export function useRunIdentity(input: RunIdentityInput): RunIdentity {
|
|
55
|
+
const { folders, sessionId, sessionData, modelNames } = input;
|
|
56
|
+
return useMemo(() => runIdentityFor(input), [folders, sessionId, sessionData, modelNames]);
|
|
57
|
+
}
|
|
@@ -161,6 +161,23 @@ describe('executeSend', () => {
|
|
|
161
161
|
expect(h1.deps.pendingHarnessRef.current).toBeNull();
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
+
test('a New Chat harness inherited from the source chat outranks a stale pick', async () => {
|
|
165
|
+
// The dialog has no picker, so its `options.harness` is the only honest
|
|
166
|
+
// answer; a ref left by an earlier pick on the pending view must not win.
|
|
167
|
+
const h1 = makeSendHarness({
|
|
168
|
+
isOmpSession: false,
|
|
169
|
+
sessionId: 'new-1',
|
|
170
|
+
folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
|
|
171
|
+
selectedFolderId: 4,
|
|
172
|
+
agent: { spawnResult: { sessionId: 'uuid-12' } },
|
|
173
|
+
});
|
|
174
|
+
h1.deps.pendingHarnessRef.current = 'opencode';
|
|
175
|
+
await act(async () => {
|
|
176
|
+
await h1.sends.executeSend('first prompt', [], { harness: 'omp-acp' });
|
|
177
|
+
});
|
|
178
|
+
expect(h1.agent.calls.newPrompts[0]?.options).toMatchObject({ harness: 'omp-acp' });
|
|
179
|
+
});
|
|
180
|
+
|
|
164
181
|
test("the spawn's answered harness is what the run is reported as", async () => {
|
|
165
182
|
const h1 = makeSendHarness({
|
|
166
183
|
isOmpSession: false,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import type { Dispatch, SetStateAction } from 'preact/compat';
|
|
16
16
|
import type { Attachment, ChatMessageData, OmpAgentHandle, PromptDispatchResult, QueuedMessageModel } from '@/shared/types';
|
|
17
17
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
18
|
-
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-
|
|
18
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
19
19
|
import type { DeferredModelStore } from '@/client/hooks/chat/timeline/deferred-model';
|
|
20
20
|
import type { ArmedGoal } from '@/shared/lib/omp/mode/actions';
|
|
21
21
|
|
|
@@ -94,10 +94,12 @@ export interface ChatTimelineSendResult {
|
|
|
94
94
|
steerOmpAgent: (text: string, attachments: Attachment[]) => Promise<PromptDispatchResult>;
|
|
95
95
|
/** `model` re-applies a queued item's snapshot before the prompt runs
|
|
96
96
|
* (set_model / set_thinking_level RPC + prompt access mode). `busy: true`
|
|
97
|
-
* means omp REFUSED the prompt mid-turn — the caller queues it instead.
|
|
97
|
+
* means omp REFUSED the prompt mid-turn — the caller queues it instead.
|
|
98
|
+
* `harness` is the New Chat dialog's inherited agent, used only by the
|
|
99
|
+
* brand-new-session branch (`/api/agent/new`). */
|
|
98
100
|
executeSend: (
|
|
99
101
|
text: string,
|
|
100
102
|
attachments: Attachment[],
|
|
101
|
-
options?: { model?: QueuedMessageModel | null },
|
|
103
|
+
options?: { model?: QueuedMessageModel | null; harness?: string | null },
|
|
102
104
|
) => Promise<PromptDispatchResult>;
|
|
103
105
|
}
|
|
@@ -18,9 +18,7 @@ import {
|
|
|
18
18
|
type ChatTimelineSendDeps,
|
|
19
19
|
type ChatTimelineSendResult,
|
|
20
20
|
} from '@/client/hooks/chat/timeline/send';
|
|
21
|
-
import {
|
|
22
|
-
type SessionSeed,
|
|
23
|
-
} from '@/client/hooks/chat/timeline/session-load';
|
|
21
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
24
22
|
|
|
25
23
|
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
26
24
|
/** The runner's own globals, restored on teardown so later files still have them. */
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
type ChatTimelineSendDeps,
|
|
25
25
|
type ChatTimelineSendResult,
|
|
26
26
|
} from '@/client/hooks/chat/timeline/send';
|
|
27
|
-
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-
|
|
27
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
28
28
|
|
|
29
29
|
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
30
30
|
|
|
@@ -19,9 +19,7 @@ import {
|
|
|
19
19
|
type ChatTimelineSendDeps,
|
|
20
20
|
type ChatTimelineSendResult,
|
|
21
21
|
} from '@/client/hooks/chat/timeline/send';
|
|
22
|
-
import {
|
|
23
|
-
type SessionSeed,
|
|
24
|
-
} from '@/client/hooks/chat/timeline/session-load';
|
|
22
|
+
import type { SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
25
23
|
|
|
26
24
|
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
27
25
|
/** The runner's own globals, restored on teardown so later files still have them. */
|
|
@@ -135,7 +135,7 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
135
135
|
const executeSend = useCallback(async (
|
|
136
136
|
text: string,
|
|
137
137
|
attachments: Attachment[],
|
|
138
|
-
options?: { model?: QueuedMessageModel | null },
|
|
138
|
+
options?: { model?: QueuedMessageModel | null; harness?: string | null },
|
|
139
139
|
) => {
|
|
140
140
|
// Last gate before a prompt leaves the client. `handleSend` already refuses
|
|
141
141
|
// these, but `executeSend` is also reached by a retry of a stored turn, a
|
|
@@ -273,8 +273,13 @@ export function useChatTimelineSend(deps: ChatTimelineSendDeps): ChatTimelineSen
|
|
|
273
273
|
accessMode: accessModeRef.current,
|
|
274
274
|
modes: spawnModes,
|
|
275
275
|
// A harness picked on the pending view rides the spawn; cleared on
|
|
276
|
-
// success below so it cannot leak onto the next new chat.
|
|
277
|
-
|
|
276
|
+
// success below so it cannot leak onto the next new chat. A New
|
|
277
|
+
// Chat opened from an ACP answer passes the SOURCE chat's harness
|
|
278
|
+
// explicitly (that dialog has no picker), and it must outrank the
|
|
279
|
+
// ref a previous pick left behind.
|
|
280
|
+
...((options?.harness ?? pendingHarnessRef.current)
|
|
281
|
+
? { harness: options?.harness ?? pendingHarnessRef.current }
|
|
282
|
+
: {}),
|
|
278
283
|
},
|
|
279
284
|
armed ? (id) => startArmedGoal(id, armed, promptText) : undefined,
|
|
280
285
|
);
|
|
@@ -168,11 +168,15 @@ export async function mount(sessionId: string, api: ProbeApi): Promise<void> {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
/** Land the registered fetch, as the server's response would. */
|
|
171
|
-
export async function resolveLoad(
|
|
171
|
+
export async function resolveLoad(
|
|
172
|
+
messages: unknown[],
|
|
173
|
+
index = 0,
|
|
174
|
+
sessionExtra: Record<string, unknown> = {},
|
|
175
|
+
): Promise<void> {
|
|
172
176
|
const gate = gates[index];
|
|
173
177
|
if (!gate) throw new Error('no session fetch was registered');
|
|
174
178
|
await act(async () => {
|
|
175
|
-
gate.resolve({ session: { id: 'sess-1', messages }, hasMore: false, oldestIndex: 0 });
|
|
179
|
+
gate.resolve({ session: { id: 'sess-1', messages, ...sessionExtra }, hasMore: false, oldestIndex: 0 });
|
|
176
180
|
});
|
|
177
181
|
for (let i = 0; i < 3; i += 1) await act(async () => {});
|
|
178
182
|
}
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
|
|
30
30
|
import { describe, expect, test } from 'bun:test';
|
|
31
31
|
import { act } from 'preact/test-utils';
|
|
32
|
+
import { h, render } from 'preact';
|
|
33
|
+
import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
|
|
34
|
+
import { useHarnesses } from '@/client/hooks/models/use-harnesses';
|
|
32
35
|
import {
|
|
33
36
|
AI_PLACEHOLDER,
|
|
34
37
|
ECHOED_TURN,
|
|
@@ -219,4 +222,32 @@ describe('a committed fetch with no local run', () => {
|
|
|
219
222
|
expect(ids(api)).toEqual([]);
|
|
220
223
|
expect(api.generatingCalls.length).toBe(before);
|
|
221
224
|
});
|
|
225
|
+
|
|
226
|
+
test('publishes the live chat\'s selector lists to its harness', async () => {
|
|
227
|
+
stubChatFetch();
|
|
228
|
+
resetHarnessesStore();
|
|
229
|
+
const live = { models: [{ value: 'gpt-5-codex', name: 'GPT-5 Codex' }], thinking: [{ value: 'high', name: 'High' }] };
|
|
230
|
+
const seen: Record<string, unknown> = {};
|
|
231
|
+
const api = makeApi();
|
|
232
|
+
// The loader's session fetch is `gates[0]`; the store read below issues the
|
|
233
|
+
// harness-catalog read, so it must mount after the probe.
|
|
234
|
+
await mount('sess-1', api);
|
|
235
|
+
const box = document.body.appendChild(document.createElement('div'));
|
|
236
|
+
await act(async () => { render(h(LiveModelsRead, { sink: seen }), box); });
|
|
237
|
+
|
|
238
|
+
await resolveLoad([ECHOED_TURN], 0, { harness: 'codex', liveModels: live });
|
|
239
|
+
|
|
240
|
+
// The picker for that harness lists what the running chat reported, not what
|
|
241
|
+
// the throwaway probe guessed.
|
|
242
|
+
expect(seen.liveModels).toEqual({ codex: live });
|
|
243
|
+
await act(async () => { render(null, box); });
|
|
244
|
+
box.remove();
|
|
245
|
+
});
|
|
222
246
|
});
|
|
247
|
+
|
|
248
|
+
/** Read the harness store the way a model picker does. */
|
|
249
|
+
function LiveModelsRead({ sink }: { sink: Record<string, unknown> }) {
|
|
250
|
+
const { liveModels } = useHarnesses();
|
|
251
|
+
sink.liveModels = liveModels;
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
@@ -21,25 +21,13 @@ import type { Dispatch, RefObject, SetStateAction } from 'preact/compat';
|
|
|
21
21
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
22
22
|
|
|
23
23
|
import type { ChatMessageData } from '@/shared/types';
|
|
24
|
+
import type { SessionDataShape, SessionSeed } from '@/client/hooks/chat/timeline/session-shapes';
|
|
25
|
+
import { publishLiveModels } from '@/client/hooks/models/use-harnesses';
|
|
24
26
|
import { SESSION_META_RETRY_SCHEDULE_MS } from '@/shared/lib/workspace/refresh-cadence';
|
|
25
27
|
import { useSessionPagination } from '@/client/hooks/chat/timeline/session-pagination';
|
|
26
28
|
import { useLostRunRecovery } from '@/client/hooks/chat/timeline/lost-run';
|
|
27
29
|
import { isOwnSpawn, isSpawnArrival } from '@/client/hooks/chat/timeline/session-switch';
|
|
28
30
|
|
|
29
|
-
export interface SessionDataShape {
|
|
30
|
-
id?: string;
|
|
31
|
-
title?: string;
|
|
32
|
-
model?: string | { provider: string; modelId: string };
|
|
33
|
-
thinkingLevel?: string;
|
|
34
|
-
messages?: any[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Session identity a spawn established before omp's JSONL is readable. */
|
|
38
|
-
export interface SessionSeed {
|
|
39
|
-
model?: { provider: string; modelId: string } | null;
|
|
40
|
-
thinkingLevel?: string | null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
31
|
export interface UseSessionLoadDeps {
|
|
44
32
|
sessionId: string | null;
|
|
45
33
|
setLocalMessages: Dispatch<SetStateAction<ChatMessageData[]>>;
|
|
@@ -106,6 +94,10 @@ export function useSessionLoad(deps: UseSessionLoadDeps) {
|
|
|
106
94
|
|
|
107
95
|
const applySessionData = useCallback((incoming: SessionDataShape) => {
|
|
108
96
|
if (incoming.model && typeof incoming.model === 'object') seededModelRef.current = incoming.model;
|
|
97
|
+
// The live chat's own selector lists are what the picker must list for this
|
|
98
|
+
// harness from now on: a probe is one throwaway spawn, and a chat already
|
|
99
|
+
// running can contradict it (codex refuses the probe while offering models).
|
|
100
|
+
if (incoming.harness && incoming.liveModels) publishLiveModels(incoming.harness, incoming.liveModels);
|
|
109
101
|
const model = incoming.model ?? (isGeneratingRef.current ? seededModelRef.current ?? undefined : undefined);
|
|
110
102
|
const thinkingLevel = incoming.thinkingLevel ?? seededThinkingLevelRef.current ?? undefined;
|
|
111
103
|
setSessionData({ ...incoming, model, thinkingLevel });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The payload `/api/chat/:id` answers with, and the identity a spawn established
|
|
8
|
+
* before that payload can be trusted.
|
|
9
|
+
*
|
|
10
|
+
* Types only, in their own module: `session-load.ts` owns the fetching and the
|
|
11
|
+
* seeding rules and sits against the per-file size ceiling.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { LiveHarnessModels } from '@/shared/types/harness';
|
|
15
|
+
|
|
16
|
+
export interface SessionDataShape {
|
|
17
|
+
id?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
model?: string | { provider: string; modelId: string };
|
|
20
|
+
thinkingLevel?: string;
|
|
21
|
+
messages?: any[];
|
|
22
|
+
/** Harness the live session runs, with the model/thinking selectors it
|
|
23
|
+
* published. Only a live non-omp session reports them. */
|
|
24
|
+
harness?: string;
|
|
25
|
+
liveModels?: LiveHarnessModels;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Session identity a spawn established before omp's JSONL is readable. */
|
|
29
|
+
export interface SessionSeed {
|
|
30
|
+
model?: { provider: string; modelId: string } | null;
|
|
31
|
+
thinkingLevel?: string | null;
|
|
32
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The harness catalog's module-level store and its one read.
|
|
8
|
+
*
|
|
9
|
+
* Split from `use-harnesses.ts` so the hook holds the controller and this file
|
|
10
|
+
* holds the state, the shared in-flight read and the invalidation generation.
|
|
11
|
+
* Two mounted surfaces — the composer's tab strip and Settings → Harnesses — read
|
|
12
|
+
* `/api/harness` at once, and probes used to live in whichever instance ran them;
|
|
13
|
+
* one store is what makes a probe visible everywhere without a reload.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
HarnessConfig, HarnessProviderSupport, HarnessesPayload, HarnessSummary, LiveHarnessModels,
|
|
18
|
+
} from '@/shared/types/harness';
|
|
19
|
+
|
|
20
|
+
export interface HarnessStore {
|
|
21
|
+
harnesses: HarnessSummary[];
|
|
22
|
+
configs: Record<string, HarnessConfig>;
|
|
23
|
+
providerSupport: Record<string, HarnessProviderSupport>;
|
|
24
|
+
liveModels: Record<string, LiveHarnessModels>;
|
|
25
|
+
isLoading: boolean;
|
|
26
|
+
error: string | null;
|
|
27
|
+
/** Bumped on every change, so `useSyncExternalStore`-style subscribers can
|
|
28
|
+
* detect it without holding the arrays themselves. */
|
|
29
|
+
version: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const store: HarnessStore = {
|
|
33
|
+
harnesses: [], configs: {}, providerSupport: {}, liveModels: {}, isLoading: true, error: null, version: 0,
|
|
34
|
+
};
|
|
35
|
+
/** Has the catalog been read at least once? A later mount must NOT re-fetch: the
|
|
36
|
+
* answer is a property of the installed agents, and `reload()` is the explicit
|
|
37
|
+
* way to re-read it. */
|
|
38
|
+
let loaded = false;
|
|
39
|
+
export const listeners = new Set<() => void>();
|
|
40
|
+
/** One in-flight catalog read shared by every mount; a second mount joins it
|
|
41
|
+
* rather than firing its own `GET /api/harness`. */
|
|
42
|
+
let inflight: Promise<void> | null = null;
|
|
43
|
+
/**
|
|
44
|
+
* Bumped by every invalidation. A read that was ALREADY IN FLIGHT when one
|
|
45
|
+
* landed answers from the state before the write (the `models` frame routinely
|
|
46
|
+
* arrives during the mount's own read), so joining it would leave the picker on
|
|
47
|
+
* the old catalog until the next explicit reload. The read re-runs instead.
|
|
48
|
+
*/
|
|
49
|
+
let generation = 0;
|
|
50
|
+
|
|
51
|
+
export function emit(patch: Partial<HarnessStore>): void {
|
|
52
|
+
Object.assign(store, patch);
|
|
53
|
+
store.version += 1;
|
|
54
|
+
for (const listener of listeners) listener();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Drop the cached answer and read again, even if a read is still in flight. */
|
|
58
|
+
export function invalidateCatalog(): Promise<void> {
|
|
59
|
+
loaded = false;
|
|
60
|
+
generation += 1;
|
|
61
|
+
return loadCatalog();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function loadCatalog(): Promise<void> {
|
|
65
|
+
if (inflight) return inflight;
|
|
66
|
+
if (loaded) return;
|
|
67
|
+
const stamp = generation;
|
|
68
|
+
emit({ isLoading: true });
|
|
69
|
+
inflight = fetch('/api/harness')
|
|
70
|
+
.then(async (response) => {
|
|
71
|
+
if (!response.ok) throw new Error(`GET /api/harness answered ${response.status}`);
|
|
72
|
+
return (await response.json()) as HarnessesPayload;
|
|
73
|
+
})
|
|
74
|
+
.then((payload) => {
|
|
75
|
+
loaded = true;
|
|
76
|
+
emit({
|
|
77
|
+
harnesses: Array.isArray(payload.harnesses) ? payload.harnesses : [],
|
|
78
|
+
// Absent from an answer written before per-harness config existed: an
|
|
79
|
+
// empty map is the honest reading, and every card then shows "not set".
|
|
80
|
+
configs: payload.configs ?? {},
|
|
81
|
+
providerSupport: payload.providerSupport ?? {},
|
|
82
|
+
error: null,
|
|
83
|
+
isLoading: false,
|
|
84
|
+
});
|
|
85
|
+
})
|
|
86
|
+
.catch((cause: unknown) => {
|
|
87
|
+
emit({
|
|
88
|
+
error: cause instanceof Error ? cause.message : 'Could not read the harness list',
|
|
89
|
+
isLoading: false,
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
.finally(() => {
|
|
93
|
+
inflight = null;
|
|
94
|
+
// A write landed while this read was in flight: the answer just stored
|
|
95
|
+
// describes the pre-write state, so read once more rather than keep it.
|
|
96
|
+
if (stamp !== generation) void invalidateCatalog();
|
|
97
|
+
});
|
|
98
|
+
return inflight;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Forget everything this process learned about the harnesses.
|
|
102
|
+
*
|
|
103
|
+
* Two callers, one meaning: a test file starts from a cold store, and
|
|
104
|
+
* `bun --hot` re-evaluates this module while the old store may still describe
|
|
105
|
+
* agents that have since been installed or removed.
|
|
106
|
+
*/
|
|
107
|
+
export function resetHarnessesStore(): void {
|
|
108
|
+
inflight = null;
|
|
109
|
+
loaded = false;
|
|
110
|
+
Object.assign(store, {
|
|
111
|
+
harnesses: [], configs: {}, providerSupport: {}, liveModels: {}, isLoading: true, error: null, version: 0,
|
|
112
|
+
});
|
|
113
|
+
for (const listener of listeners) listener();
|
|
114
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A landed provider write must hand the browser the two facts the card cannot
|
|
8
|
+
* derive itself: the config the server saved and the harness tabs whose cached
|
|
9
|
+
* probe measured the OLD registry. Dropping `probeInvalidated` left the composer
|
|
10
|
+
* picker on a stale model list, because nothing told that tab to probe again.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
14
|
+
|
|
15
|
+
import { addProvider, importProvider } from '@/client/hooks/models/provider-writes';
|
|
16
|
+
|
|
17
|
+
const realFetch = Bun.fetch;
|
|
18
|
+
let bodies: unknown[] = [];
|
|
19
|
+
let announceCalls: unknown[][] = [];
|
|
20
|
+
|
|
21
|
+
function stubFetch(payload: unknown, status = 200): void {
|
|
22
|
+
(globalThis as unknown as Record<string, unknown>).fetch = async (_input: unknown, init?: { body?: string }) => {
|
|
23
|
+
bodies.push(init?.body ? JSON.parse(init.body) : null);
|
|
24
|
+
return new Response(JSON.stringify(payload), {
|
|
25
|
+
status,
|
|
26
|
+
headers: { 'content-type': 'application/json' },
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
bodies = [];
|
|
33
|
+
announceCalls = [];
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
(globalThis as unknown as Record<string, unknown>).fetch = realFetch;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function announce(id: string, config?: unknown, invalidated?: unknown): void {
|
|
41
|
+
announceCalls.push([id, config, invalidated]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('provider writes', () => {
|
|
45
|
+
test('an add announces the saved config and the probes it invalidated', async () => {
|
|
46
|
+
const config = { path: '/home/me/.claude.json' };
|
|
47
|
+
stubFetch({ config, probeInvalidated: ['omp-acp'], protocol: 'anthropic', target: 'anthropic' });
|
|
48
|
+
|
|
49
|
+
const outcome = await addProvider('omp-acp', { target: 'registry', id: 'minimax' } as never, announce);
|
|
50
|
+
|
|
51
|
+
expect(outcome.problem).toBeNull();
|
|
52
|
+
expect(outcome.detail).toBe('anthropic → anthropic');
|
|
53
|
+
expect(announceCalls).toEqual([['omp-acp', config, ['omp-acp']]]);
|
|
54
|
+
expect(bodies).toEqual([{ probe: 'omp-acp', addProvider: { target: 'registry', id: 'minimax' } }]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('an import carries the row, not the credential', async () => {
|
|
58
|
+
stubFetch({ imported: { id: 'minimax', replaced: false, path: '/w/models.yml', dialect: 'omp', notes: [] } });
|
|
59
|
+
|
|
60
|
+
const outcome = await importProvider(
|
|
61
|
+
'omp-acp',
|
|
62
|
+
'minimax',
|
|
63
|
+
{ source: 'claude', name: 'MiniMax', baseUrl: 'https://api.minimax.io', protocol: 'anthropic', models: ['m1'], contextWindow: 200_000 } as never,
|
|
64
|
+
announce,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(outcome.problem).toBeNull();
|
|
68
|
+
const body = bodies[0] as { importProvider: { entry: Record<string, unknown> } };
|
|
69
|
+
expect(body.importProvider.entry).not.toHaveProperty('apiKey');
|
|
70
|
+
expect(body.importProvider.entry.models).toEqual(['m1']);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('a refused write reports the server reason and announces nothing', async () => {
|
|
74
|
+
stubFetch({ error: 'that harness has no launch command' }, 400);
|
|
75
|
+
|
|
76
|
+
const outcome = await addProvider('omp-acp', { target: 'registry' } as never, announce);
|
|
77
|
+
|
|
78
|
+
expect(outcome.problem).toBe('that harness has no launch command');
|
|
79
|
+
expect(announceCalls).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -34,14 +34,21 @@ interface ProviderWritePayload {
|
|
|
34
34
|
target?: string;
|
|
35
35
|
protocol?: string;
|
|
36
36
|
probe?: { protocols: string[]; error?: string };
|
|
37
|
+
/** Harness tabs whose cached probe no longer describes the registry. */
|
|
38
|
+
probeInvalidated?: string[];
|
|
37
39
|
error?: string;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
* What `announce` does with a landed write: save the config the server answered
|
|
42
|
-
* with, when there is one, and re-
|
|
44
|
+
* with, when there is one, re-read the catalog, and re-probe the harness tabs
|
|
45
|
+
* whose cached answer the write invalidated.
|
|
43
46
|
*/
|
|
44
|
-
export type ProviderWriteAnnouncer = (
|
|
47
|
+
export type ProviderWriteAnnouncer = (
|
|
48
|
+
id: string,
|
|
49
|
+
config?: HarnessConfig,
|
|
50
|
+
probeInvalidated?: readonly string[],
|
|
51
|
+
) => void;
|
|
45
52
|
|
|
46
53
|
/**
|
|
47
54
|
* Turn one provider-write answer into what the card repeats.
|
|
@@ -63,7 +70,7 @@ function outcomeOf(
|
|
|
63
70
|
}
|
|
64
71
|
// An env-style target answered with a CONFIG; a registry target with what it
|
|
65
72
|
// wrote. Both change what the card shows, so both are folded back in.
|
|
66
|
-
announce(id, payload.config);
|
|
73
|
+
announce(id, payload.config, payload.probeInvalidated);
|
|
67
74
|
const imported = payload.imported;
|
|
68
75
|
const parts = [
|
|
69
76
|
payload.protocol ? `${payload.protocol} → ${payload.target ?? imported?.path ?? 'the agent'}` : null,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `useHarnesses()` contract, named where a consumer can import it.
|
|
8
|
+
*
|
|
9
|
+
* The store's implementation file is at the 350-line ceiling; the type earns its
|
|
10
|
+
* own module and keeps every consumer off `ReturnType<typeof useHarnesses>`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
HarnessConfig, HarnessImportOutcome, HarnessProviderSupport, HarnessSummary, LiveHarnessModels,
|
|
15
|
+
} from '@/shared/types/harness';
|
|
16
|
+
import type { AddProviderInput } from '@/client/components/settings/categories/harness-settings/AddProviderForm';
|
|
17
|
+
|
|
18
|
+
export interface HarnessesController {
|
|
19
|
+
harnesses: HarnessSummary[];
|
|
20
|
+
/** Per-harness config, keyed by id. Empty until the catalog is read. */
|
|
21
|
+
configs: Record<string, HarnessConfig>;
|
|
22
|
+
/** Persist one harness's config; resolves to the server's refusal, or null. */
|
|
23
|
+
saveConfig: (id: string, config: HarnessConfig) => Promise<string | null>;
|
|
24
|
+
/** What each harness can do about other providers, keyed by id. */
|
|
25
|
+
providerSupport: Record<string, HarnessProviderSupport>;
|
|
26
|
+
/**
|
|
27
|
+
* The model/thinking selectors a harness's LIVE chat published, keyed by id.
|
|
28
|
+
*
|
|
29
|
+
* A probe is one throwaway spawn, and it can be refused (`codex` answers
|
|
30
|
+
* "Authentication required" to the probe while the chat the user is running
|
|
31
|
+
* lists its models) or aged. The open session's own selectors are the truth
|
|
32
|
+
* for that harness, so the picker reads them first; absent means "only the
|
|
33
|
+
* probe has spoken".
|
|
34
|
+
*/
|
|
35
|
+
liveModels: Record<string, LiveHarnessModels>;
|
|
36
|
+
/** Copy one provider from a source registry into a harness.
|
|
37
|
+
*
|
|
38
|
+
* The ROW travels with the id: the writer needs the endpoint, dialect and
|
|
39
|
+
* model list, and the server would otherwise have to look them up again. The
|
|
40
|
+
* credential is not in the row — the server reads that from the source file. */
|
|
41
|
+
importProvider: (
|
|
42
|
+
id: string,
|
|
43
|
+
sourceId: string,
|
|
44
|
+
entry: HarnessProviderSupport['importable'][number],
|
|
45
|
+
) => Promise<HarnessImportOutcome>;
|
|
46
|
+
/** Add a provider by typing its endpoint and key. */
|
|
47
|
+
addProvider: (id: string, input: AddProviderInput) => Promise<HarnessImportOutcome>;
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
error: string | null;
|
|
50
|
+
/** Re-read the catalog. */
|
|
51
|
+
reload: () => void;
|
|
52
|
+
/** Probe one harness (spawns that agent once) and merge the answer in. */
|
|
53
|
+
probe: (id: string, cwd?: string) => Promise<string | null>;
|
|
54
|
+
/** Switch one harness on or off. Switching ON also probes it once, server-side,
|
|
55
|
+
* so its models are ready for the composer. Resolves to the refusal, or null. */
|
|
56
|
+
setEnabled: (id: string, enabled: boolean) => Promise<string | null>;
|
|
57
|
+
}
|