@wowyuarm/dsh-agent-team 0.2.0 → 0.2.1

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 (67) hide show
  1. package/README.md +5 -5
  2. package/README.zh.md +5 -5
  3. package/cordis.patch.yml +26 -12
  4. package/package.json +50 -47
  5. package/packages/agent-team/lib/attachments.js +63 -4
  6. package/packages/agent-team/lib/compaction-engine.js +18 -0
  7. package/packages/agent-team/lib/context-continuity-host.js +198 -4
  8. package/packages/agent-team/lib/context-judge.js +150 -0
  9. package/packages/agent-team/lib/index.js +482 -97
  10. package/packages/agent-team/lib/invariant.js +36 -12
  11. package/packages/agent-team/lib/ledger.js +2 -1
  12. package/packages/agent-team/lib/member-runtime.js +2 -1
  13. package/packages/agent-team/lib/recovery.js +53 -4
  14. package/packages/agent-team/lib/typert.host.js +138 -44
  15. package/packages/agent-team/lib/typert.remote-client.d.ts +3 -1
  16. package/packages/agent-team/lib/typert.remote-client.d.ts.map +1 -1
  17. package/packages/agent-team/lib/typert.remote-client.js +75 -35
  18. package/packages/agent-team/lib/types/attachments.d.ts +32 -2
  19. package/packages/agent-team/lib/types/attachments.d.ts.map +1 -1
  20. package/packages/agent-team/lib/types/compaction-engine.d.ts +19 -0
  21. package/packages/agent-team/lib/types/compaction-engine.d.ts.map +1 -0
  22. package/packages/agent-team/lib/types/context-continuity-host.d.ts +131 -4
  23. package/packages/agent-team/lib/types/context-continuity-host.d.ts.map +1 -1
  24. package/packages/agent-team/lib/types/context-judge.d.ts +82 -0
  25. package/packages/agent-team/lib/types/context-judge.d.ts.map +1 -0
  26. package/packages/agent-team/lib/types/index.d.ts +259 -17
  27. package/packages/agent-team/lib/types/index.d.ts.map +1 -1
  28. package/packages/agent-team/lib/types/invariant.d.ts +27 -5
  29. package/packages/agent-team/lib/types/invariant.d.ts.map +1 -1
  30. package/packages/agent-team/lib/types/ledger.d.ts.map +1 -1
  31. package/packages/agent-team/lib/types/member-runtime.d.ts +1 -1
  32. package/packages/agent-team/lib/types/member-runtime.d.ts.map +1 -1
  33. package/packages/agent-team/lib/types/recovery.d.ts +19 -6
  34. package/packages/agent-team/lib/types/recovery.d.ts.map +1 -1
  35. package/packages/agent-team/lib/types/types/requests-results.d.ts +28 -2
  36. package/packages/agent-team/lib/types/types/requests-results.d.ts.map +1 -1
  37. package/packages/agent-team/lib/types/types.d.ts +9 -0
  38. package/packages/agent-team/lib/types/types.d.ts.map +1 -1
  39. package/packages/client-agent-team/lib/client.js +1006 -374
  40. package/packages/client-agent-team/lib/client.js.map +1 -1
  41. package/packages/client-agent-team/lib/types/client/{HumanSettingsSection.d.ts → TeamSettingsSection.d.ts} +12 -4
  42. package/packages/client-agent-team/lib/types/client/TeamSettingsSection.d.ts.map +1 -0
  43. package/packages/client-agent-team/lib/types/client/TeamSettingsSection.js +195 -0
  44. package/packages/client-agent-team/lib/types/client/attachment-preview.d.ts +7 -11
  45. package/packages/client-agent-team/lib/types/client/attachment-preview.d.ts.map +1 -1
  46. package/packages/client-agent-team/lib/types/client/attachment-preview.js +13 -3
  47. package/packages/client-agent-team/lib/types/client/context-judge.d.ts +64 -0
  48. package/packages/client-agent-team/lib/types/client/context-judge.d.ts.map +1 -0
  49. package/packages/client-agent-team/lib/types/client/context-judge.js +78 -0
  50. package/packages/client-agent-team/lib/types/client/index.d.ts.map +1 -1
  51. package/packages/client-agent-team/lib/types/client/index.js +75 -11
  52. package/packages/client-agent-team/lib/types/client/judge-form.d.ts +99 -0
  53. package/packages/client-agent-team/lib/types/client/judge-form.d.ts.map +1 -0
  54. package/packages/client-agent-team/lib/types/client/judge-form.js +208 -0
  55. package/packages/client-agent-team/lib/types/client/locales.d.ts +52 -6
  56. package/packages/client-agent-team/lib/types/client/locales.d.ts.map +1 -1
  57. package/packages/client-agent-team/lib/types/client/locales.js +55 -6
  58. package/packages/tool-agent-team/README.md +6 -3
  59. package/packages/tool-agent-team/README.zh.md +6 -3
  60. package/packages/tool-agent-team/lib/context-tools.js +84 -112
  61. package/packages/tool-agent-team/lib/types/context-tools.d.ts +29 -13
  62. package/packages/tool-agent-team/lib/types/context-tools.d.ts.map +1 -1
  63. package/packages/agent-team/lib/pressure-policy.js +0 -235
  64. package/packages/agent-team/lib/types/pressure-policy.d.ts +0 -134
  65. package/packages/agent-team/lib/types/pressure-policy.d.ts.map +0 -1
  66. package/packages/client-agent-team/lib/types/client/HumanSettingsSection.d.ts.map +0 -1
  67. package/packages/client-agent-team/lib/types/client/HumanSettingsSection.js +0 -118
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Team's relatedness judge: the long-gap gate's `jev` service, mounted by this
3
+ * bundle when a key resolves and left unmounted when none does.
4
+ *
5
+ * The key is the switch, so nothing here decides policy: a key in the Host
6
+ * row's `jev` config — or in the environment variable that config names —
7
+ * mounts the service, clearing it unmounts the service, and the gate asks
8
+ * whatever is mounted. A deployment that mounts its own `jev` row keeps
9
+ * working, because the judge is read as a service rather than as this mount.
10
+ *
11
+ * The mount also carries the one setting the two sides must agree on: jev's own
12
+ * call budget is derived from the gate's deadline, so a judge can never be
13
+ * configured to outlive the time the gate gives it — the mismatch that would
14
+ * otherwise leave every long-gap step ungated without a word.
15
+ * @module @wowyuarm/dsh-agent-team/context-judge
16
+ */
17
+ import { DEFAULT_API_KEY_ENV, Jev } from '@wowyuarm/dsh-jev';
18
+ /**
19
+ * The judge's call budget keeps this much of the gate's deadline for the hop
20
+ * back: the gate abandons a judgement that outlives its own deadline, so a
21
+ * judge allowed to use the whole deadline would always be abandoned first.
22
+ */
23
+ const JUDGE_DEADLINE_MARGIN_MS = 1_000;
24
+ /**
25
+ * Wait before the judge's second attempt. Pinned rather than inherited from the
26
+ * service's own default, because it is half of the same budget the deadline
27
+ * above sizes: a backoff longer than this would spend the gate's remaining time
28
+ * waiting instead of asking again.
29
+ */
30
+ const JUDGE_RETRY_DELAY_MS = 500;
31
+ /** The key a row states, or the one the named environment variable holds. */
32
+ function resolvedKey(config, envName) {
33
+ const stated = config?.apiKey;
34
+ if (stated !== undefined && stated !== '')
35
+ return stated;
36
+ const fromEnv = process.env[envName];
37
+ return fromEnv === undefined || fromEnv === '' ? undefined : fromEnv;
38
+ }
39
+ /**
40
+ * The config one mount runs with. Exported because it is the whole contract
41
+ * between the gate's deadline and the judge's own budget, and a pure function
42
+ * is what a test can hold still.
43
+ */
44
+ export function judgeMountConfig(config, key, envName, deadlineMs) {
45
+ return {
46
+ apiKey: key,
47
+ apiKeyEnv: envName,
48
+ ...(config?.model === undefined ? {} : { model: config.model }),
49
+ ...(config?.apiBase === undefined ? {} : { apiBase: config.apiBase }),
50
+ timeoutMs: Math.max(JUDGE_DEADLINE_MARGIN_MS, deadlineMs - JUDGE_DEADLINE_MARGIN_MS),
51
+ // Two attempts: this call sits on the path that starts a turn, so the
52
+ // budget stays small — but one transport blip should not cost the step its
53
+ // gate, which is what a single attempt did. The gate races the whole call
54
+ // against its deadline anyway, so a second attempt that cannot finish in
55
+ // time costs the turn nothing beyond what it already spent.
56
+ attempts: 2,
57
+ retryDelayMs: JUDGE_RETRY_DELAY_MS,
58
+ };
59
+ }
60
+ /**
61
+ * One Host's judge: the service it mounted, the failure that kept one from
62
+ * mounting, and the reconciliation that keeps the two in step with the row.
63
+ */
64
+ export class TeamContextJudge {
65
+ ctx;
66
+ options;
67
+ fiber;
68
+ failure;
69
+ /** The mount the live fiber runs with, so an unchanged row does not restart it. */
70
+ mounted;
71
+ constructor(ctx, options) {
72
+ this.ctx = ctx;
73
+ this.options = options;
74
+ }
75
+ /**
76
+ * The judge a step may ask, or undefined when the deployment has none: this
77
+ * bundle's own mount first, then a service another row mounted.
78
+ */
79
+ judge() {
80
+ return this.fiber?.ctx.get('jev') ?? this.ctx.get('jev');
81
+ }
82
+ /** The environment variable this deployment reads the key from. */
83
+ keyEnv() {
84
+ const name = this.options.config()?.apiKeyEnv;
85
+ return name === undefined || name === '' ? DEFAULT_API_KEY_ENV : name;
86
+ }
87
+ /** Whether a key is resolvable right now, from the row or from its environment. */
88
+ key() {
89
+ return resolvedKey(this.options.config(), this.keyEnv());
90
+ }
91
+ /**
92
+ * Make the mount match the row: mount when a key resolves and none is
93
+ * mounted, re-configure a live mount whose settings changed, unmount when the
94
+ * key is gone. Called at init and on every volatile update of the row, so a
95
+ * key written in the Team settings surface takes effect without a restart.
96
+ */
97
+ async sync() {
98
+ const config = this.options.config();
99
+ const key = this.key();
100
+ if (key === undefined) {
101
+ this.failure = undefined;
102
+ await this.unmount();
103
+ return;
104
+ }
105
+ const wanted = judgeMountConfig(config, key, this.keyEnv(), this.options.deadlineMs());
106
+ const signature = JSON.stringify(wanted);
107
+ if (this.fiber !== undefined && signature === this.mounted)
108
+ return;
109
+ if (this.fiber === undefined) {
110
+ this.fiber = this.ctx.plugin(Jev, wanted);
111
+ this.mounted = signature;
112
+ }
113
+ else {
114
+ this.mounted = signature;
115
+ // `update` re-activates the fiber with the new config, and clears a
116
+ // previous failure, so a corrected endpoint recovers without a restart.
117
+ this.fiber.update(wanted);
118
+ }
119
+ try {
120
+ await this.fiber.await();
121
+ this.failure = undefined;
122
+ }
123
+ catch (error) {
124
+ // A rejected key or endpoint is a configuration failure the settings
125
+ // surface reports: the row keeps what the Human wrote, and the status
126
+ // says why the judge is not answering.
127
+ this.failure = error instanceof Error ? error.message : String(error);
128
+ }
129
+ }
130
+ /** Drop this bundle's mount, if it has one. */
131
+ async unmount() {
132
+ const fiber = this.fiber;
133
+ this.fiber = undefined;
134
+ this.mounted = undefined;
135
+ if (fiber !== undefined)
136
+ await fiber.dispose();
137
+ }
138
+ /** What the Team settings surface states about the judge. */
139
+ status() {
140
+ const keyEnv = this.keyEnv();
141
+ if (this.judge() !== undefined)
142
+ return { enabled: true, keyEnv };
143
+ return {
144
+ enabled: false,
145
+ reason: this.key() === undefined ? 'no-key' : 'unavailable',
146
+ ...(this.failure === undefined ? {} : { detail: this.failure }),
147
+ keyEnv,
148
+ };
149
+ }
150
+ }