@danceiny/gotry 0.0.1-rc.18 → 0.0.1-rc.19

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 (137) hide show
  1. package/README.md +42 -16
  2. package/README.zh-CN.md +37 -15
  3. package/bin/gotry-bootstrap.js +236 -3
  4. package/bin/gotry-inner.js +66 -20
  5. package/bin/gotry-runtime-resolution.d.ts +1 -1
  6. package/bin/gotry-runtime-resolution.js +7 -8
  7. package/cordis.gotry-patch.yml +15 -5
  8. package/data/stations-12306-verify.json +524 -0
  9. package/dist/capabilities/agent-reach.js +4 -4
  10. package/dist/capabilities/channel-health.js +103 -0
  11. package/dist/capabilities/channel-registry.js +213 -0
  12. package/dist/capabilities/doctor.js +285 -0
  13. package/dist/capabilities/effect.js +178 -5
  14. package/dist/capabilities/flyai.js +13 -0
  15. package/dist/capabilities/session/adapters/ctrip-hotel.js +207 -0
  16. package/dist/capabilities/session/adapters/rail-12306.js +285 -0
  17. package/dist/capabilities/session/extension-bridge.js +14 -1
  18. package/dist/capabilities/session/extension-channel.js +4 -2
  19. package/dist/capabilities/session/extension-distribution.js +1 -1
  20. package/dist/capabilities/session-search.js +311 -0
  21. package/dist/capabilities/visa-policy.js +126 -0
  22. package/dist/scripts/agent-planning-turn-deadline-e2e.js +304 -0
  23. package/dist/scripts/agent-planning-turn-deadline-tests.js +281 -0
  24. package/dist/scripts/benchmark-environment-bridge-e2e.js +5 -10
  25. package/dist/scripts/benchmark-environment-bridge-tests.js +148 -142
  26. package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +26 -26
  27. package/dist/scripts/{booking-copilot-availability-policy-v2-tests.js → booking-copilot-availability-policy-tests.js} +115 -115
  28. package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +41 -1
  29. package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +75 -120
  30. package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +370 -61
  31. package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +2 -2
  32. package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +7 -3
  33. package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +15 -9
  34. package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +19 -11
  35. package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +16 -52
  36. package/dist/scripts/booking-copilot-runtime-proof-tests.js +3953 -155
  37. package/dist/scripts/booking-copilot-server-proof-tests.js +58 -23
  38. package/dist/scripts/booking-copilot-startup-proof-tests.js +10 -119
  39. package/dist/scripts/booking-surface-contract-proof-tests.js +1154 -326
  40. package/dist/scripts/bootstrap-tests.js +87 -2
  41. package/dist/scripts/build-metrics-report.js +339 -0
  42. package/dist/scripts/channel-probe-tests.js +148 -0
  43. package/dist/scripts/channel-probe.js +252 -0
  44. package/dist/scripts/channel-registry-tests.js +262 -0
  45. package/dist/scripts/doctor-tests.js +121 -0
  46. package/dist/scripts/effect-tests.js +274 -1
  47. package/dist/scripts/extension-tests.js +129 -11
  48. package/dist/scripts/fact-gate-tests.js +91 -2
  49. package/dist/scripts/flyai-tests.js +17 -1
  50. package/dist/scripts/hbcli-e2e-tests.js +1 -3
  51. package/dist/scripts/metrics-report-tests.js +288 -0
  52. package/dist/scripts/persona-surface-guard-tests.js +19 -0
  53. package/dist/scripts/session-tests.js +401 -1
  54. package/dist/scripts/smoke.js +100 -83
  55. package/dist/scripts/turn-handoff-collect-tests.js +216 -0
  56. package/dist/scripts/turn-handoff-collect.js +189 -0
  57. package/dist/scripts/turn-policy-tests.js +56 -0
  58. package/dist/scripts/typed-contract-canary.js +261 -0
  59. package/dist/scripts/visa-policy-tests.js +75 -0
  60. package/dist/scripts/wish-channel-gate-tests.js +111 -0
  61. package/dist/src/artifact-gate.js +91 -3
  62. package/dist/src/benchmark-agent-conformance.js +7 -4
  63. package/dist/src/benchmark-environment-bridge.js +68 -7
  64. package/dist/src/bookable-facts.js +62 -3
  65. package/dist/src/booking-surface/{availability-policy-v2.js → availability-policy.js} +89 -89
  66. package/dist/src/booking-surface/canonical-schema.js +8 -22
  67. package/dist/src/booking-surface/contracts.js +70 -19
  68. package/dist/src/booking-surface/dsh-planner.js +310 -177
  69. package/dist/src/booking-surface/dsh-plugin.js +3 -3
  70. package/dist/src/booking-surface/index.js +1 -5
  71. package/dist/src/booking-surface/profile.js +1 -1
  72. package/dist/src/booking-surface/runtime.js +1682 -247
  73. package/dist/src/booking-surface/server.js +371 -185
  74. package/dist/src/booking-surface/startup.js +17 -27
  75. package/dist/src/booking-surface/validation.js +270 -760
  76. package/dist/src/index.js +735 -149
  77. package/dist/src/turn-deadline.js +292 -0
  78. package/dist/src/turn-policy.js +146 -0
  79. package/dist/src/wish-pool.js +5 -0
  80. package/extension/background.js +23 -4
  81. package/extension/content-main.js +47 -9
  82. package/extension/manifest.json +27 -9
  83. package/package.json +6 -26
  84. package/schemas/booking.surface.schema.json +2593 -0
  85. package/ts/capabilities/agent-reach.ts +4 -4
  86. package/ts/capabilities/flyai.ts +21 -3
  87. package/ts/capabilities/session/action-cache.ts +1 -1
  88. package/ts/capabilities/session/adapters/ctrip-hotel.ts +238 -0
  89. package/ts/capabilities/session/adapters/rail-12306.ts +293 -0
  90. package/ts/capabilities/session/extension-bridge.ts +32 -2
  91. package/ts/capabilities/session/extension-channel.ts +9 -8
  92. package/ts/capabilities/session/extension-distribution.ts +3 -1
  93. package/ts/capabilities/session/health-watch.ts +1 -1
  94. package/ts/capabilities/session/read-guard.ts +1 -1
  95. package/ts/capabilities/session/wizard.ts +1 -1
  96. package/ts/capabilities/session-search.ts +323 -1
  97. package/ts/package.json +1 -0
  98. package/ts/scripts/turn-handoff-collect.ts +178 -0
  99. package/ts/src/artifact-gate.ts +82 -2
  100. package/ts/src/benchmark-agent-conformance.ts +14 -6
  101. package/ts/src/benchmark-environment-bridge.ts +29 -10
  102. package/ts/src/bookable-facts.ts +109 -5
  103. package/ts/src/booking-saga.ts +1 -1
  104. package/ts/src/booking-surface/{availability-policy-v2.ts → availability-policy.ts} +124 -125
  105. package/ts/src/booking-surface/canonical-schema.js +8 -22
  106. package/ts/src/booking-surface/contracts.ts +278 -239
  107. package/ts/src/booking-surface/dsh-planner.ts +333 -194
  108. package/ts/src/booking-surface/dsh-plugin.js +3 -3
  109. package/ts/src/booking-surface/index.ts +1 -5
  110. package/ts/src/booking-surface/profile.ts +11 -11
  111. package/ts/src/booking-surface/runtime.ts +1351 -351
  112. package/ts/src/booking-surface/server.ts +282 -175
  113. package/ts/src/booking-surface/startup.ts +36 -48
  114. package/ts/src/booking-surface/validation.ts +194 -442
  115. package/ts/src/contracts.ts +1 -1
  116. package/ts/src/index.ts +489 -171
  117. package/ts/src/loop.ts +1 -1
  118. package/ts/src/state-ledger.ts +1 -1
  119. package/ts/src/turn-deadline.ts +361 -0
  120. package/ts/src/turn-policy.ts +154 -0
  121. package/ts/src/wish-pool.ts +17 -4
  122. package/dist/scripts/agent-planning-budget-e2e.js +0 -227
  123. package/dist/scripts/agent-planning-budget-tests.js +0 -173
  124. package/dist/scripts/booking-copilot-v2-runtime-proof-tests.js +0 -3935
  125. package/dist/scripts/booking-surface-v2-contract-proof-tests.js +0 -1174
  126. package/dist/src/booking-surface/contracts-v2.js +0 -89
  127. package/dist/src/booking-surface/runtime-v2.js +0 -1771
  128. package/dist/src/booking-surface/server-v2.js +0 -334
  129. package/dist/src/booking-surface/validation-v2.js +0 -319
  130. package/dist/src/tool-budget.js +0 -136
  131. package/schemas/booking.surface.v1.schema.json +0 -927
  132. package/schemas/booking.surface.v2.schema.json +0 -61
  133. package/ts/src/booking-surface/contracts-v2.ts +0 -118
  134. package/ts/src/booking-surface/runtime-v2.ts +0 -1466
  135. package/ts/src/booking-surface/server-v2.ts +0 -247
  136. package/ts/src/booking-surface/validation-v2.ts +0 -205
  137. package/ts/src/tool-budget.ts +0 -165
@@ -7,53 +7,46 @@ import { ensureLedger, type StateLedger } from '../state-ledger.ts'
7
7
  import {
8
8
  buildDshPlannerEnvironment,
9
9
  createDshEmbeddedBookingPlanner,
10
- createDshEmbeddedBookingPlannerV2,
11
- type DshEmbeddedBookingPlannerHandleV1,
12
- type DshEmbeddedBookingPlannerHandleV2,
13
- type DshEmbeddedBookingPlannerOptionsV1,
10
+ type DshEmbeddedBookingPlannerHandle,
11
+ type DshEmbeddedBookingPlannerOptions,
14
12
  } from './dsh-planner.ts'
15
13
  import { BookingCopilotTaskRuntime } from './runtime.ts'
16
- import { BookingCopilotTaskRuntimeV2 } from './runtime-v2.ts'
17
- import { BOOKING_COPILOT_V2_INGRESS_MODES, type BookingCopilotV2IngressMode, type BookingIngressBindingV2, type BookingIngressPrincipalV2 } from './contracts-v2.ts'
14
+ import { BOOKING_COPILOT_INGRESS_MODES, type BookingCopilotIngressMode, type BookingIngressBinding, type BookingIngressPrincipal } from './contracts.ts'
18
15
  import {
19
16
  startBookingCopilotServer,
20
- type BookingCopilotServerHandleV1,
21
- type BookingCopilotServerOptionsV1,
17
+ type BookingCopilotServerHandle,
18
+ type BookingCopilotServerOptions,
22
19
  } from './server.ts'
23
20
 
24
- export interface BookingCopilotStartupConfigV1 {
21
+ export interface BookingCopilotStartupConfig {
25
22
  apiKey: string
26
23
  stateRoot: string
27
24
  host: string
28
25
  port: number
29
26
  artifactId?: string
30
27
  /** Defaults to bound-turn-only; a complete injected seam enables ingress. */
31
- ingressMode: BookingCopilotV2IngressMode
28
+ ingressMode: BookingCopilotIngressMode
32
29
  }
33
30
 
34
- export interface BookingCopilotStartupHandleV1 {
31
+ export interface BookingCopilotStartupHandle {
35
32
  port: number
36
33
  close(): Promise<void>
37
34
  }
38
35
 
39
- export interface BookingCopilotStartupDependenciesV1 {
36
+ export interface BookingCopilotStartupDependencies {
40
37
  ensureLedger(stateRoot: string): StateLedger
41
38
  runtimeFactory(ledger: StateLedger): BookingCopilotTaskRuntime
42
- createPlanner(options: DshEmbeddedBookingPlannerOptionsV1): Promise<DshEmbeddedBookingPlannerHandleV1>
43
- runtimeFactoryV2?: (ledger: StateLedger) => BookingCopilotTaskRuntimeV2
44
- createPlannerV2?: (options: DshEmbeddedBookingPlannerOptionsV1) => Promise<DshEmbeddedBookingPlannerHandleV2>
45
- /** Optional in-process BFF identity seam; standalone v2 uses bound-turn-only mode. */
46
- ingressBinding?: BookingIngressBindingV2
47
- principal?: BookingIngressPrincipalV2
48
- startServer(options: BookingCopilotServerOptionsV1): Promise<BookingCopilotServerHandleV1>
39
+ createPlanner(options: DshEmbeddedBookingPlannerOptions): Promise<DshEmbeddedBookingPlannerHandle>
40
+ /** Optional in-process BFF identity seam; standalone use is bound-turn-only. */
41
+ ingressBinding?: BookingIngressBinding
42
+ principal?: BookingIngressPrincipal
43
+ startServer(options: BookingCopilotServerOptions): Promise<BookingCopilotServerHandle>
49
44
  }
50
45
 
51
- const DEFAULT_DEPENDENCIES: BookingCopilotStartupDependenciesV1 = {
46
+ const DEFAULT_DEPENDENCIES: BookingCopilotStartupDependencies = {
52
47
  ensureLedger,
53
48
  runtimeFactory: (ledger) => new BookingCopilotTaskRuntime(ledger),
54
49
  createPlanner: createDshEmbeddedBookingPlanner,
55
- runtimeFactoryV2: (ledger) => new BookingCopilotTaskRuntimeV2(ledger),
56
- createPlannerV2: createDshEmbeddedBookingPlannerV2,
57
50
  startServer: startBookingCopilotServer,
58
51
  }
59
52
 
@@ -66,7 +59,7 @@ function parsePort(raw: string | undefined): number {
66
59
 
67
60
  export function resolveBookingCopilotStartupConfig(
68
61
  env: Record<string, string | undefined> = process.env,
69
- ): BookingCopilotStartupConfigV1 {
62
+ ): BookingCopilotStartupConfig {
70
63
  const apiKey = env.GOTRY_BOOKING_COPILOT_API_KEY ?? ''
71
64
  if (!apiKey) throw new Error('booking_copilot_api_key_required')
72
65
  const stateRoot = env.GOTRY_BOOKING_COPILOT_STATE_ROOT ?? ''
@@ -76,10 +69,10 @@ export function resolveBookingCopilotStartupConfig(
76
69
  if (artifactId !== undefined && !/^[0-9a-f]{40}$/.test(artifactId)) {
77
70
  throw new Error('booking_copilot_artifact_id_invalid')
78
71
  }
79
- const rawIngressMode = env.GOTRY_BOOKING_COPILOT_V2_INGRESS_MODE
72
+ const rawIngressMode = env.GOTRY_BOOKING_COPILOT_INGRESS_MODE
80
73
  const ingressMode = rawIngressMode === undefined || rawIngressMode === '' ? 'bff-bound-turn-only' : rawIngressMode
81
- if (!(BOOKING_COPILOT_V2_INGRESS_MODES as readonly string[]).includes(ingressMode)) {
82
- throw new Error('booking_copilot_v2_ingress_mode_invalid')
74
+ if (!(BOOKING_COPILOT_INGRESS_MODES as readonly string[]).includes(ingressMode)) {
75
+ throw new Error('booking_copilot_ingress_mode_invalid')
83
76
  }
84
77
  return {
85
78
  apiKey,
@@ -87,21 +80,19 @@ export function resolveBookingCopilotStartupConfig(
87
80
  host: env.GOTRY_BOOKING_COPILOT_HOST || '127.0.0.1',
88
81
  port: parsePort(env.GOTRY_BOOKING_COPILOT_PORT),
89
82
  artifactId,
90
- ingressMode: ingressMode as BookingCopilotV2IngressMode,
83
+ ingressMode: ingressMode as BookingCopilotIngressMode,
91
84
  }
92
85
  }
93
86
 
94
87
  async function closeAll(
95
- server: BookingCopilotServerHandleV1 | undefined,
96
- planner: DshEmbeddedBookingPlannerHandleV1 | DshEmbeddedBookingPlannerHandleV2 | undefined,
97
- plannerV2: DshEmbeddedBookingPlannerHandleV2 | undefined,
88
+ server: BookingCopilotServerHandle | undefined,
89
+ planner: DshEmbeddedBookingPlannerHandle | undefined,
98
90
  ledger: StateLedger | undefined,
99
91
  ): Promise<void> {
100
92
  const failures: unknown[] = []
101
93
  for (const close of [
102
94
  server ? () => server.close() : undefined,
103
95
  planner ? () => planner.close() : undefined,
104
- plannerV2 ? () => plannerV2.close() : undefined,
105
96
  ledger ? () => Promise.resolve(ledger.close()) : undefined,
106
97
  ]) {
107
98
  if (!close) continue
@@ -117,44 +108,41 @@ async function closeAll(
117
108
  */
118
109
  export async function startBookingCopilotFromEnvironment(
119
110
  env: Record<string, string | undefined> = process.env,
120
- dependencies: BookingCopilotStartupDependenciesV1 = DEFAULT_DEPENDENCIES,
121
- ): Promise<BookingCopilotStartupHandleV1> {
111
+ dependencies: BookingCopilotStartupDependencies = DEFAULT_DEPENDENCIES,
112
+ ): Promise<BookingCopilotStartupHandle> {
122
113
  const config = resolveBookingCopilotStartupConfig(env)
123
114
  const activeDependencies = dependencies
124
115
  const hasIngressBinding = Boolean(activeDependencies.ingressBinding)
125
116
  const hasPrincipal = Boolean(activeDependencies.principal)
126
- if (hasIngressBinding !== hasPrincipal) throw new Error('booking_copilot_v2_ingress_binding_pair_required')
117
+ if (hasIngressBinding !== hasPrincipal) throw new Error('booking_copilot_ingress_binding_pair_required')
127
118
  const ingressPair = hasIngressBinding && hasPrincipal
128
- if (ingressPair && env.GOTRY_BOOKING_COPILOT_V2_INGRESS_MODE !== undefined && config.ingressMode === 'bff-bound-turn-only') {
129
- throw new Error('booking_copilot_v2_ingress_mode_conflict')
119
+ if (ingressPair && env.GOTRY_BOOKING_COPILOT_INGRESS_MODE !== undefined && config.ingressMode === 'bff-bound-turn-only') {
120
+ throw new Error('booking_copilot_ingress_mode_conflict')
130
121
  }
131
- if (!ingressPair && config.ingressMode === 'bff-ingress-binding') throw new Error('booking_copilot_v2_ingress_binding_required')
122
+ if (!ingressPair && config.ingressMode === 'bff-ingress-binding') throw new Error('booking_copilot_ingress_binding_required')
132
123
  if (ingressPair && (typeof activeDependencies.ingressBinding?.bind !== 'function'
133
124
  || typeof activeDependencies.principal?.subject !== 'string' || activeDependencies.principal.subject.length === 0 || activeDependencies.principal.subject.length > 256
134
125
  || typeof activeDependencies.principal?.scope !== 'string' || activeDependencies.principal.scope.length === 0 || activeDependencies.principal.scope.length > 256)) {
135
- throw new Error('booking_copilot_v2_ingress_binding_invalid')
126
+ throw new Error('booking_copilot_ingress_binding_invalid')
136
127
  }
137
- const activeIngressMode: BookingCopilotV2IngressMode = ingressPair ? 'bff-ingress-binding' : 'bff-bound-turn-only'
128
+ const activeIngressMode: BookingCopilotIngressMode = ingressPair ? 'bff-ingress-binding' : 'bff-bound-turn-only'
138
129
  mkdirSync(config.stateRoot, { recursive: true })
139
130
  let ledger: StateLedger | undefined
140
- let planner: DshEmbeddedBookingPlannerHandleV1 | undefined
141
- let plannerV2: DshEmbeddedBookingPlannerHandleV2 | undefined
142
- let server: BookingCopilotServerHandleV1 | undefined
131
+ let planner: DshEmbeddedBookingPlannerHandle | undefined
132
+ let server: BookingCopilotServerHandle | undefined
143
133
  try {
144
134
  ledger = dependencies.ensureLedger(config.stateRoot)
145
135
  const plannerOptions = { stateRoot: config.stateRoot, env: buildDshPlannerEnvironment(env) }
146
- if (!activeDependencies.runtimeFactoryV2 || !activeDependencies.createPlannerV2) throw new Error('booking_copilot_v2_startup_dependency_missing')
147
136
  const runtime = activeDependencies.runtimeFactory(ledger)
148
137
  planner = await activeDependencies.createPlanner(plannerOptions)
149
- const runtimeV2 = activeDependencies.runtimeFactoryV2(ledger)
150
- plannerV2 = await activeDependencies.createPlannerV2(plannerOptions)
151
138
  server = await activeDependencies.startServer({
152
139
  apiKey: config.apiKey, runtime, plannerFactory: planner.plannerFactory,
153
- v2: { runtime: runtimeV2, plannerFactory: plannerV2.plannerFactory, ingressBinding: activeDependencies.ingressBinding, principal: activeDependencies.principal, ingressMode: activeIngressMode },
140
+ ...(ingressPair ? { ingressBinding: activeDependencies.ingressBinding, principal: activeDependencies.principal } : {}),
141
+ ingressMode: activeIngressMode,
154
142
  host: config.host, port: config.port, artifactId: config.artifactId,
155
143
  })
156
144
  } catch (error) {
157
- try { await closeAll(server, planner, plannerV2, ledger) } catch (cleanupError) {
145
+ try { await closeAll(server, planner, ledger) } catch (cleanupError) {
158
146
  throw new AggregateError([error, cleanupError], 'booking_copilot_startup_and_cleanup_failed')
159
147
  }
160
148
  throw error
@@ -166,7 +154,7 @@ export async function startBookingCopilotFromEnvironment(
166
154
  async close() {
167
155
  if (closed) return
168
156
  closed = true
169
- await closeAll(server, planner, plannerV2, ledger)
157
+ await closeAll(server, planner, ledger)
170
158
  },
171
159
  }
172
160
  }