cordisx 0.1.0-beta.46 → 0.1.0-beta.47
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/assets/launcher/native-app-server-protocol.mjs +23 -29
- package/dist/assets/launcher/native-provider-continuation.mjs +109 -0
- package/dist/assets/launcher/native-provider-transport.mjs +2 -2
- package/dist/codex-adapter/adapter.mjs +141 -28
- package/dist/codex-adapter/index.js +1 -1
- package/dist/codex-adapter/native-provider-continuation-structure.d.ts +16 -0
- package/dist/codex-adapter/native-provider-continuation-structure.js +100 -0
- package/dist/codex-adapter/native-submission-structure.js +32 -6
- package/dist/native/native-helper-artifact.json +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/help.d.ts.map +1 -1
- package/dist/src/cli/help.js +2 -1
- package/dist/src/cli/help.js.map +1 -1
- package/dist/src/cli/parse.d.ts +1 -0
- package/dist/src/cli/parse.d.ts.map +1 -1
- package/dist/src/cli/parse.js +9 -1
- package/dist/src/cli/parse.js.map +1 -1
- package/dist/src/cli/production-managed-services.d.ts +1 -0
- package/dist/src/cli/production-managed-services.d.ts.map +1 -1
- package/dist/src/cli/production-managed-services.js +1 -0
- package/dist/src/cli/production-managed-services.js.map +1 -1
- package/dist/src/cli/production-plugin-management.d.ts +1 -0
- package/dist/src/cli/production-plugin-management.d.ts.map +1 -1
- package/dist/src/cli/production-plugin-management.js +5 -1
- package/dist/src/cli/production-plugin-management.js.map +1 -1
- package/dist/src/cli/run-command-dispatch.d.ts.map +1 -1
- package/dist/src/cli/run-command-dispatch.js +10 -1
- package/dist/src/cli/run-command-dispatch.js.map +1 -1
- package/dist/src/cli/run-command.d.ts +0 -1
- package/dist/src/cli/run-command.d.ts.map +1 -1
- package/dist/src/cli/run-command.js +28 -18
- package/dist/src/cli/run-command.js.map +1 -1
- package/dist/src/cli/service-owner.d.ts +4 -0
- package/dist/src/cli/service-owner.d.ts.map +1 -0
- package/dist/src/cli/service-owner.js +154 -0
- package/dist/src/cli/service-owner.js.map +1 -0
- package/dist/src/cli/start-mode.d.ts +4 -1
- package/dist/src/cli/start-mode.d.ts.map +1 -1
- package/dist/src/cli/start-mode.js +9 -6
- package/dist/src/cli/start-mode.js.map +1 -1
- package/dist/src/cli/supervisor-command.d.ts +1 -0
- package/dist/src/cli/supervisor-command.d.ts.map +1 -1
- package/dist/src/cli/supervisor-command.js +42 -11
- package/dist/src/cli/supervisor-command.js.map +1 -1
- package/dist/src/cli/supervisor-runtime.d.ts +1 -0
- package/dist/src/cli/supervisor-runtime.d.ts.map +1 -1
- package/dist/src/cli/supervisor-runtime.js +15 -1
- package/dist/src/cli/supervisor-runtime.js.map +1 -1
- package/dist/src/cli/supervisor-state.d.ts +2 -0
- package/dist/src/cli/supervisor-state.d.ts.map +1 -1
- package/dist/src/cli/supervisor-state.js +2 -0
- package/dist/src/cli/supervisor-state.js.map +1 -1
- package/dist/src/diagnostics/journal.d.ts.map +1 -1
- package/dist/src/diagnostics/journal.js +1 -0
- package/dist/src/diagnostics/journal.js.map +1 -1
- package/dist/src/launcher/agent-bridge.d.ts.map +1 -1
- package/dist/src/launcher/agent-bridge.js +7 -1
- package/dist/src/launcher/agent-bridge.js.map +1 -1
- package/dist/src/launcher/existing-model-provider-display.d.ts +5 -0
- package/dist/src/launcher/existing-model-provider-display.d.ts.map +1 -0
- package/dist/src/launcher/existing-model-provider-display.js +54 -0
- package/dist/src/launcher/existing-model-provider-display.js.map +1 -0
- package/dist/src/launcher/existing-terminal-provider-rpc.d.ts.map +1 -1
- package/dist/src/launcher/existing-terminal-provider-rpc.js +20 -1
- package/dist/src/launcher/existing-terminal-provider-rpc.js.map +1 -1
- package/dist/src/launcher/managed-service-candidate.d.ts +1 -0
- package/dist/src/launcher/managed-service-candidate.d.ts.map +1 -1
- package/dist/src/launcher/managed-service-candidate.js.map +1 -1
- package/dist/src/launcher/managed-service-node-host.js +1 -1
- package/dist/src/launcher/managed-service-node-host.js.map +1 -1
- package/dist/src/launcher/managed-service-process.d.ts +1 -1
- package/dist/src/launcher/managed-service-process.d.ts.map +1 -1
- package/dist/src/launcher/managed-service-process.js +12 -2
- package/dist/src/launcher/managed-service-process.js.map +1 -1
- package/dist/src/launcher/managed-service-runtime-process.d.ts.map +1 -1
- package/dist/src/launcher/managed-service-runtime-process.js +21 -2
- package/dist/src/launcher/managed-service-runtime-process.js.map +1 -1
- package/dist/src/launcher/managed-service-runtime.d.ts +2 -0
- package/dist/src/launcher/managed-service-runtime.d.ts.map +1 -1
- package/dist/src/launcher/managed-service-runtime.js +8 -2
- package/dist/src/launcher/managed-service-runtime.js.map +1 -1
- package/dist/src/launcher/managed-service-startup-diagnostic.d.ts +2 -1
- package/dist/src/launcher/managed-service-startup-diagnostic.d.ts.map +1 -1
- package/dist/src/launcher/managed-service-startup-diagnostic.js.map +1 -1
- package/dist/src/launcher/management-rpc.d.ts.map +1 -1
- package/dist/src/launcher/management-rpc.js +6 -0
- package/dist/src/launcher/management-rpc.js.map +1 -1
- package/dist/src/launcher/model-api-server.d.ts +34 -0
- package/dist/src/launcher/model-api-server.d.ts.map +1 -0
- package/dist/src/launcher/model-api-server.js +444 -0
- package/dist/src/launcher/model-api-server.js.map +1 -0
- package/dist/src/launcher/native-model-provider-catalog.d.ts +4 -0
- package/dist/src/launcher/native-model-provider-catalog.d.ts.map +1 -1
- package/dist/src/launcher/native-model-provider-catalog.js.map +1 -1
- package/dist/src/launcher/native-remote-provider-source.d.ts +3 -3
- package/dist/src/launcher/native-remote-provider-source.d.ts.map +1 -1
- package/dist/src/launcher/native-remote-provider-source.js +18 -4
- package/dist/src/launcher/native-remote-provider-source.js.map +1 -1
- package/dist/src/launcher/native-submission-cdp-channel.d.ts +2 -0
- package/dist/src/launcher/native-submission-cdp-channel.d.ts.map +1 -1
- package/dist/src/launcher/native-submission-cdp-channel.js +43 -4
- package/dist/src/launcher/native-submission-cdp-channel.js.map +1 -1
- package/dist/src/launcher/native-submission-composition.d.ts.map +1 -1
- package/dist/src/launcher/native-submission-composition.js +122 -1
- package/dist/src/launcher/native-submission-composition.js.map +1 -1
- package/dist/src/launcher/native-submission-continuation.d.ts +17 -0
- package/dist/src/launcher/native-submission-continuation.d.ts.map +1 -0
- package/dist/src/launcher/native-submission-continuation.js +56 -0
- package/dist/src/launcher/native-submission-continuation.js.map +1 -0
- package/dist/src/launcher/native-submission-control-server.d.ts.map +1 -1
- package/dist/src/launcher/native-submission-control-server.js +21 -2
- package/dist/src/launcher/native-submission-control-server.js.map +1 -1
- package/dist/src/launcher/native-submission-controller-contracts.d.ts +34 -0
- package/dist/src/launcher/native-submission-controller-contracts.d.ts.map +1 -1
- package/dist/src/launcher/native-submission-controller.d.ts.map +1 -1
- package/dist/src/launcher/native-submission-controller.js +59 -40
- package/dist/src/launcher/native-submission-controller.js.map +1 -1
- package/dist/src/launcher/native-submission-records.d.ts +50 -0
- package/dist/src/launcher/native-submission-records.d.ts.map +1 -0
- package/dist/src/launcher/native-submission-records.js +30 -0
- package/dist/src/launcher/native-submission-records.js.map +1 -0
- package/dist/src/launcher/plugin-lifecycle-model.d.ts +2 -0
- package/dist/src/launcher/plugin-lifecycle-model.d.ts.map +1 -1
- package/dist/src/launcher/plugin-lifecycle-model.js.map +1 -1
- package/dist/src/launcher/plugin-lifecycle-transaction.js +2 -2
- package/dist/src/launcher/plugin-lifecycle-transaction.js.map +1 -1
- package/dist/src/launcher/profile-runtime-owner.d.ts +3 -0
- package/dist/src/launcher/profile-runtime-owner.d.ts.map +1 -0
- package/dist/src/launcher/profile-runtime-owner.js +17 -0
- package/dist/src/launcher/profile-runtime-owner.js.map +1 -0
- package/dist/src/launcher/remote-terminal-provider-client.d.ts.map +1 -1
- package/dist/src/launcher/remote-terminal-provider-client.js +4 -0
- package/dist/src/launcher/remote-terminal-provider-client.js.map +1 -1
- package/dist/src/launcher/responses-encrypted-replay.js +1 -1
- package/dist/src/launcher/service-model-api.d.ts +25 -0
- package/dist/src/launcher/service-model-api.d.ts.map +1 -0
- package/dist/src/launcher/service-model-api.js +84 -0
- package/dist/src/launcher/service-model-api.js.map +1 -0
- package/dist/src/launcher/service-plugin-runtime.d.ts +5 -0
- package/dist/src/launcher/service-plugin-runtime.d.ts.map +1 -0
- package/dist/src/launcher/service-plugin-runtime.js +90 -0
- package/dist/src/launcher/service-plugin-runtime.js.map +1 -0
- package/dist/src/launcher/terminal-provider.d.ts +3 -0
- package/dist/src/launcher/terminal-provider.d.ts.map +1 -1
- package/dist/src/launcher/terminal-provider.js +17 -6
- package/dist/src/launcher/terminal-provider.js.map +1 -1
- package/dist/src/management/contracts.d.ts +2 -1
- package/dist/src/management/contracts.d.ts.map +1 -1
- package/dist/src/management/service.d.ts +1 -0
- package/dist/src/management/service.d.ts.map +1 -1
- package/dist/src/management/service.js +9 -4
- package/dist/src/management/service.js.map +1 -1
- package/dist/src/model-provider-display.d.ts +13 -0
- package/dist/src/model-provider-display.d.ts.map +1 -0
- package/dist/src/model-provider-display.js +36 -0
- package/dist/src/model-provider-display.js.map +1 -0
- package/dist/src/renderer/adapter/model-provider-display.d.ts +8 -0
- package/dist/src/renderer/adapter/model-provider-display.d.ts.map +1 -0
- package/dist/src/renderer/adapter/model-provider-display.js +46 -0
- package/dist/src/renderer/adapter/model-provider-display.js.map +1 -0
- package/dist/src/renderer/adapter/native-composer-creation.d.ts +23 -0
- package/dist/src/renderer/adapter/native-composer-creation.d.ts.map +1 -0
- package/dist/src/renderer/adapter/native-composer-creation.js +129 -0
- package/dist/src/renderer/adapter/native-composer-creation.js.map +1 -0
- package/dist/src/renderer/adapter/native-submission-action-normalizer.d.ts +1 -0
- package/dist/src/renderer/adapter/native-submission-action-normalizer.d.ts.map +1 -1
- package/dist/src/renderer/adapter/native-submission-action-normalizer.js +3 -0
- package/dist/src/renderer/adapter/native-submission-action-normalizer.js.map +1 -1
- package/dist/src/renderer/codex-router-history.d.ts +13 -15
- package/dist/src/renderer/codex-router-history.d.ts.map +1 -1
- package/dist/src/renderer/codex-router-history.js +56 -78
- package/dist/src/renderer/codex-router-history.js.map +1 -1
- package/dist/src/renderer/codex-router-navigator.d.ts +22 -0
- package/dist/src/renderer/codex-router-navigator.d.ts.map +1 -0
- package/dist/src/renderer/codex-router-navigator.js +82 -0
- package/dist/src/renderer/codex-router-navigator.js.map +1 -0
- package/dist/src/renderer/host-ui/AgentTaskDetailsNavigator.js +2 -2
- package/dist/src/renderer/host-ui/AgentTaskDetailsNavigator.js.map +1 -1
- package/dist/src/renderer/install-model-provider-selector.d.ts +1 -1
- package/dist/src/renderer/install-model-provider-selector.d.ts.map +1 -1
- package/dist/src/renderer/install-model-provider-selector.js +12 -4
- package/dist/src/renderer/install-model-provider-selector.js.map +1 -1
- package/dist/src/renderer/model-provider-preferences.d.ts +1 -0
- package/dist/src/renderer/model-provider-preferences.d.ts.map +1 -1
- package/dist/src/renderer/model-provider-preferences.js +4 -0
- package/dist/src/renderer/model-provider-preferences.js.map +1 -1
- package/dist/src/renderer/model-provider-selection.d.ts +41 -0
- package/dist/src/renderer/model-provider-selection.d.ts.map +1 -0
- package/dist/src/renderer/model-provider-selection.js +141 -0
- package/dist/src/renderer/model-provider-selection.js.map +1 -0
- package/dist/src/renderer/model-provider-selector.d.ts +5 -4
- package/dist/src/renderer/model-provider-selector.d.ts.map +1 -1
- package/dist/src/renderer/model-provider-selector.js +18 -97
- package/dist/src/renderer/model-provider-selector.js.map +1 -1
- package/dist/src/renderer/model-providers.d.ts +3 -0
- package/dist/src/renderer/model-providers.d.ts.map +1 -1
- package/dist/src/renderer/model-providers.js +10 -3
- package/dist/src/renderer/model-providers.js.map +1 -1
- package/dist/src/renderer/native-composer-creation-handoff.d.ts +25 -0
- package/dist/src/renderer/native-composer-creation-handoff.d.ts.map +1 -0
- package/dist/src/renderer/native-composer-creation-handoff.js +147 -0
- package/dist/src/renderer/native-composer-creation-handoff.js.map +1 -0
- package/dist/src/renderer/native-composer-refresh.d.ts +33 -0
- package/dist/src/renderer/native-composer-refresh.d.ts.map +1 -0
- package/dist/src/renderer/native-composer-refresh.js +105 -0
- package/dist/src/renderer/native-composer-refresh.js.map +1 -0
- package/dist/src/renderer/native-composer-request-observer.d.ts +34 -0
- package/dist/src/renderer/native-composer-request-observer.d.ts.map +1 -0
- package/dist/src/renderer/native-composer-request-observer.js +169 -0
- package/dist/src/renderer/native-composer-request-observer.js.map +1 -0
- package/dist/src/renderer/native-composer-submission-router.d.ts +7 -7
- package/dist/src/renderer/native-composer-submission-router.d.ts.map +1 -1
- package/dist/src/renderer/native-composer-submission-router.js +21 -1
- package/dist/src/renderer/native-composer-submission-router.js.map +1 -1
- package/dist/src/renderer/native-model-provider-transport.d.ts +4 -7
- package/dist/src/renderer/native-model-provider-transport.d.ts.map +1 -1
- package/dist/src/renderer/native-model-provider-transport.js +107 -234
- package/dist/src/renderer/native-model-provider-transport.js.map +1 -1
- package/dist/src/renderer/native-provider-continuation.d.ts +29 -0
- package/dist/src/renderer/native-provider-continuation.d.ts.map +1 -0
- package/dist/src/renderer/native-provider-continuation.js +64 -0
- package/dist/src/renderer/native-provider-continuation.js.map +1 -0
- package/dist/src/renderer/native-provider-selection-client.d.ts +9 -1
- package/dist/src/renderer/native-provider-selection-client.d.ts.map +1 -1
- package/dist/src/renderer/native-provider-selection-client.js +22 -2
- package/dist/src/renderer/native-provider-selection-client.js.map +1 -1
- package/dist/src/renderer/native-provider-submission-policy.d.ts +1 -0
- package/dist/src/renderer/native-provider-submission-policy.d.ts.map +1 -1
- package/dist/src/renderer/native-provider-submission-policy.js.map +1 -1
- package/dist/src/renderer/navigation-registry-base.js +7 -7
- package/dist/src/renderer/navigation-registry-base.js.map +1 -1
- package/dist/src/renderer/runtime-agent-composition.d.ts.map +1 -1
- package/dist/src/renderer/runtime-agent-composition.js +6 -1
- package/dist/src/renderer/runtime-agent-composition.js.map +1 -1
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ import { nativeInput } from './native-app-server-input.mjs'
|
|
|
9
9
|
import { createNativeProviderTransport } from './native-provider-transport.mjs'
|
|
10
10
|
import { nativeProviderFailure } from './native-provider-errors.mjs'
|
|
11
11
|
import { switchNativeThread } from './native-thread-switch.mjs'
|
|
12
|
+
import { createNativeProviderContinuation, dispatchNativeSelectionMutation } from './native-provider-continuation.mjs'
|
|
12
13
|
|
|
13
14
|
const socketPath = process.env.CORDISX_NATIVE_CONTROL_SOCKET
|
|
14
15
|
const nonce = process.env.CORDISX_NATIVE_CONTROL_NONCE
|
|
@@ -618,6 +619,7 @@ async function forward(line) {
|
|
|
618
619
|
firstTurns.delete(params.threadId)
|
|
619
620
|
agentFirstTurns.delete(params.threadId)
|
|
620
621
|
}
|
|
622
|
+
if (message.method === 'turn/start') continuation.dispatched(token, params.threadId)
|
|
621
623
|
await write(nativeTransport.stdin, JSON.stringify(message))
|
|
622
624
|
} catch {
|
|
623
625
|
desktopCalls.delete(message?.id)
|
|
@@ -872,6 +874,11 @@ readLines(nativeTransport.stdout, line => {
|
|
|
872
874
|
|
|
873
875
|
const switching = new Set()
|
|
874
876
|
const switchRequests = new Map()
|
|
877
|
+
const continuation = createNativeProviderContinuation({
|
|
878
|
+
nativeCall,
|
|
879
|
+
lifecyclePending,
|
|
880
|
+
current: threadId => !closed && !cancelledRecovery.has(threadId) && !lifecyclePending(threadId),
|
|
881
|
+
})
|
|
875
882
|
const BRIDGE_NATIVE_METHODS = new Set([
|
|
876
883
|
'thread/list',
|
|
877
884
|
'thread/read',
|
|
@@ -944,33 +951,20 @@ readLines(control, line => {
|
|
|
944
951
|
}).catch(() => write(control, { id: message.id, ok: false }).catch(stop))
|
|
945
952
|
return
|
|
946
953
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
})
|
|
964
|
-
if (result.reason === 'provider-switch-reconciliation-required') {
|
|
965
|
-
uncertainSwitches.set(message.threadId, undefined)
|
|
966
|
-
}
|
|
967
|
-
await write(control, { id: message.id, ...result })
|
|
968
|
-
} catch {
|
|
969
|
-
await write(control, { id: message.id, ok: false })
|
|
970
|
-
} finally {
|
|
971
|
-
switching.delete(message.threadId)
|
|
972
|
-
switchRequests.delete(message.id)
|
|
973
|
-
cancelledRecovery.delete(message.threadId)
|
|
974
|
-
}
|
|
975
|
-
})().catch(stop)
|
|
954
|
+
dispatchNativeSelectionMutation(message, {
|
|
955
|
+
switching,
|
|
956
|
+
switchRequests,
|
|
957
|
+
recoveringTurns,
|
|
958
|
+
lifecyclePending,
|
|
959
|
+
cancelledRecovery,
|
|
960
|
+
uncertainSwitches,
|
|
961
|
+
nativeCall,
|
|
962
|
+
controlCall,
|
|
963
|
+
switchNativeThread,
|
|
964
|
+
continuation,
|
|
965
|
+
write,
|
|
966
|
+
control,
|
|
967
|
+
closed: () => closed,
|
|
968
|
+
stop,
|
|
969
|
+
})
|
|
976
970
|
}, maxControlLineBytes)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const valid = (value, max = 512) =>
|
|
2
|
+
typeof value === 'string' && value.length > 0 && value.length <= max && !/[\0\r\n]/u.test(value)
|
|
3
|
+
|
|
4
|
+
/** Owns only normal forks created for a Host-admitted Composer Send. */
|
|
5
|
+
export function createNativeProviderContinuation({ nativeCall, lifecyclePending, current }) {
|
|
6
|
+
const forks = new Map()
|
|
7
|
+
const discard = async (operationToken, threadId) => {
|
|
8
|
+
const fork = forks.get(operationToken)
|
|
9
|
+
if (!fork || fork.threadId !== threadId || fork.dispatched) return false
|
|
10
|
+
const read = await nativeCall('thread/read', { threadId, includeTurns: false })
|
|
11
|
+
if (
|
|
12
|
+
read?.thread?.id !== threadId || read.thread.modelProvider !== fork.providerId
|
|
13
|
+
|| !['idle', 'notLoaded'].includes(read.thread.status?.type) || lifecyclePending(threadId)
|
|
14
|
+
) return false
|
|
15
|
+
await nativeCall('thread/archive', { threadId })
|
|
16
|
+
forks.delete(operationToken)
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
dispatched(operationToken, threadId) {
|
|
21
|
+
const fork = forks.get(operationToken)
|
|
22
|
+
if (fork?.threadId === threadId) {
|
|
23
|
+
fork.dispatched = true
|
|
24
|
+
forks.delete(operationToken)
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
async handle(message) {
|
|
28
|
+
if (!valid(message.operationToken, 256)) return { ok: false }
|
|
29
|
+
if (message.type === 'continuation-discard') {
|
|
30
|
+
return { ok: true, value: await discard(message.operationToken, message.threadId) }
|
|
31
|
+
}
|
|
32
|
+
if (!valid(message.threadId) || !valid(message.providerId, 128) || !valid(message.model)) {
|
|
33
|
+
return { ok: false }
|
|
34
|
+
}
|
|
35
|
+
if (forks.has(message.operationToken) || forks.size >= 32) return { ok: false }
|
|
36
|
+
const source = await nativeCall('thread/read', { threadId: message.threadId, includeTurns: false })
|
|
37
|
+
if (
|
|
38
|
+
!current(message.threadId) || source?.thread?.id !== message.threadId
|
|
39
|
+
|| !['idle', 'notLoaded', 'systemError'].includes(source.thread.status?.type)
|
|
40
|
+
) return { ok: false }
|
|
41
|
+
if (source.thread.ephemeral === true) return { ok: false, reason: 'provider-switch-unsupported' }
|
|
42
|
+
try {
|
|
43
|
+
const result = await nativeCall('thread/fork', {
|
|
44
|
+
threadId: message.threadId,
|
|
45
|
+
modelProvider: message.providerId,
|
|
46
|
+
model: message.model,
|
|
47
|
+
config: message.config,
|
|
48
|
+
ephemeral: false,
|
|
49
|
+
excludeTurns: true,
|
|
50
|
+
deferGoalContinuation: true,
|
|
51
|
+
})
|
|
52
|
+
const thread = result?.thread
|
|
53
|
+
if (
|
|
54
|
+
!valid(thread?.id) || thread.id === message.threadId || thread.ephemeral === true
|
|
55
|
+
|| result.modelProvider !== message.providerId || result.model !== message.model
|
|
56
|
+
|| thread.status?.type !== 'idle'
|
|
57
|
+
) return { ok: false, reason: 'provider-switch-reconciliation-required' }
|
|
58
|
+
forks.set(message.operationToken, { threadId: thread.id, providerId: message.providerId, dispatched: false })
|
|
59
|
+
if (!current(message.threadId)) {
|
|
60
|
+
await discard(message.operationToken, thread.id)
|
|
61
|
+
return { ok: false, reason: 'provider-switch-reconciliation-required' }
|
|
62
|
+
}
|
|
63
|
+
return { ok: true, value: { threadId: thread.id } }
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return error.nativeError === undefined
|
|
66
|
+
? { ok: false, reason: 'provider-switch-reconciliation-required' }
|
|
67
|
+
: { ok: false }
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Shared switch/fork scheduling preserves the existing lifecycle fence. */
|
|
74
|
+
export function dispatchNativeSelectionMutation(message, ports) {
|
|
75
|
+
const { switching, switchRequests, recoveringTurns, lifecyclePending, cancelledRecovery, uncertainSwitches } = ports
|
|
76
|
+
const { nativeCall, controlCall, switchNativeThread, continuation, write, control, closed, stop } = ports
|
|
77
|
+
if (!['switch', 'continuation-fork', 'continuation-discard'].includes(message.type)) return false
|
|
78
|
+
if (
|
|
79
|
+
typeof message.id !== 'string' || switching.has(message.threadId) || recoveringTurns.has(message.threadId)
|
|
80
|
+
|| lifecyclePending(message.threadId)
|
|
81
|
+
) {
|
|
82
|
+
void write(control, { id: message.id, ok: false }).catch(stop)
|
|
83
|
+
return true
|
|
84
|
+
}
|
|
85
|
+
switching.add(message.threadId)
|
|
86
|
+
switchRequests.set(message.id, message.threadId)
|
|
87
|
+
void (async () => {
|
|
88
|
+
try {
|
|
89
|
+
const result = message.type === 'switch'
|
|
90
|
+
? await switchNativeThread(message, {
|
|
91
|
+
nativeCall,
|
|
92
|
+
controlCall,
|
|
93
|
+
current: () => !closed() && !cancelledRecovery.has(message.threadId) && !lifecyclePending(message.threadId),
|
|
94
|
+
})
|
|
95
|
+
: await continuation.handle(message)
|
|
96
|
+
if (result.reason === 'provider-switch-reconciliation-required') {
|
|
97
|
+
uncertainSwitches.set(message.threadId, undefined)
|
|
98
|
+
}
|
|
99
|
+
await write(control, { id: message.id, ...result })
|
|
100
|
+
} catch {
|
|
101
|
+
await write(control, { id: message.id, ok: false })
|
|
102
|
+
} finally {
|
|
103
|
+
switching.delete(message.threadId)
|
|
104
|
+
switchRequests.delete(message.id)
|
|
105
|
+
cancelledRecovery.delete(message.threadId)
|
|
106
|
+
}
|
|
107
|
+
})().catch(stop)
|
|
108
|
+
return true
|
|
109
|
+
}
|
|
@@ -40,7 +40,7 @@ export function createNativeProviderTransport(primary, { executable, args, env,
|
|
|
40
40
|
if (pending) {
|
|
41
41
|
connection.pending.delete(key(message.id))
|
|
42
42
|
const thread = message.result?.thread
|
|
43
|
-
if (!message.error && thread?.id && ['thread/start', 'thread/resume'].includes(pending.method)) {
|
|
43
|
+
if (!message.error && thread?.id && ['thread/start', 'thread/resume', 'thread/fork'].includes(pending.method)) {
|
|
44
44
|
owners.set(thread.id, {
|
|
45
45
|
connection,
|
|
46
46
|
status: thread.status,
|
|
@@ -225,7 +225,7 @@ export function createNativeProviderTransport(primary, { executable, args, env,
|
|
|
225
225
|
) return
|
|
226
226
|
const params = object(message.params)
|
|
227
227
|
let connection = owners.get(params?.threadId)?.connection ?? primary
|
|
228
|
-
if (initializeParams && ['thread/start', 'thread/resume'].includes(message.method)) {
|
|
228
|
+
if (initializeParams && ['thread/start', 'thread/resume', 'thread/fork'].includes(message.method)) {
|
|
229
229
|
const config = object(params?.config)
|
|
230
230
|
const tables = config ? Object.keys(config).filter(name => name.startsWith('model_providers.')) : []
|
|
231
231
|
const id = provider(params?.modelProvider) ?? provider(config?.model_provider)
|
|
@@ -5928,9 +5928,105 @@ function nativeModuleFactories(ast) {
|
|
|
5928
5928
|
return result;
|
|
5929
5929
|
}
|
|
5930
5930
|
|
|
5931
|
+
// src/native-provider-continuation-structure.ts
|
|
5932
|
+
var continuation = "__cordisxProviderContinuation";
|
|
5933
|
+
var carrier = "__cordisxOperationToken";
|
|
5934
|
+
var has = (node, keys) => keys.every((key) => properties(node).has(key));
|
|
5935
|
+
function continuationLocalSend(plan) {
|
|
5936
|
+
const matches = plan.functions.flatMap((fn) => {
|
|
5937
|
+
if (!fn.async || fn.body.type !== "BlockStatement" || fn.params.length !== 10 || !fn.params.every((param) => param.type === "Identifier")) return [];
|
|
5938
|
+
const context = fn.params[0].name;
|
|
5939
|
+
const follow = fn.params[1].name;
|
|
5940
|
+
const calls = plan.nodes(fn.body, (node) => node.type === "ObjectExpression" && has(node, [
|
|
5941
|
+
"scope",
|
|
5942
|
+
"context",
|
|
5943
|
+
"targetConversationId",
|
|
5944
|
+
"managerHostId",
|
|
5945
|
+
"clientUserMessageId",
|
|
5946
|
+
"onMessageAdded",
|
|
5947
|
+
"permissionSelection",
|
|
5948
|
+
"submissionLifecycle"
|
|
5949
|
+
]) && properties(node).get("context")?.name === context && member(properties(node).get("targetConversationId"), "localConversationId") && properties(node).get("targetConversationId")?.object.name === follow);
|
|
5950
|
+
return calls.length === 1 ? [{ fn, context, follow }] : [];
|
|
5951
|
+
});
|
|
5952
|
+
if (matches.length === 0) return;
|
|
5953
|
+
for (const { fn, context, follow } of matches) {
|
|
5954
|
+
const restore = fn.params[4].name;
|
|
5955
|
+
plan.insert(
|
|
5956
|
+
fn.body.start + 1,
|
|
5957
|
+
`
|
|
5958
|
+
if(${context}.${continuation}!==void 0){
|
|
5959
|
+
let __cxBranch=${context}.${continuation};
|
|
5960
|
+
if(__cxBranch.sourceThreadId!==${follow}.localConversationId
|
|
5961
|
+
||typeof __cxBranch.threadId!=='string'||!__cxBranch.threadId||__cxBranch.threadId.length>512
|
|
5962
|
+
||/[\\0\\r\\n]/u.test(__cxBranch.threadId)||__cxBranch.threadId===__cxBranch.sourceThreadId
|
|
5963
|
+
||typeof ${context}.${carrier}!=='string')throw new Error('Native continuation target changed');
|
|
5964
|
+
${follow}={...${follow},localConversationId:__cxBranch.threadId};
|
|
5965
|
+
${context}={...${context},messageThreadId:__cxBranch.threadId};
|
|
5966
|
+
if(${restore}!=null)${restore}={...${restore},context:{...${restore}.context,messageThreadId:__cxBranch.threadId}};
|
|
5967
|
+
}
|
|
5968
|
+
`
|
|
5969
|
+
);
|
|
5970
|
+
plan.capabilities.push("continuation-local-send");
|
|
5971
|
+
plan.claimCapability("continuation-local-send", fn);
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
function continuationComposerSend(plan, fn, input, decision2) {
|
|
5975
|
+
const target = plan.binding(input, "submitTarget");
|
|
5976
|
+
const calls = plan.nodes(fn.body, (node) => node.type === "AwaitExpression" && node.argument.type === "CallExpression" && member(node.argument.callee, "submit") && node.argument.callee.object.name === target);
|
|
5977
|
+
if (calls.length === 0) return void 0;
|
|
5978
|
+
const local = calls.filter(
|
|
5979
|
+
(node) => node.argument.arguments.length >= 7 && !member(node.argument.arguments[4], "executionOptions")
|
|
5980
|
+
);
|
|
5981
|
+
if (local.length !== 1) throw new Error("Native capability continuation-submit: ambiguous local submission");
|
|
5982
|
+
const names = new Set(plan.nodes(fn, (node) => node.type === "Identifier").map((node) => node.name));
|
|
5983
|
+
let witness = "__cxContinuationSubmission";
|
|
5984
|
+
while (names.has(witness)) witness += "_";
|
|
5985
|
+
const call = local[0];
|
|
5986
|
+
const callback = call.argument.arguments[7];
|
|
5987
|
+
if (!callback) throw new Error("Native capability continuation-submit: missing message callback");
|
|
5988
|
+
let deferred = "__cxContinuationMessageAdded";
|
|
5989
|
+
while (names.has(deferred)) deferred += "_";
|
|
5990
|
+
plan.insert(fn.body.start + 1, `let ${witness},${deferred};try{`);
|
|
5991
|
+
plan.replace(
|
|
5992
|
+
callback,
|
|
5993
|
+
`((__cxCallback)=>{
|
|
5994
|
+
if(${decision2}.continuation===void 0||typeof __cxCallback!=='function')return __cxCallback;
|
|
5995
|
+
${deferred}={callback:__cxCallback,accepted:false};
|
|
5996
|
+
return(...__cxArgs)=>{
|
|
5997
|
+
if(${deferred}.accepted)return __cxCallback(...__cxArgs);
|
|
5998
|
+
${deferred}.args=__cxArgs;
|
|
5999
|
+
};
|
|
6000
|
+
})(${plan.text(callback)})`
|
|
6001
|
+
);
|
|
6002
|
+
const capture = `((__cxResult)=>{
|
|
6003
|
+
if(${decision2}.continuation!==void 0)${witness}={operationToken:${decision2}.operationToken,
|
|
6004
|
+
continuation:${decision2}.continuation,accepted:__cxResult?.threadId===${decision2}.continuation.threadId
|
|
6005
|
+
&&__cxResult?.messageResult?.status==='sent'};
|
|
6006
|
+
if(${witness}?.accepted&&${deferred}){
|
|
6007
|
+
${deferred}.accepted=true;
|
|
6008
|
+
if(${deferred}.args){
|
|
6009
|
+
const __cxArgs=${deferred}.args;delete ${deferred}.args;
|
|
6010
|
+
try{Promise.resolve(${deferred}.callback(...__cxArgs)).catch(()=>{});}catch{}
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
return __cxResult;
|
|
6014
|
+
})(`;
|
|
6015
|
+
plan.insert(call.start, capture);
|
|
6016
|
+
plan.insert(call.end, ")");
|
|
6017
|
+
plan.insert(
|
|
6018
|
+
fn.body.end - 1,
|
|
6019
|
+
`}finally{
|
|
6020
|
+
if(${witness}?.accepted)queueMicrotask(()=>globalThis.__cordisxNativeContinuationComplete?.(${witness}));
|
|
6021
|
+
}`
|
|
6022
|
+
);
|
|
6023
|
+
plan.capabilities.push("continuation-composer-send");
|
|
6024
|
+
return `,...(${decision2}.continuation===void 0?{}:{${continuation}:${decision2}.continuation})`;
|
|
6025
|
+
}
|
|
6026
|
+
|
|
5931
6027
|
// src/native-submission-structure.ts
|
|
5932
6028
|
var TOKEN = "cordisx.operation_token";
|
|
5933
|
-
var
|
|
6029
|
+
var carrier2 = "__cordisxOperationToken";
|
|
5934
6030
|
var reasoningCarrier = "__cordisxReasoningEffort";
|
|
5935
6031
|
var decision = "__cordisxAdmissionDecision";
|
|
5936
6032
|
var tier = "globalThis.__cordisxNativeServiceTierOverride";
|
|
@@ -5938,7 +6034,7 @@ var hash = (source) => createHash2("sha256").update(source).digest("hex");
|
|
|
5938
6034
|
var valid = (value) => `(typeof ${value}==='string'&&${value}.length>=16&&${value}.length<=256&&!/[\\0\\r\\n]/u.test(${value})?${value}:void 0)`;
|
|
5939
6035
|
var config = (value, base = "void 0") => `(${value}===void 0?${base}:{...${base},${JSON.stringify(TOKEN)}:${value}})`;
|
|
5940
6036
|
var isFunction2 = (node) => /^(?:FunctionExpression|FunctionDeclaration|ArrowFunctionExpression)$/u.test(node?.type ?? "");
|
|
5941
|
-
var
|
|
6037
|
+
var has2 = (node, keys) => keys.every((key) => properties(node).has(key));
|
|
5942
6038
|
var uniqueBinding = (plan, root, base) => {
|
|
5943
6039
|
const names = new Set(plan.nodes(root, (node) => node.type === "Identifier").map((node) => node.name));
|
|
5944
6040
|
let binding = base;
|
|
@@ -5947,10 +6043,10 @@ var uniqueBinding = (plan, root, base) => {
|
|
|
5947
6043
|
};
|
|
5948
6044
|
function inputPattern(plan, fn, keys) {
|
|
5949
6045
|
const parameter = fn.params[0]?.type === "AssignmentPattern" ? fn.params[0].left : fn.params[0];
|
|
5950
|
-
if (
|
|
6046
|
+
if (has2(parameter, keys)) return parameter;
|
|
5951
6047
|
if (parameter?.type !== "Identifier") return void 0;
|
|
5952
6048
|
const patterns = (plan.declarations.get(fn) ?? []).filter(
|
|
5953
|
-
(declaration) => declaration.init?.type === "Identifier" && declaration.init.name === parameter.name &&
|
|
6049
|
+
(declaration) => declaration.init?.type === "Identifier" && declaration.init.name === parameter.name && has2(declaration.id, keys)
|
|
5954
6050
|
);
|
|
5955
6051
|
if (patterns.length === 0) return void 0;
|
|
5956
6052
|
return one(patterns, "submission-input").id;
|
|
@@ -6035,7 +6131,7 @@ function submitGuard(plan, fn) {
|
|
|
6035
6131
|
const input = inputPattern(plan, fn, ["submitTarget", "isResponseInProgress", "options"]);
|
|
6036
6132
|
const bind = (name) => plan.binding(input, name);
|
|
6037
6133
|
const options = bind("options");
|
|
6038
|
-
const declaration = plan.require(fn.body, (n) => n.type === "VariableDeclarator" &&
|
|
6134
|
+
const declaration = plan.require(fn.body, (n) => n.type === "VariableDeclarator" && has2(n.id, ["promptRawOverride", "persistedPromptRawOverride"]) && n.init?.type === "Identifier" && n.init.name === options, "submit-options");
|
|
6039
6135
|
if (!fn.async) throw new Error("Native capability submit guard requires asynchronous admission");
|
|
6040
6136
|
const block = plan.require(
|
|
6041
6137
|
fn.body,
|
|
@@ -6058,27 +6154,35 @@ function submitGuard(plan, fn) {
|
|
|
6058
6154
|
const follow = bind("followUp");
|
|
6059
6155
|
const raw = plan.binding(declaration.id, "promptRawOverride");
|
|
6060
6156
|
const persisted = plan.binding(declaration.id, "persistedPromptRawOverride");
|
|
6157
|
+
const continuationContext = continuationComposerSend(plan, fn, input, decision);
|
|
6061
6158
|
plan.insert(
|
|
6062
6159
|
optionsStatement.end,
|
|
6063
6160
|
`;let ${decision}={allow:true};if(typeof globalThis.__cordisxNativeSubmitHook==='function'){
|
|
6064
|
-
${decision}=await globalThis.__cordisxNativeSubmitHook({target:${bind("submitTarget")}.type,thread:${bind("conversationId")},response:${bind("isResponseInProgress")},followUp:${follow}?.type,followUpThread:${follow}?.type==='local'?${follow}.localConversationId:void 0,defaultAction:${bind("defaultFollowUpSubmitAction")},explicitAction:${options}.followUpSubmitAction,edit:${bind("editingQueuedMessagePosition")},promptOverride:${raw}!=null||${persisted}!=null}
|
|
6161
|
+
${decision}=await globalThis.__cordisxNativeSubmitHook({target:${bind("submitTarget")}.type,thread:${bind("conversationId")},response:${bind("isResponseInProgress")},followUp:${follow}?.type,followUpThread:${follow}?.type==='local'?${follow}.localConversationId:void 0,defaultAction:${bind("defaultFollowUpSubmitAction")},explicitAction:${options}.followUpSubmitAction,edit:${bind("editingQueuedMessagePosition")},promptOverride:${raw}!=null||${persisted}!=null,continuationAvailable:${continuationContext !== void 0}
|
|
6162
|
+
&&globalThis.__cordisxNativeContinuationLocalSendReady===true
|
|
6163
|
+
&&typeof globalThis.__cordisxNativeContinuationComplete==='function'});
|
|
6065
6164
|
if(${decision}?.allow!==true)return;if(${decision}.operationToken!==void 0&&${valid(`${decision}.operationToken`)}===void 0)return;
|
|
6165
|
+
if(${decision}.continuation!==void 0&&(${continuationContext === void 0}
|
|
6166
|
+
||${decision}.continuation.sourceThreadId!==${bind("conversationId")}
|
|
6167
|
+
||typeof ${decision}.continuation.threadId!=='string'||!${decision}.continuation.threadId
|
|
6168
|
+
||${decision}.continuation.threadId.length>512||/[\\0\\r\\n]/u.test(${decision}.continuation.threadId)
|
|
6169
|
+
||${decision}.continuation.threadId===${bind("conversationId")}||${decision}.operationToken===void 0))return;
|
|
6066
6170
|
}`
|
|
6067
6171
|
);
|
|
6068
|
-
const context = plan.require(fn.body, (n) => n.type === "ObjectExpression" &&
|
|
6172
|
+
const context = plan.require(fn.body, (n) => n.type === "ObjectExpression" && has2(n, ["threadReferences", "openingPromptForHistory"]) && n.properties.some(
|
|
6069
6173
|
(p) => p.type === "SpreadElement"
|
|
6070
6174
|
), "submit-context");
|
|
6071
6175
|
plan.insert(
|
|
6072
6176
|
context.end - 1,
|
|
6073
|
-
`,...(${decision}.serviceTier==='priority'||${decision}.serviceTier==='default'?{__cordisxServiceTier:${decision}.serviceTier}:{}),...(${decision}.operationToken===void 0?{}:{${
|
|
6177
|
+
`,...(${decision}.serviceTier==='priority'||${decision}.serviceTier==='default'?{__cordisxServiceTier:${decision}.serviceTier}:{}),...(${decision}.operationToken===void 0?{}:{${carrier2}:${decision}.operationToken,...(${JSON.stringify(modelReasoningEfforts)}.includes(${decision}.reasoningEffort)?{${reasoningCarrier}:${decision}.reasoningEffort}:{})})${continuationContext ?? ""}`
|
|
6074
6178
|
);
|
|
6075
6179
|
plan.capabilities.push("submit-guard");
|
|
6076
6180
|
}
|
|
6077
6181
|
function draftRequest(plan, fn) {
|
|
6078
6182
|
const context = plan.binding(inputPattern(plan, fn, ["context", "prompt", "serviceTier"]), "context");
|
|
6079
|
-
const request = plan.require(fn.body, (n) => n.type === "ObjectExpression" &&
|
|
6183
|
+
const request = plan.require(fn.body, (n) => n.type === "ObjectExpression" && has2(n, ["configOverrides", "requiresThreadReferences", "input", "serviceTier"]), "draft-request");
|
|
6080
6184
|
const overrides = properties(request).get("configOverrides");
|
|
6081
|
-
const token2 = valid(`${context}.${
|
|
6185
|
+
const token2 = valid(`${context}.${carrier2}`);
|
|
6082
6186
|
const effort = `${context}.${reasoningCarrier}`;
|
|
6083
6187
|
plan.replace(
|
|
6084
6188
|
overrides,
|
|
@@ -6094,33 +6198,41 @@ function existingRequest(plan, fn) {
|
|
|
6094
6198
|
const context = plan.binding(inputPattern(plan, fn, ["context", "targetConversationId", "serviceTier"]), "context");
|
|
6095
6199
|
const request = plan.require(
|
|
6096
6200
|
fn.body,
|
|
6097
|
-
(n) => n.type === "ObjectExpression" &&
|
|
6201
|
+
(n) => n.type === "ObjectExpression" && has2(n, ["threadId", "turnTrigger", "clientUserMessageId", "input", "multiAgentMode", "serviceTier"]),
|
|
6098
6202
|
"existing-request"
|
|
6099
6203
|
);
|
|
6100
|
-
|
|
6204
|
+
const token2 = valid(`${context}.${carrier2}`);
|
|
6205
|
+
plan.addConfig(request, token2);
|
|
6206
|
+
const metadata = properties(request).get("responsesapiClientMetadata");
|
|
6207
|
+
if (metadata) plan.replace(metadata, config(token2, plan.text(metadata)));
|
|
6208
|
+
else plan.insert(request.end - 1, `,...(${token2}===void 0?{}:{responsesapiClientMetadata:${config(token2)}})`);
|
|
6101
6209
|
plan.serviceTier(request, context);
|
|
6102
6210
|
plan.capabilities.push("existing-request");
|
|
6103
6211
|
}
|
|
6104
6212
|
function draftConfigForward(plan, fn) {
|
|
6105
|
-
const declaration = plan.require(fn.body, (n) => n.type === "VariableDeclarator" &&
|
|
6213
|
+
const declaration = plan.require(fn.body, (n) => n.type === "VariableDeclarator" && has2(n.id, ["configOverrides", "input", "threadStartKind", "requiresThreadReferences"]), "draft-config-input");
|
|
6106
6214
|
const binding = plan.binding(declaration.id, "configOverrides");
|
|
6107
|
-
plan.require(fn.body, (n) => n.type === "ObjectExpression" &&
|
|
6215
|
+
plan.require(fn.body, (n) => n.type === "ObjectExpression" && has2(n, ["config", "input", "threadStartKind", "requiresThreadReferences"]) && properties(n).get("config")?.type === "Identifier" && properties(n).get("config")?.name === binding, "draft-config-forward");
|
|
6108
6216
|
plan.capabilities.push("draft-config-forward");
|
|
6109
6217
|
}
|
|
6110
6218
|
function normalizedRequest(plan, fn) {
|
|
6111
|
-
const declaration = plan.require(fn.body, (n) => n.type === "VariableDeclarator" &&
|
|
6219
|
+
const declaration = plan.require(fn.body, (n) => n.type === "VariableDeclarator" && has2(n.id, ["inheritThreadSettings", "usePermissionSelection", "useAppServerPermissionDefault"]) && !has2(n.id, ["localTurnMetadata"]), "normalized-context");
|
|
6112
6220
|
if (declaration.init?.type !== "LogicalExpression" || !member(declaration.init.left, "context")) {
|
|
6113
6221
|
throw new Error("Native capability normalized-context: expected operation context");
|
|
6114
6222
|
}
|
|
6115
6223
|
const operation = plan.text(declaration.init.left.object);
|
|
6116
6224
|
const request = plan.require(
|
|
6117
6225
|
fn.body,
|
|
6118
|
-
(n) => n.type === "ObjectExpression" &&
|
|
6226
|
+
(n) => n.type === "ObjectExpression" && has2(n, ["input", "model", "effort", "multiAgentMode", "serviceTier", "cyberAccessProgram"]),
|
|
6119
6227
|
"normalized-request"
|
|
6120
6228
|
);
|
|
6121
|
-
|
|
6229
|
+
const token2 = valid(`${operation}.request.config?.[${JSON.stringify(TOKEN)}]`);
|
|
6230
|
+
plan.addConfig(request, token2);
|
|
6231
|
+
const metadata = properties(request).get("responsesapiClientMetadata");
|
|
6232
|
+
if (metadata) plan.replace(metadata, config(token2, plan.text(metadata)));
|
|
6233
|
+
else plan.insert(request.end - 1, `,...(${token2}===void 0?{}:{responsesapiClientMetadata:${config(token2)}})`);
|
|
6122
6234
|
plan.serviceTier(request, `(${operation}.context??{})`);
|
|
6123
|
-
const params = plan.require(fn.body, (n) => n.type === "ObjectExpression" && n !== request &&
|
|
6235
|
+
const params = plan.require(fn.body, (n) => n.type === "ObjectExpression" && n !== request && has2(n, ["model", "effort", "multiAgentMode", "serviceTier"]), "normalized-params");
|
|
6124
6236
|
plan.serviceTier(params, `(${operation}.context??{})`);
|
|
6125
6237
|
plan.capabilities.push("normalized-request");
|
|
6126
6238
|
}
|
|
@@ -6188,7 +6300,7 @@ function finalDispatch(plan, fn) {
|
|
|
6188
6300
|
plan.capabilities.push("final-dispatch");
|
|
6189
6301
|
}
|
|
6190
6302
|
function firstTurn(plan, fn) {
|
|
6191
|
-
const declaration = plan.require(fn.body, (n) => n.type === "VariableDeclarator" &&
|
|
6303
|
+
const declaration = plan.require(fn.body, (n) => n.type === "VariableDeclarator" && has2(n.id, [
|
|
6192
6304
|
"projectAssignment",
|
|
6193
6305
|
"threadStartKind",
|
|
6194
6306
|
"input",
|
|
@@ -6197,9 +6309,9 @@ function firstTurn(plan, fn) {
|
|
|
6197
6309
|
]), "first-turn-input");
|
|
6198
6310
|
const incomingConfig = properties(declaration.id).has("config") ? plan.binding(declaration.id, "config") : declaration.init?.type === "Identifier" ? `${plan.text(declaration.init)}.config` : void 0;
|
|
6199
6311
|
if (incomingConfig === void 0) throw new Error("Native capability first-turn-input: missing config source");
|
|
6200
|
-
const request = plan.require(fn.body, (n) => n.type === "ObjectExpression" &&
|
|
6312
|
+
const request = plan.require(fn.body, (n) => n.type === "ObjectExpression" && has2(n, ["model", "effort", "multiAgentMode", "input", "toolOutput", "collaborationMode"]), "first-turn-request");
|
|
6201
6313
|
const token2 = valid(`${incomingConfig}?.[${JSON.stringify(TOKEN)}]`);
|
|
6202
|
-
const receipt = plan.require(fn.body, (n) => n.type === "VariableDeclarator" &&
|
|
6314
|
+
const receipt = plan.require(fn.body, (n) => n.type === "VariableDeclarator" && has2(n.id, ["conversationResponse"]) && n.init?.type === "AwaitExpression", "first-turn-receipt");
|
|
6203
6315
|
const response = plan.binding(receipt.id, "conversationResponse");
|
|
6204
6316
|
const model = properties(request).get("model");
|
|
6205
6317
|
if (!plan.nodes(model, (n) => member(n, "model") && n.object.name === response).length) {
|
|
@@ -6226,7 +6338,7 @@ function firstTurn(plan, fn) {
|
|
|
6226
6338
|
function modelCompletion(plan) {
|
|
6227
6339
|
const menus = [];
|
|
6228
6340
|
visitSyntax(plan.ast, (node, parents) => {
|
|
6229
|
-
if (node.type === "ObjectExpression" &&
|
|
6341
|
+
if (node.type === "ObjectExpression" && has2(node, ["onSelectModel", "onSelectModelOption"]) && (has2(node, ["onSelectReasoningEffort"]) || has2(node, ["onSelectComplete", "onBeforeSelectModel", "onSelectDefault", "model", "reasoningEffort"]))) {
|
|
6230
6342
|
const binding = properties(node).get("onSelectModel");
|
|
6231
6343
|
if (binding?.type === "Identifier") menus.push({ binding: binding.name, owner: parents.findLast(isFunction2) });
|
|
6232
6344
|
}
|
|
@@ -6258,6 +6370,7 @@ function modelCompletion(plan) {
|
|
|
6258
6370
|
function analyzeNativeSubmissionTransforms(resources) {
|
|
6259
6371
|
const plans = resources.map((resource) => new ResourcePlan(resource));
|
|
6260
6372
|
for (const plan of plans) {
|
|
6373
|
+
continuationLocalSend(plan);
|
|
6261
6374
|
for (const fn of plan.functions) {
|
|
6262
6375
|
const before = plan.capabilities.length;
|
|
6263
6376
|
if (inputPattern(plan, fn, ["submitTarget", "isResponseInProgress", "options"])) {
|
|
@@ -6278,14 +6391,14 @@ function analyzeNativeSubmissionTransforms(resources) {
|
|
|
6278
6391
|
finalDispatch(plan, fn);
|
|
6279
6392
|
}
|
|
6280
6393
|
const declarations = plan.declarations.get(fn) ?? [];
|
|
6281
|
-
if (declarations.some((n) =>
|
|
6394
|
+
if (declarations.some((n) => has2(n.id, ["configOverrides", "input", "threadStartKind", "requiresThreadReferences"]))) {
|
|
6282
6395
|
draftConfigForward(plan, fn);
|
|
6283
6396
|
}
|
|
6284
6397
|
if (declarations.some(
|
|
6285
|
-
(n) => n.type === "VariableDeclarator" &&
|
|
6398
|
+
(n) => n.type === "VariableDeclarator" && has2(n.id, ["inheritThreadSettings", "usePermissionSelection", "useAppServerPermissionDefault"]) && !has2(n.id, ["localTurnMetadata"])
|
|
6286
6399
|
)) normalizedRequest(plan, fn);
|
|
6287
6400
|
if (declarations.some(
|
|
6288
|
-
(n) => n.type === "VariableDeclarator" &&
|
|
6401
|
+
(n) => n.type === "VariableDeclarator" && has2(n.id, [
|
|
6289
6402
|
"projectAssignment",
|
|
6290
6403
|
"threadStartKind",
|
|
6291
6404
|
"input",
|
|
@@ -6320,7 +6433,7 @@ function analyzeNativeSubmissionTransforms(resources) {
|
|
|
6320
6433
|
const sha256 = hash(plan.resource.source);
|
|
6321
6434
|
const marker2 = `__cordisxNativeStructure_${sha256.slice(0, 16)}`;
|
|
6322
6435
|
const source = applySourceEdits(plan.resource.source, plan.edits) + `
|
|
6323
|
-
;globalThis.${marker2}=true;${plan.capabilities.includes("submit-guard") ? "globalThis.__cordisxNativeSubmissionActivate?.(true);" : ""}`;
|
|
6436
|
+
;globalThis.${marker2}=true;${plan.capabilities.includes("submit-guard") ? "globalThis.__cordisxNativeSubmissionActivate?.(true);" : ""}${plan.capabilities.includes("continuation-local-send") ? "globalThis.__cordisxNativeContinuationLocalSendReady=true;" : ""}`;
|
|
6324
6437
|
return Object.freeze({
|
|
6325
6438
|
url: plan.resource.url,
|
|
6326
6439
|
sha256,
|
|
@@ -6333,7 +6446,7 @@ function analyzeNativeSubmissionTransforms(resources) {
|
|
|
6333
6446
|
source,
|
|
6334
6447
|
anchorMatches: 1,
|
|
6335
6448
|
acknowledgementExpression: `globalThis.${marker2}===true`,
|
|
6336
|
-
fenceExpression: `(delete globalThis.${marker2},delete globalThis.__cordisxNativeSubmitHook,true)`
|
|
6449
|
+
fenceExpression: `(delete globalThis.${marker2},delete globalThis.__cordisxNativeSubmitHook,delete globalThis.__cordisxNativeContinuationLocalSendReady,true)`
|
|
6337
6450
|
};
|
|
6338
6451
|
}
|
|
6339
6452
|
});
|
|
@@ -7192,7 +7305,7 @@ var syntaxes = /* @__PURE__ */ new WeakMap();
|
|
|
7192
7305
|
var bundle = {
|
|
7193
7306
|
apiVersion: 1,
|
|
7194
7307
|
relayContract: 1,
|
|
7195
|
-
version: "0.1.0-beta.
|
|
7308
|
+
version: "0.1.0-beta.3",
|
|
7196
7309
|
resourceHints: [
|
|
7197
7310
|
["submitTarget", "options", "openingPromptForHistory"],
|
|
7198
7311
|
["context", "configOverrides", "requiresThreadReferences"],
|
|
@@ -11,7 +11,7 @@ const syntaxes = new WeakMap();
|
|
|
11
11
|
export const bundle = {
|
|
12
12
|
apiVersion: 1,
|
|
13
13
|
relayContract: 1,
|
|
14
|
-
version: '0.1.0-beta.
|
|
14
|
+
version: '0.1.0-beta.3',
|
|
15
15
|
resourceHints: [
|
|
16
16
|
['submitTarget', 'options', 'openingPromptForHistory'],
|
|
17
17
|
['context', 'configOverrides', 'requiresThreadReferences'],
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SyntaxNode } from './native-source-structure.js';
|
|
2
|
+
interface ContinuationPlan {
|
|
3
|
+
readonly functions: readonly SyntaxNode[];
|
|
4
|
+
text(node: SyntaxNode): string;
|
|
5
|
+
binding(pattern: SyntaxNode, name: string): string;
|
|
6
|
+
nodes(root: SyntaxNode, predicate: (node: SyntaxNode, parents: readonly SyntaxNode[]) => boolean): SyntaxNode[];
|
|
7
|
+
insert(at: number, text: string): void;
|
|
8
|
+
replace(node: SyntaxNode, text: string): void;
|
|
9
|
+
claimCapability(capability: string, fn: SyntaxNode): void;
|
|
10
|
+
readonly capabilities: string[];
|
|
11
|
+
}
|
|
12
|
+
/** Retarget before the native local submission owner creates state, resumes, or builds an operation. */
|
|
13
|
+
export declare function continuationLocalSend(plan: ContinuationPlan): void;
|
|
14
|
+
/** Capture the real native submit result and navigate only after its Composer cleanup has run. */
|
|
15
|
+
export declare function continuationComposerSend(plan: ContinuationPlan, fn: SyntaxNode, input: SyntaxNode, decision: string): string | undefined;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { member, properties } from './native-source-structure.js';
|
|
2
|
+
const continuation = '__cordisxProviderContinuation';
|
|
3
|
+
const carrier = '__cordisxOperationToken';
|
|
4
|
+
const has = (node, keys) => keys.every(key => properties(node).has(key));
|
|
5
|
+
/** Retarget before the native local submission owner creates state, resumes, or builds an operation. */
|
|
6
|
+
export function continuationLocalSend(plan) {
|
|
7
|
+
const matches = plan.functions.flatMap(fn => {
|
|
8
|
+
if (!fn.async || fn.body.type !== 'BlockStatement' || fn.params.length !== 10
|
|
9
|
+
|| !fn.params.every((param) => param.type === 'Identifier'))
|
|
10
|
+
return [];
|
|
11
|
+
const context = fn.params[0].name;
|
|
12
|
+
const follow = fn.params[1].name;
|
|
13
|
+
const calls = plan.nodes(fn.body, node => node.type === 'ObjectExpression'
|
|
14
|
+
&& has(node, [
|
|
15
|
+
'scope',
|
|
16
|
+
'context',
|
|
17
|
+
'targetConversationId',
|
|
18
|
+
'managerHostId',
|
|
19
|
+
'clientUserMessageId',
|
|
20
|
+
'onMessageAdded',
|
|
21
|
+
'permissionSelection',
|
|
22
|
+
'submissionLifecycle',
|
|
23
|
+
])
|
|
24
|
+
&& properties(node).get('context')?.name === context
|
|
25
|
+
&& member(properties(node).get('targetConversationId'), 'localConversationId')
|
|
26
|
+
&& properties(node).get('targetConversationId')?.object.name === follow);
|
|
27
|
+
return calls.length === 1 ? [{ fn, context, follow }] : [];
|
|
28
|
+
});
|
|
29
|
+
if (matches.length === 0)
|
|
30
|
+
return;
|
|
31
|
+
for (const { fn, context, follow } of matches) {
|
|
32
|
+
const restore = fn.params[4].name;
|
|
33
|
+
plan.insert(fn.body.start + 1, `
|
|
34
|
+
if(${context}.${continuation}!==void 0){
|
|
35
|
+
let __cxBranch=${context}.${continuation};
|
|
36
|
+
if(__cxBranch.sourceThreadId!==${follow}.localConversationId
|
|
37
|
+
||typeof __cxBranch.threadId!=='string'||!__cxBranch.threadId||__cxBranch.threadId.length>512
|
|
38
|
+
||/[\\0\\r\\n]/u.test(__cxBranch.threadId)||__cxBranch.threadId===__cxBranch.sourceThreadId
|
|
39
|
+
||typeof ${context}.${carrier}!=='string')throw new Error('Native continuation target changed');
|
|
40
|
+
${follow}={...${follow},localConversationId:__cxBranch.threadId};
|
|
41
|
+
${context}={...${context},messageThreadId:__cxBranch.threadId};
|
|
42
|
+
if(${restore}!=null)${restore}={...${restore},context:{...${restore}.context,messageThreadId:__cxBranch.threadId}};
|
|
43
|
+
}
|
|
44
|
+
`);
|
|
45
|
+
plan.capabilities.push('continuation-local-send');
|
|
46
|
+
plan.claimCapability('continuation-local-send', fn);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Capture the real native submit result and navigate only after its Composer cleanup has run. */
|
|
50
|
+
export function continuationComposerSend(plan, fn, input, decision) {
|
|
51
|
+
const target = plan.binding(input, 'submitTarget');
|
|
52
|
+
const calls = plan.nodes(fn.body, node => node.type === 'AwaitExpression' && node.argument.type === 'CallExpression'
|
|
53
|
+
&& member(node.argument.callee, 'submit') && node.argument.callee.object.name === target);
|
|
54
|
+
if (calls.length === 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
const local = calls.filter(node => node.argument.arguments.length >= 7
|
|
57
|
+
&& !member(node.argument.arguments[4], 'executionOptions'));
|
|
58
|
+
if (local.length !== 1)
|
|
59
|
+
throw new Error('Native capability continuation-submit: ambiguous local submission');
|
|
60
|
+
const names = new Set(plan.nodes(fn, node => node.type === 'Identifier').map(node => node.name));
|
|
61
|
+
let witness = '__cxContinuationSubmission';
|
|
62
|
+
while (names.has(witness))
|
|
63
|
+
witness += '_';
|
|
64
|
+
const call = local[0];
|
|
65
|
+
const callback = call.argument.arguments[7];
|
|
66
|
+
if (!callback)
|
|
67
|
+
throw new Error('Native capability continuation-submit: missing message callback');
|
|
68
|
+
let deferred = '__cxContinuationMessageAdded';
|
|
69
|
+
while (names.has(deferred))
|
|
70
|
+
deferred += '_';
|
|
71
|
+
plan.insert(fn.body.start + 1, `let ${witness},${deferred};try{`);
|
|
72
|
+
plan.replace(callback, `((__cxCallback)=>{
|
|
73
|
+
if(${decision}.continuation===void 0||typeof __cxCallback!=='function')return __cxCallback;
|
|
74
|
+
${deferred}={callback:__cxCallback,accepted:false};
|
|
75
|
+
return(...__cxArgs)=>{
|
|
76
|
+
if(${deferred}.accepted)return __cxCallback(...__cxArgs);
|
|
77
|
+
${deferred}.args=__cxArgs;
|
|
78
|
+
};
|
|
79
|
+
})(${plan.text(callback)})`);
|
|
80
|
+
const capture = `((__cxResult)=>{
|
|
81
|
+
if(${decision}.continuation!==void 0)${witness}={operationToken:${decision}.operationToken,
|
|
82
|
+
continuation:${decision}.continuation,accepted:__cxResult?.threadId===${decision}.continuation.threadId
|
|
83
|
+
&&__cxResult?.messageResult?.status==='sent'};
|
|
84
|
+
if(${witness}?.accepted&&${deferred}){
|
|
85
|
+
${deferred}.accepted=true;
|
|
86
|
+
if(${deferred}.args){
|
|
87
|
+
const __cxArgs=${deferred}.args;delete ${deferred}.args;
|
|
88
|
+
try{Promise.resolve(${deferred}.callback(...__cxArgs)).catch(()=>{});}catch{}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return __cxResult;
|
|
92
|
+
})(`;
|
|
93
|
+
plan.insert(call.start, capture);
|
|
94
|
+
plan.insert(call.end, ')');
|
|
95
|
+
plan.insert(fn.body.end - 1, `}finally{
|
|
96
|
+
if(${witness}?.accepted)queueMicrotask(()=>globalThis.__cordisxNativeContinuationComplete?.(${witness}));
|
|
97
|
+
}`);
|
|
98
|
+
plan.capabilities.push('continuation-composer-send');
|
|
99
|
+
return `,...(${decision}.continuation===void 0?{}:{${continuation}:${decision}.continuation})`;
|
|
100
|
+
}
|