@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.
Files changed (90) hide show
  1. package/README.md +82 -0
  2. package/docs/consumer-capability-matrix.md +374 -0
  3. package/package.json +17 -10
  4. package/scripts/generate-codex-protocol.ts +711 -0
  5. package/src/agents/agent-operation.ts +8 -0
  6. package/src/agents/agent-provider.ts +3 -0
  7. package/src/agents/agent-run.ts +14 -2
  8. package/src/agents/agent-runtime-error.ts +28 -0
  9. package/src/agents/agent-session-events.ts +33 -0
  10. package/src/agents/agent-tool-runner.ts +12 -11
  11. package/src/agents/agent-tool.ts +12 -4
  12. package/src/agents/author-context.ts +1 -1
  13. package/src/agents/claude/claude-auth.ts +40 -0
  14. package/src/agents/claude/claude-browser-turn-metadata.ts +70 -0
  15. package/src/agents/claude/claude-code-process.ts +98 -0
  16. package/src/agents/claude/claude-command-mapper.ts +63 -3
  17. package/src/agents/claude/claude-desktop.ts +55 -0
  18. package/src/agents/claude/claude-event-mapper.ts +876 -124
  19. package/src/agents/claude/claude-file-change.ts +128 -0
  20. package/src/agents/claude/claude-provider.ts +344 -29
  21. package/src/agents/claude/claude-run.ts +922 -91
  22. package/src/agents/claude/claude-selected-repository-instructions.ts +91 -0
  23. package/src/agents/claude/claude-skill-catalog.ts +75 -0
  24. package/src/agents/claude/claude-steered-notifications.ts +180 -0
  25. package/src/agents/claude/claude-tool-mapper.ts +81 -2
  26. package/src/agents/claude/claude-workspace-skills.ts +87 -0
  27. package/src/agents/claude/index.ts +2 -0
  28. package/src/agents/codex/codex-auth-mapper.ts +27 -0
  29. package/src/agents/codex/codex-auth.ts +19 -0
  30. package/src/agents/codex/codex-browser-auth-broker.ts +320 -0
  31. package/src/agents/codex/codex-browser-auth-status.ts +55 -0
  32. package/src/agents/codex/codex-command-mapper.ts +38 -3
  33. package/src/agents/codex/codex-event-mapper.ts +375 -64
  34. package/src/agents/codex/codex-json-rpc-client.ts +66 -21
  35. package/src/agents/codex/codex-provider.ts +118 -236
  36. package/src/agents/codex/codex-run-auth.ts +113 -0
  37. package/src/agents/codex/codex-run.ts +428 -48
  38. package/src/agents/codex/codex-tool-mapper.ts +2 -2
  39. package/src/agents/codex/codex.errors.ts +8 -0
  40. package/src/agents/codex/generated/meta.gen.ts +144 -6
  41. package/src/agents/codex/generated/namespaces.gen.ts +92 -3
  42. package/src/agents/codex/generated/schema.gen.ts +24698 -15638
  43. package/src/agents/codex/lazy-codex-run-auth.ts +47 -0
  44. package/src/agents/index.ts +5 -0
  45. package/src/agents/input-attachment-preparation.ts +13 -0
  46. package/src/agents/mcp-tool-content.ts +82 -0
  47. package/src/agents/model-rebinding-run.ts +14 -3
  48. package/src/agents/selected-repository-instructions.ts +202 -0
  49. package/src/agents/session-context.ts +41 -0
  50. package/src/agents/subscription-token-refresh.ts +73 -0
  51. package/src/agents/user-input-request.ts +19 -20
  52. package/src/errors/index.ts +1 -1
  53. package/src/errors/validation-error.ts +6 -0
  54. package/src/protocol/agent-catalog.ts +159 -0
  55. package/src/protocol/agent-command.ts +54 -7
  56. package/src/protocol/agent-content.ts +36 -16
  57. package/src/protocol/agent-event.ts +210 -73
  58. package/src/protocol/agent-identity.ts +29 -0
  59. package/src/protocol/agent-json.ts +122 -8
  60. package/src/protocol/agent-metadata.ts +2 -2
  61. package/src/protocol/agent-model.ts +13 -1
  62. package/src/protocol/agent-notification.ts +110 -0
  63. package/src/protocol/agent-presentation.ts +71 -20
  64. package/src/protocol/agent-tool.ts +66 -10
  65. package/src/protocol/agent-usage.ts +4 -1
  66. package/src/protocol/agent-user-input.ts +4 -4
  67. package/src/protocol/agent-work.ts +12 -10
  68. package/src/protocol/index.ts +2 -0
  69. package/src/protocol/rejected-keys.ts +11 -0
  70. package/src/provenance.gen.ts +3 -3
  71. package/src/steps/contract.ts +4 -1
  72. package/src/steps/projector.ts +17 -1
  73. package/src/supervisor/agent-provider-factory.ts +60 -5
  74. package/src/supervisor/bootstrap-binder.ts +3 -2
  75. package/src/supervisor/index.ts +1 -1
  76. package/src/supervisor/persistence/supervisor-store.ts +22 -8
  77. package/src/supervisor/runtime-handler.ts +30 -2
  78. package/src/supervisor-protocol/agent-event-wrapper.ts +30 -0
  79. package/src/supervisor-protocol/bootstrap.ts +4 -1
  80. package/src/supervisor-protocol/command-body.ts +4 -1
  81. package/src/supervisor-protocol/envelopes/supervisor-to-control-plane.ts +1 -0
  82. package/src/testing/in-memory-runtime-control-plane.ts +118 -12
  83. package/src/testing/index.ts +1 -1
  84. package/src/worker-runtime-client/command-pump.ts +85 -10
  85. package/src/worker-runtime-client/connection-attempt.ts +95 -20
  86. package/src/worker-runtime-client/frame-processor.ts +242 -58
  87. package/src/worker-runtime-client/index.ts +8 -2
  88. package/src/worker-runtime-client/ports.ts +34 -2
  89. package/src/worker-runtime-client/rpc-request-manager.ts +152 -107
  90. 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
+ }