@meistrari/agent-core 0.2.0-experimental.0 → 0.2.0-experimental.2
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/README.md +82 -0
- package/docs/consumer-capability-matrix.md +374 -0
- package/package.json +17 -10
- package/scripts/generate-codex-protocol.ts +711 -0
- package/src/agents/agent-operation.ts +8 -0
- package/src/agents/agent-provider.ts +3 -0
- package/src/agents/agent-run.ts +14 -2
- package/src/agents/agent-runtime-error.ts +28 -0
- package/src/agents/agent-session-events.ts +33 -0
- package/src/agents/agent-tool-runner.ts +12 -11
- package/src/agents/agent-tool.ts +12 -4
- package/src/agents/author-context.ts +1 -1
- package/src/agents/claude/claude-auth.ts +40 -0
- package/src/agents/claude/claude-browser-turn-metadata.ts +70 -0
- package/src/agents/claude/claude-code-process.ts +98 -0
- package/src/agents/claude/claude-command-mapper.ts +63 -3
- package/src/agents/claude/claude-desktop.ts +55 -0
- package/src/agents/claude/claude-event-mapper.ts +876 -124
- package/src/agents/claude/claude-file-change.ts +128 -0
- package/src/agents/claude/claude-provider.ts +344 -29
- package/src/agents/claude/claude-run.ts +922 -91
- package/src/agents/claude/claude-selected-repository-instructions.ts +91 -0
- package/src/agents/claude/claude-skill-catalog.ts +75 -0
- package/src/agents/claude/claude-steered-notifications.ts +180 -0
- package/src/agents/claude/claude-tool-mapper.ts +81 -2
- package/src/agents/claude/claude-workspace-skills.ts +87 -0
- package/src/agents/claude/index.ts +2 -0
- package/src/agents/codex/codex-auth-mapper.ts +27 -0
- package/src/agents/codex/codex-auth.ts +19 -0
- package/src/agents/codex/codex-browser-auth-broker.ts +320 -0
- package/src/agents/codex/codex-browser-auth-status.ts +55 -0
- package/src/agents/codex/codex-command-mapper.ts +38 -3
- package/src/agents/codex/codex-event-mapper.ts +375 -64
- package/src/agents/codex/codex-json-rpc-client.ts +66 -21
- package/src/agents/codex/codex-provider.ts +118 -236
- package/src/agents/codex/codex-run-auth.ts +113 -0
- package/src/agents/codex/codex-run.ts +428 -48
- package/src/agents/codex/codex-tool-mapper.ts +2 -2
- package/src/agents/codex/codex.errors.ts +8 -0
- package/src/agents/codex/generated/meta.gen.ts +144 -6
- package/src/agents/codex/generated/namespaces.gen.ts +92 -3
- package/src/agents/codex/generated/schema.gen.ts +24698 -15638
- package/src/agents/codex/lazy-codex-run-auth.ts +47 -0
- package/src/agents/index.ts +5 -0
- package/src/agents/input-attachment-preparation.ts +13 -0
- package/src/agents/mcp-tool-content.ts +82 -0
- package/src/agents/model-rebinding-run.ts +14 -3
- package/src/agents/selected-repository-instructions.ts +202 -0
- package/src/agents/session-context.ts +41 -0
- package/src/agents/subscription-token-refresh.ts +73 -0
- package/src/agents/user-input-request.ts +19 -20
- package/src/errors/index.ts +1 -1
- package/src/errors/validation-error.ts +6 -0
- package/src/protocol/agent-catalog.ts +159 -0
- package/src/protocol/agent-command.ts +54 -7
- package/src/protocol/agent-content.ts +36 -16
- package/src/protocol/agent-event.ts +210 -73
- package/src/protocol/agent-identity.ts +29 -0
- package/src/protocol/agent-json.ts +122 -8
- package/src/protocol/agent-metadata.ts +2 -2
- package/src/protocol/agent-model.ts +13 -1
- package/src/protocol/agent-notification.ts +110 -0
- package/src/protocol/agent-presentation.ts +71 -20
- package/src/protocol/agent-tool.ts +66 -10
- package/src/protocol/agent-usage.ts +4 -1
- package/src/protocol/agent-user-input.ts +4 -4
- package/src/protocol/agent-work.ts +12 -10
- package/src/protocol/index.ts +2 -0
- package/src/protocol/rejected-keys.ts +11 -0
- package/src/provenance.gen.ts +3 -3
- package/src/steps/contract.ts +4 -1
- package/src/steps/projector.ts +17 -1
- package/src/supervisor/agent-provider-factory.ts +60 -5
- package/src/supervisor/bootstrap-binder.ts +3 -2
- package/src/supervisor/index.ts +1 -1
- package/src/supervisor/persistence/supervisor-store.ts +22 -8
- package/src/supervisor/runtime-handler.ts +30 -2
- package/src/supervisor-protocol/agent-event-wrapper.ts +30 -0
- package/src/supervisor-protocol/bootstrap.ts +4 -1
- package/src/supervisor-protocol/command-body.ts +4 -1
- package/src/supervisor-protocol/envelopes/supervisor-to-control-plane.ts +1 -0
- package/src/testing/in-memory-runtime-control-plane.ts +118 -12
- package/src/testing/index.ts +1 -1
- package/src/worker-runtime-client/command-pump.ts +85 -10
- package/src/worker-runtime-client/connection-attempt.ts +95 -20
- package/src/worker-runtime-client/frame-processor.ts +242 -58
- package/src/worker-runtime-client/index.ts +8 -2
- package/src/worker-runtime-client/ports.ts +34 -2
- package/src/worker-runtime-client/rpc-request-manager.ts +152 -107
- package/src/worker-runtime-client/sandbox-connection-runtime.ts +72 -35
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { CodexAuthProvider, CodexAuthRefreshInput, CodexAuthTokenRequest, CodexAuthTokens } from './codex-auth'
|
|
2
|
+
import { AgentProviderProtocolError } from '../agent-runtime-error'
|
|
3
|
+
import { SubscriptionTokenRefresh } from '../subscription-token-refresh'
|
|
4
|
+
|
|
5
|
+
export class CodexRunAuthClosedError extends AgentProviderProtocolError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super({ message: 'Codex run authentication is closed.' })
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** One initial account selection; later replacements are owned by the central refresh callback. */
|
|
12
|
+
export class CodexRunAuth {
|
|
13
|
+
private readonly abort = new AbortController()
|
|
14
|
+
private readonly ready = Promise.withResolvers<void>()
|
|
15
|
+
private initialAcquisition: Promise<CodexAuthTokens> | undefined
|
|
16
|
+
private current: CodexAuthTokens | undefined
|
|
17
|
+
private readonly refresher = new SubscriptionTokenRefresh<CodexAuthTokens>({
|
|
18
|
+
installed: async () => {
|
|
19
|
+
const installed = await this.getCurrentTokens({})
|
|
20
|
+
this.abort.signal.throwIfAborted()
|
|
21
|
+
return installed
|
|
22
|
+
},
|
|
23
|
+
current: () => {
|
|
24
|
+
if (!this.current)
|
|
25
|
+
throw authSourceClosed()
|
|
26
|
+
return this.current
|
|
27
|
+
},
|
|
28
|
+
install: (tokens) => {
|
|
29
|
+
this.current = tokens
|
|
30
|
+
},
|
|
31
|
+
refresh: async (rejected) => {
|
|
32
|
+
const tokens = await waitForAuth(this.provider.refreshAuthTokens({ reason: 'unauthorized', ...rejected }), this.abort.signal)
|
|
33
|
+
this.abort.signal.throwIfAborted()
|
|
34
|
+
return tokens
|
|
35
|
+
},
|
|
36
|
+
accountId: tokens => tokens.chatgptAccountId,
|
|
37
|
+
conflictingIdentity: () => new AgentProviderProtocolError({ message: 'Codex authentication generation has conflicting token identities.' }),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
constructor(private readonly provider: CodexAuthProvider) {
|
|
41
|
+
void this.ready.promise.catch(() => undefined)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async acquireInitialTokens(input: CodexAuthTokenRequest): Promise<CodexAuthTokens> {
|
|
45
|
+
this.abort.signal.throwIfAborted()
|
|
46
|
+
this.initialAcquisition ??= this.acquire(input)
|
|
47
|
+
return await this.initialAcquisition
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async getCurrentTokens(input: CodexAuthTokenRequest): Promise<CodexAuthTokens> {
|
|
51
|
+
const signal = this.operationSignal(input.signal)
|
|
52
|
+
await waitForAuth(this.ready.promise, signal)
|
|
53
|
+
signal.throwIfAborted()
|
|
54
|
+
if (!this.current)
|
|
55
|
+
throw authSourceClosed()
|
|
56
|
+
return this.current
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async refreshAuthTokens(input: CodexAuthRefreshInput): Promise<CodexAuthTokens> {
|
|
60
|
+
this.abort.signal.throwIfAborted()
|
|
61
|
+
return await this.refresher.refresh(input)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
close(): void {
|
|
65
|
+
this.current = undefined
|
|
66
|
+
this.initialAcquisition = undefined
|
|
67
|
+
this.refresher.clear()
|
|
68
|
+
this.abort.abort(authSourceClosed())
|
|
69
|
+
this.ready.reject(authSourceClosed())
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private async acquire(input: CodexAuthTokenRequest): Promise<CodexAuthTokens> {
|
|
73
|
+
const signal = this.operationSignal(input.signal)
|
|
74
|
+
try {
|
|
75
|
+
signal.throwIfAborted()
|
|
76
|
+
const tokens = await waitForAuth(this.provider.getAuthTokens({ signal }), signal)
|
|
77
|
+
signal.throwIfAborted()
|
|
78
|
+
this.current = tokens
|
|
79
|
+
this.ready.resolve()
|
|
80
|
+
return tokens
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
this.ready.reject(error)
|
|
84
|
+
throw error
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private operationSignal(signal: AbortSignal | undefined): AbortSignal {
|
|
89
|
+
return signal ? AbortSignal.any([signal, this.abort.signal]) : this.abort.signal
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function waitForAuth<T>(operation: Promise<T>, signal: AbortSignal): Promise<T> {
|
|
94
|
+
signal.throwIfAborted()
|
|
95
|
+
let abort: (() => void) | undefined
|
|
96
|
+
try {
|
|
97
|
+
return await Promise.race([
|
|
98
|
+
operation,
|
|
99
|
+
new Promise<never>((_, reject) => {
|
|
100
|
+
abort = () => reject(signal.reason)
|
|
101
|
+
signal.addEventListener('abort', abort, { once: true })
|
|
102
|
+
}),
|
|
103
|
+
])
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
if (abort)
|
|
107
|
+
signal.removeEventListener('abort', abort)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function authSourceClosed(): CodexRunAuthClosedError {
|
|
112
|
+
return new CodexRunAuthClosedError()
|
|
113
|
+
}
|