maka-agent 0.2.0-dev.43.20260919 → 0.2.0-dev.45.20260921

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 (89) hide show
  1. package/LICENSE +12 -6
  2. package/dist/mcp-capability-provider.js +7 -0
  3. package/dist/runtime-host-service-manager.js +1 -6
  4. package/dist/runtime-host-tui-command.js +1 -1
  5. package/dist/runtime-host-update-command.js +39 -27
  6. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  7. package/node_modules/@maka/core/dist/artifacts.js +1 -0
  8. package/node_modules/@maka/core/dist/chat-model-choice.js +3 -0
  9. package/node_modules/@maka/core/dist/llm-connections.js +3 -21
  10. package/node_modules/@maka/core/dist/model-catalog.js +8 -20
  11. package/node_modules/@maka/core/dist/model-metadata.generated.js +304 -304
  12. package/node_modules/@maka/core/dist/model-metadata.js +1 -2
  13. package/node_modules/@maka/core/dist/model-thinking.js +16 -1
  14. package/node_modules/@maka/core/dist/models-dev-projection.js +0 -1
  15. package/node_modules/@maka/core/dist/provider-auth.js +1 -7
  16. package/node_modules/@maka/core/dist/provider-registry.js +20 -58
  17. package/node_modules/@maka/core/dist/recall.js +5 -1
  18. package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +7 -0
  19. package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +14 -1
  20. package/node_modules/@maka/core/dist/session-start-mode.js +2 -5
  21. package/node_modules/@maka/core/dist/session.js +0 -1
  22. package/node_modules/@maka/core/dist/settings.js +19 -3
  23. package/node_modules/@maka/core/dist/tool-quiet-preview.js +2 -16
  24. package/node_modules/@maka/core/dist/transcript-search.js +46 -0
  25. package/node_modules/@maka/core/package.json +1 -4
  26. package/node_modules/@maka/mcp/dist/index.js +22 -0
  27. package/node_modules/@maka/mcp/dist/oauth.js +4 -2
  28. package/node_modules/@maka/mcp/dist/tool-progress.js +45 -0
  29. package/node_modules/@maka/runtime/dist/model-factory.js +0 -16
  30. package/node_modules/@maka/runtime/dist/model-fetcher.js +1 -4
  31. package/node_modules/@maka/runtime/dist/model-runtime.js +0 -8
  32. package/node_modules/@maka/runtime/dist/opencode-session-header.js +2 -3
  33. package/node_modules/@maka/runtime/dist/recall-tools.js +4 -0
  34. package/node_modules/@maka/runtime/dist/session-manager.js +5 -57
  35. package/node_modules/@maka/runtime/dist/subagent-tools.js +69 -11
  36. package/node_modules/@maka/runtime/dist/test-connection.js +4 -114
  37. package/node_modules/@maka/runtime/package.json +0 -1
  38. package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +44 -9
  39. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +25 -18
  40. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +3 -1
  41. package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
  42. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +33 -3
  43. package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +0 -108
  44. package/node_modules/@maka/runtime-host/dist/protocol/index.js +12 -1
  45. package/node_modules/@maka/runtime-host/dist/protocol/message.js +10 -0
  46. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +4 -6
  47. package/node_modules/@maka/runtime-host/dist/protocol/recall.js +270 -0
  48. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
  49. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -7
  50. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +0 -33
  51. package/node_modules/@maka/runtime-host/dist/protocol/usage-screen.js +12 -4
  52. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +6 -0
  53. package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +31 -104
  54. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +1 -57
  55. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +11 -35
  56. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +3 -20
  57. package/node_modules/@maka/runtime-host/dist/server/interactive-turn-coordinator.js +1 -16
  58. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +46 -28
  59. package/node_modules/@maka/runtime-host/dist/server/recall-coordinator.js +117 -0
  60. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +5 -16
  61. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +21 -12
  62. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +0 -4
  63. package/node_modules/@maka/runtime-host/dist/server/session-turn-access-request-coordinator.js +7 -17
  64. package/node_modules/@maka/storage/dist/artifact-metadata-codec.js +4 -3
  65. package/node_modules/@maka/storage/dist/artifact-store.js +1 -11
  66. package/node_modules/@maka/storage/dist/process-lifetime-file-update-lock.js +0 -41
  67. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +0 -62
  68. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +0 -31
  69. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +0 -3
  70. package/node_modules/@maka/storage/dist/sqlite-usage-schema.js +29 -5
  71. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +2 -0
  72. package/node_modules/@maka/storage/dist/storage-writer-composition.js +0 -3
  73. package/node_modules/@maka/storage/dist/telemetry-file-schema.js +5 -3
  74. package/node_modules/@maka/storage/dist/usage-screen.js +5 -6
  75. package/node_modules/@maka/storage/dist/usage-stores.js +14 -4
  76. package/node_modules/@maka/storage/package.json +0 -2
  77. package/package.json +1 -1
  78. package/node_modules/@maka/core/dist/connection-usage.js +0 -27
  79. package/node_modules/@maka/core/dist/deep-research-client-progress.js +0 -132
  80. package/node_modules/@maka/core/dist/deep-research-run.js +0 -625
  81. package/node_modules/@maka/core/dist/deep-research.js +0 -208
  82. package/node_modules/@maka/core/dist/thread-search.js +0 -498
  83. package/node_modules/@maka/runtime/dist/commandcode-cli-language-model.js +0 -837
  84. package/node_modules/@maka/runtime/dist/connection-usage.js +0 -232
  85. package/node_modules/@maka/runtime/dist/deep-research-tools.js +0 -732
  86. package/node_modules/@maka/runtime-host/dist/protocol/deep-research.js +0 -233
  87. package/node_modules/@maka/runtime-host/dist/server/deep-research-coordinator.js +0 -116
  88. package/node_modules/@maka/storage/dist/deep-research-authority.js +0 -129
  89. package/node_modules/@maka/storage/dist/deep-research-store.js +0 -343
@@ -1,233 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
- import { DEEP_RESEARCH_CHECKLIST_ITEMS_MAX, DEEP_RESEARCH_CLIENT_IMPLEMENTATION_PROMPT_MAX_BYTES, DEEP_RESEARCH_CLIENT_OBJECTIVE_MAX_BYTES, DEEP_RESEARCH_CLIENT_RECENT_ITEMS_MAX, DEEP_RESEARCH_CLIENT_TEXT_MAX_BYTES, DEEP_RESEARCH_INSPECTED_REF_KINDS, DEEP_RESEARCH_REPORT_SECTION_KEYS, DEEP_RESEARCH_REPORT_SECTION_STATUSES, DEEP_RESEARCH_RUN_STATUSES, DEEP_RESEARCH_SCOPE_LEVELS, DEEP_RESEARCH_STAGES, DEEP_RESEARCH_CHECKLIST_STATUSES, } from '@maka/core/deep-research-run';
20
- import { requireCount, requireEncodedByteLimit, requireEntityId, requireExactRecord, requireShapedRecord, requireUtf8String, } from './codec.js';
21
- import { invalidProtocolFrame } from './errors.js';
22
- import { defineOperation } from './operation-spec.js';
23
- export const DEEP_RESEARCH_RESULT_MAX_BYTES = 48 * 1024;
24
- export const DEEP_RESEARCH_RECENT_REFS_MAX = DEEP_RESEARCH_CLIENT_RECENT_ITEMS_MAX;
25
- export { DEEP_RESEARCH_CLIENT_OBJECTIVE_MAX_BYTES, DEEP_RESEARCH_CLIENT_TEXT_MAX_BYTES };
26
- export const DEEP_RESEARCH_IMPLEMENTATION_PROMPT_MAX_BYTES = DEEP_RESEARCH_CLIENT_IMPLEMENTATION_PROMPT_MAX_BYTES;
27
- const DEEP_RESEARCH_STABLE_ID_MAX_BYTES = 128;
28
- const DEEP_RESEARCH_STABLE_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
29
- const QUERY_ERRORS = [
30
- 'host_not_ready',
31
- 'host_draining',
32
- 'operation_unavailable',
33
- 'not_found',
34
- 'session_archived',
35
- 'invalid_request',
36
- 'internal_failure',
37
- ];
38
- export function encodeDeepResearchSnapshot(progress, revision) {
39
- return decodeDeepResearchQueryResult({
40
- kind: 'snapshot',
41
- revision,
42
- ...progress,
43
- checklist: progress.checklist.map((item) => ({
44
- ...item,
45
- blockedReason: item.blockedReason ?? null,
46
- })),
47
- recentInspectedRefs: progress.recentInspectedRefs.map((ref) => ({
48
- ...ref,
49
- label: ref.label ?? null,
50
- })),
51
- reportArtifactId: progress.reportArtifactId ?? null,
52
- implementationPrompt: progress.implementationPrompt ?? null,
53
- });
54
- }
55
- export const DEEP_RESEARCH_OPERATION_SPECS = {
56
- 'deep-research.query': defineOperation({
57
- mode: 'query',
58
- availability: 'ready',
59
- errors: QUERY_ERRORS,
60
- decodeInput: decodeDeepResearchQueryInput,
61
- decodeOutput: decodeDeepResearchQueryResult,
62
- assertOutputForInput(input, output) {
63
- if (output.sessionId !== input.sessionId) {
64
- throw invalidProtocolFrame('Deep Research result belongs to a different Session');
65
- }
66
- },
67
- }),
68
- };
69
- export function decodeDeepResearchQueryInput(value) {
70
- const input = requireExactRecord(value, 'Deep Research query input', ['sessionId']);
71
- return { sessionId: requireEntityId(input.sessionId, 'sessionId') };
72
- }
73
- export function decodeDeepResearchQueryResult(value) {
74
- requireEncodedByteLimit(value, 'Deep Research query result', DEEP_RESEARCH_RESULT_MAX_BYTES);
75
- const record = requireShapedRecord(value, 'Deep Research query result', ['kind', 'sessionId', 'revision'], [
76
- 'objective',
77
- 'scopeLevel',
78
- 'status',
79
- 'stage',
80
- 'round',
81
- 'createdAt',
82
- 'updatedAt',
83
- 'artifactsCount',
84
- 'stepsCount',
85
- 'checklist',
86
- 'reportSections',
87
- 'recentInspectedRefs',
88
- 'workerRunIds',
89
- 'blockers',
90
- 'reportArtifactId',
91
- 'implementationPrompt',
92
- ]);
93
- const sessionId = requireEntityId(record.sessionId, 'sessionId');
94
- const revision = requireCount(record.revision, 'Deep Research revision');
95
- if (record.kind === 'not_started') {
96
- requireExactRecord(record, 'Deep Research not-started result', [
97
- 'kind',
98
- 'sessionId',
99
- 'revision',
100
- ]);
101
- if (revision !== 0)
102
- throw invalidProtocolFrame('Invalid Deep Research not-started revision');
103
- return { kind: 'not_started', sessionId, revision: 0 };
104
- }
105
- if (record.kind !== 'snapshot') {
106
- throw invalidProtocolFrame('Invalid Deep Research query result kind');
107
- }
108
- requireExactRecord(record, 'Deep Research snapshot result', [
109
- 'kind',
110
- 'sessionId',
111
- 'revision',
112
- 'objective',
113
- 'scopeLevel',
114
- 'status',
115
- 'stage',
116
- 'round',
117
- 'createdAt',
118
- 'updatedAt',
119
- 'artifactsCount',
120
- 'stepsCount',
121
- 'checklist',
122
- 'reportSections',
123
- 'recentInspectedRefs',
124
- 'workerRunIds',
125
- 'blockers',
126
- 'reportArtifactId',
127
- 'implementationPrompt',
128
- ]);
129
- if (revision === 0)
130
- throw invalidProtocolFrame('Invalid Deep Research snapshot revision');
131
- return {
132
- kind: 'snapshot',
133
- sessionId,
134
- revision,
135
- objective: requireUtf8String(record.objective, 'Deep Research objective', DEEP_RESEARCH_CLIENT_OBJECTIVE_MAX_BYTES),
136
- scopeLevel: requireEnum(record.scopeLevel, DEEP_RESEARCH_SCOPE_LEVELS, 'Deep Research scope level'),
137
- status: requireEnum(record.status, DEEP_RESEARCH_RUN_STATUSES, 'Deep Research status'),
138
- stage: requireEnum(record.stage, DEEP_RESEARCH_STAGES, 'Deep Research stage'),
139
- round: requireCount(record.round, 'Deep Research round'),
140
- createdAt: requireCount(record.createdAt, 'Deep Research createdAt'),
141
- updatedAt: requireCount(record.updatedAt, 'Deep Research updatedAt'),
142
- artifactsCount: requireCount(record.artifactsCount, 'Deep Research artifact count'),
143
- stepsCount: requireCount(record.stepsCount, 'Deep Research step count'),
144
- checklist: decodeChecklist(record.checklist),
145
- reportSections: decodeReportSections(record.reportSections),
146
- recentInspectedRefs: decodeInspectedRefs(record.recentInspectedRefs),
147
- workerRunIds: decodeIds(record.workerRunIds, 'Deep Research worker run ids'),
148
- blockers: decodeTexts(record.blockers, 'Deep Research blockers'),
149
- reportArtifactId: nullableId(record.reportArtifactId, 'Deep Research report artifact id'),
150
- implementationPrompt: nullableText(record.implementationPrompt, 'Deep Research implementation prompt', DEEP_RESEARCH_IMPLEMENTATION_PROMPT_MAX_BYTES),
151
- };
152
- }
153
- function decodeTexts(value, name) {
154
- if (!Array.isArray(value) || value.length > DEEP_RESEARCH_RECENT_REFS_MAX) {
155
- throw invalidProtocolFrame(`Invalid ${name}`);
156
- }
157
- return value.map((item) => requireUtf8String(item, name, DEEP_RESEARCH_CLIENT_TEXT_MAX_BYTES));
158
- }
159
- function decodeChecklist(value) {
160
- if (!Array.isArray(value) || value.length > DEEP_RESEARCH_CHECKLIST_ITEMS_MAX) {
161
- throw invalidProtocolFrame('Invalid Deep Research checklist');
162
- }
163
- return value.map((candidate) => {
164
- const item = requireExactRecord(candidate, 'Deep Research checklist item', [
165
- 'itemId',
166
- 'title',
167
- 'status',
168
- 'blockedReason',
169
- ]);
170
- return {
171
- itemId: requireEntityId(item.itemId, 'Deep Research checklist item id'),
172
- title: requireUtf8String(item.title, 'Deep Research checklist title', DEEP_RESEARCH_CLIENT_TEXT_MAX_BYTES),
173
- status: requireEnum(item.status, DEEP_RESEARCH_CHECKLIST_STATUSES, 'Deep Research checklist status'),
174
- blockedReason: nullableText(item.blockedReason, 'Deep Research checklist blocker', DEEP_RESEARCH_CLIENT_TEXT_MAX_BYTES),
175
- };
176
- });
177
- }
178
- function decodeReportSections(value) {
179
- if (!Array.isArray(value) || value.length > DEEP_RESEARCH_REPORT_SECTION_KEYS.length) {
180
- throw invalidProtocolFrame('Invalid Deep Research report sections');
181
- }
182
- return value.map((candidate) => {
183
- const section = requireExactRecord(candidate, 'Deep Research report section', [
184
- 'key',
185
- 'status',
186
- ]);
187
- return {
188
- key: requireEnum(section.key, DEEP_RESEARCH_REPORT_SECTION_KEYS, 'Deep Research report section key'),
189
- status: requireEnum(section.status, DEEP_RESEARCH_REPORT_SECTION_STATUSES, 'Deep Research report section status'),
190
- };
191
- });
192
- }
193
- function decodeInspectedRefs(value) {
194
- if (!Array.isArray(value) || value.length > DEEP_RESEARCH_RECENT_REFS_MAX) {
195
- throw invalidProtocolFrame('Invalid Deep Research inspected refs');
196
- }
197
- return value.map((candidate) => {
198
- const ref = requireExactRecord(candidate, 'Deep Research inspected ref', [
199
- 'kind',
200
- 'locator',
201
- 'label',
202
- ]);
203
- return {
204
- kind: requireEnum(ref.kind, DEEP_RESEARCH_INSPECTED_REF_KINDS, 'Deep Research inspected ref kind'),
205
- locator: requireUtf8String(ref.locator, 'Deep Research inspected ref locator', DEEP_RESEARCH_CLIENT_TEXT_MAX_BYTES),
206
- label: nullableText(ref.label, 'Deep Research inspected ref label', DEEP_RESEARCH_CLIENT_TEXT_MAX_BYTES),
207
- };
208
- });
209
- }
210
- function decodeIds(value, label) {
211
- if (!Array.isArray(value) || value.length > DEEP_RESEARCH_RECENT_REFS_MAX) {
212
- throw invalidProtocolFrame(`Invalid ${label}`);
213
- }
214
- return value.map((candidate) => requireStableResearchId(candidate, label));
215
- }
216
- function nullableId(value, label) {
217
- return value === null ? null : requireEntityId(value, label);
218
- }
219
- function nullableText(value, label, maxBytes) {
220
- return value === null ? null : requireUtf8String(value, label, maxBytes);
221
- }
222
- function requireStableResearchId(value, label) {
223
- const id = requireUtf8String(value, label, DEEP_RESEARCH_STABLE_ID_MAX_BYTES);
224
- if (!DEEP_RESEARCH_STABLE_ID.test(id))
225
- throw invalidProtocolFrame(`Invalid ${label}`);
226
- return id;
227
- }
228
- function requireEnum(value, values, label) {
229
- if (typeof value !== 'string' || !values.includes(value)) {
230
- throw invalidProtocolFrame(`Invalid ${label}`);
231
- }
232
- return value;
233
- }
@@ -1,116 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
- import { projectDeepResearchEvents } from '@maka/core/deep-research-run';
20
- import { projectDeepResearchClientProgress } from '@maka/core/deep-research-client-progress';
21
- import { isDeepResearchSession } from '@maka/core/deep-research';
22
- import { buildDeepResearchTools } from '@maka/runtime/deep-research-tools';
23
- import { authenticateInteractiveArtifactStoreWriter, } from '@maka/storage/artifact-stores';
24
- import { authenticateInteractiveDeepResearchStoreWriter, } from '@maka/storage/deep-research-authority';
25
- import { isSessionNotFoundError, } from '@maka/storage/execution-stores';
26
- import { encodeDeepResearchSnapshot, } from '../protocol/index.js';
27
- /** Host-owned Deep Research ledger, model-tool, and Client projection boundary. */
28
- export class HostDeepResearchCoordinator {
29
- handlers = {
30
- 'deep-research.query': (input) => this.#sessionAdmission.run(input.sessionId, () => this.#query(input)),
31
- };
32
- #store;
33
- #artifacts;
34
- #sessions;
35
- #sessionAdmission;
36
- #unsubscribe;
37
- constructor(input) {
38
- this.#store = authenticateInteractiveDeepResearchStoreWriter(input.store);
39
- this.#artifacts = authenticateInteractiveArtifactStoreWriter(input.artifacts);
40
- this.#sessions = input.sessions;
41
- this.#sessionAdmission = input.sessionAdmission;
42
- this.#unsubscribe = this.#store.subscribe(({ sessionId }) => {
43
- input.onProjectionChanged(sessionId);
44
- });
45
- }
46
- toolsForSession(sessionId) {
47
- return buildDeepResearchTools({
48
- store: this.#store,
49
- artifactStore: {
50
- create: async (input) => {
51
- if (input.sessionId !== sessionId) {
52
- throw new Error('Deep Research tool attempted to write another Session');
53
- }
54
- return this.#artifacts.create(input);
55
- },
56
- get: async (artifactId) => (await this.#artifacts.getInSession(sessionId, artifactId)).record ?? null,
57
- readText: (artifactId, options) => this.#artifacts.readTextInSession(sessionId, artifactId, options),
58
- delete: (artifactId) => this.#artifacts.deleteOwnedArtifactInSession(sessionId, artifactId, 'deep_research'),
59
- },
60
- });
61
- }
62
- close() {
63
- this.#unsubscribe();
64
- }
65
- async #query(input) {
66
- const unavailable = await this.#assertSessionAvailable(input.sessionId);
67
- if (unavailable)
68
- return failure(unavailable.code, unavailable.message);
69
- try {
70
- const events = await this.#store.readEvents(input.sessionId);
71
- if (events.length === 0) {
72
- return success({ kind: 'not_started', sessionId: input.sessionId, revision: 0 });
73
- }
74
- const projection = projectDeepResearchEvents(events);
75
- if (projection.diagnostics.length > 0 || !projection.run) {
76
- return failure('internal_failure', 'Deep Research projection is unavailable');
77
- }
78
- return success(projectDeepResearchRun(projection.run, events.length));
79
- }
80
- catch (error) {
81
- if (isSessionNotFoundError(error))
82
- return failure('not_found', 'Session does not exist');
83
- return failure('internal_failure', 'Deep Research projection is unavailable');
84
- }
85
- }
86
- async #assertSessionAvailable(sessionId) {
87
- try {
88
- const header = await this.#sessions.readHeaderSnapshot(sessionId);
89
- if (header.isArchived) {
90
- return { code: 'session_archived', message: 'Session is archived' };
91
- }
92
- if (!isDeepResearchSession(header.labels)) {
93
- return {
94
- code: 'invalid_request',
95
- message: 'Session is not a Deep Research Session',
96
- };
97
- }
98
- return undefined;
99
- }
100
- catch (error) {
101
- if (isSessionNotFoundError(error)) {
102
- return { code: 'not_found', message: 'Session does not exist' };
103
- }
104
- return { code: 'internal_failure', message: 'Session authority is unavailable' };
105
- }
106
- }
107
- }
108
- export function projectDeepResearchRun(run, revision) {
109
- return encodeDeepResearchSnapshot(projectDeepResearchClientProgress(run), revision);
110
- }
111
- function success(result) {
112
- return { ok: true, result };
113
- }
114
- function failure(code, message) {
115
- return { ok: false, error: { code, message } };
116
- }
@@ -1,129 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
- import { assertStorageRootLease, runWithStorageRootLease, StorageRootAuthorityError, } from './root-authority.js';
20
- import { createSqliteDeepResearchStore, } from './deep-research-store.js';
21
- const writerBrand = Symbol('InteractiveDeepResearchStoreWriter');
22
- const writers = new WeakSet();
23
- const writerByLease = new WeakMap();
24
- const writerOpeningByLease = new WeakMap();
25
- export function authenticateInteractiveDeepResearchStoreWriter(writer) {
26
- if (!writers.has(writer)) {
27
- throw new StorageRootAuthorityError('invalid_lease', 'Expected an authentic interactive Deep Research Store writer');
28
- }
29
- return writer;
30
- }
31
- export async function openInteractiveDeepResearchStoreForWrite(lease) {
32
- await assertStorageRootLease(lease, 'interactive', 'write');
33
- const existing = writerByLease.get(lease);
34
- if (existing)
35
- return existing;
36
- const opening = writerOpeningByLease.get(lease);
37
- if (opening)
38
- return opening;
39
- const pending = Promise.resolve().then(async () => {
40
- let store;
41
- try {
42
- store = await runWithStorageRootLease(lease, 'interactive', 'write', async (root) => {
43
- const opened = createSqliteDeepResearchStore(root);
44
- try {
45
- await opened.ready();
46
- return opened;
47
- }
48
- catch (error) {
49
- opened.close();
50
- throw error;
51
- }
52
- });
53
- await assertStorageRootLease(lease, 'interactive', 'write');
54
- const recoveredExisting = writerByLease.get(lease);
55
- if (recoveredExisting) {
56
- store.close();
57
- return recoveredExisting;
58
- }
59
- const writer = createWriterFacade(lease, store);
60
- writers.add(writer);
61
- writerByLease.set(lease, writer);
62
- return writer;
63
- }
64
- catch (error) {
65
- store?.close();
66
- throw error;
67
- }
68
- });
69
- writerOpeningByLease.set(lease, pending);
70
- try {
71
- return await pending;
72
- }
73
- finally {
74
- if (writerOpeningByLease.get(lease) === pending)
75
- writerOpeningByLease.delete(lease);
76
- }
77
- }
78
- function createWriterFacade(lease, store) {
79
- let closed = false;
80
- const run = (operation) => {
81
- if (closed) {
82
- return Promise.reject(new StorageRootAuthorityError('invalid_lease', 'Deep Research Store writer is closed'));
83
- }
84
- return runWithStorageRootLease(lease, 'interactive', 'write', operation);
85
- };
86
- const writer = {
87
- kind: 'interactive',
88
- access: 'write',
89
- [writerBrand]: true,
90
- read: (sessionId) => run(() => store.read(sessionId)),
91
- readEvents: (sessionId) => run(() => store.readEvents(sessionId)),
92
- start: (sessionId, objective, scopeLevel, context) => run(() => store.start(sessionId, objective, scopeLevel, cloneContext(context))),
93
- recordArtifact: (sessionId, artifact, context) => run(() => store.recordArtifact(sessionId, cloneArtifact(artifact), cloneContext(context))),
94
- updateChecklist: (sessionId, item, context) => run(() => store.updateChecklist(sessionId, cloneChecklist(item), cloneContext(context))),
95
- recordStep: (sessionId, step, context) => run(() => store.recordStep(sessionId, cloneStep(step), cloneContext(context))),
96
- recordCheckpoint: (sessionId, checkpoint, context) => run(() => store.recordCheckpoint(sessionId, cloneCheckpoint(checkpoint), cloneContext(context))),
97
- complete: (sessionId, reportArtifactId, handoff, context) => run(() => store.complete(sessionId, reportArtifactId, cloneHandoff(handoff), cloneContext(context))),
98
- subscribe: (listener) => store.subscribe(listener),
99
- purgeSessionState: (sessionId) => run(() => store.purgeSessionState(sessionId)),
100
- close: () => {
101
- if (closed)
102
- return;
103
- closed = true;
104
- if (writerByLease.get(lease) === writer)
105
- writerByLease.delete(lease);
106
- writers.delete(writer);
107
- store.close();
108
- },
109
- };
110
- return Object.freeze(writer);
111
- }
112
- function cloneContext(context) {
113
- return context ? { ...context } : undefined;
114
- }
115
- function cloneArtifact(artifact) {
116
- return structuredClone(artifact);
117
- }
118
- function cloneChecklist(item) {
119
- return structuredClone(item);
120
- }
121
- function cloneStep(step) {
122
- return structuredClone(step);
123
- }
124
- function cloneCheckpoint(checkpoint) {
125
- return structuredClone(checkpoint);
126
- }
127
- function cloneHandoff(handoff) {
128
- return structuredClone(handoff);
129
- }