@fungi.computer/bird-dog 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.
package/dist/effect.d.ts CHANGED
@@ -16,6 +16,11 @@ export declare const BirdDogAgentRecipientReferenceSchema: Schema.Struct<{
16
16
  readonly agentId: Schema.String;
17
17
  readonly sessionId: Schema.optionalKey<Schema.String>;
18
18
  }>;
19
+ /** The Hub's stable system identity for a terminal offline disposition. */
20
+ export declare const BirdDogSystemIdentitySchema: Schema.Struct<{
21
+ readonly kind: Schema.Literal<"system">;
22
+ readonly systemId: Schema.Literal<"hub">;
23
+ }>;
19
24
  /** The most characters a reply's failure diagnostic may carry. */
20
25
  export declare const BIRD_DOG_DIAGNOSTIC_MAX_LENGTH = 200;
21
26
  /**
@@ -69,12 +74,12 @@ export declare const BirdDogMailSchema: Schema.Union<readonly [Schema.Struct<{
69
74
  readonly commandId: Schema.String;
70
75
  readonly outcome: Schema.Literals<readonly ["completed", "failed", "interrupted", "cancelled", "outcome_unknown"]>;
71
76
  readonly diagnostic: Schema.optionalKey<Schema.String>;
72
- }>, Schema.Struct<{
73
- readonly outcome: Schema.Literal<"undeliverable">;
74
- readonly reason: Schema.Literals<readonly ["recipient_offline", "recipient_left"]>;
75
77
  }>, Schema.Struct<{
76
78
  readonly outcome: Schema.Literal<"accepted">;
77
79
  readonly commandId: Schema.String;
80
+ }>, Schema.Struct<{
81
+ readonly outcome: Schema.Literal<"undeliverable">;
82
+ readonly reason: Schema.Literal<"recipient_left">;
78
83
  }>]>>;
79
84
  readonly key: Schema.String;
80
85
  readonly to: Schema.Struct<{
@@ -92,14 +97,13 @@ export declare const BirdDogMailSchema: Schema.Union<readonly [Schema.Struct<{
92
97
  readonly meta: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
93
98
  }>, Schema.Struct<{
94
99
  readonly from: Schema.Struct<{
95
- readonly kind: Schema.Literal<"agent">;
96
- readonly agentId: Schema.String;
97
- readonly sessionId: Schema.optionalKey<Schema.String>;
100
+ readonly kind: Schema.Literal<"system">;
101
+ readonly systemId: Schema.Literal<"hub">;
98
102
  }>;
99
- /** An unstarted recipient can only author an undeliverable reply. */
103
+ /** Only the Hub may author this offline disposition. */
100
104
  readonly reply: Schema.Struct<{
101
105
  readonly outcome: Schema.Literal<"undeliverable">;
102
- readonly reason: Schema.Literals<readonly ["recipient_offline", "recipient_left"]>;
106
+ readonly reason: Schema.Literal<"recipient_offline">;
103
107
  }>;
104
108
  readonly key: Schema.String;
105
109
  readonly to: Schema.Struct<{
@@ -142,12 +146,12 @@ export declare const BirdDogAgentJobPayloadSchema: Schema.Struct<{
142
146
  readonly commandId: Schema.String;
143
147
  readonly outcome: Schema.Literals<readonly ["completed", "failed", "interrupted", "cancelled", "outcome_unknown"]>;
144
148
  readonly diagnostic: Schema.optionalKey<Schema.String>;
145
- }>, Schema.Struct<{
146
- readonly outcome: Schema.Literal<"undeliverable">;
147
- readonly reason: Schema.Literals<readonly ["recipient_offline", "recipient_left"]>;
148
149
  }>, Schema.Struct<{
149
150
  readonly outcome: Schema.Literal<"accepted">;
150
151
  readonly commandId: Schema.String;
152
+ }>, Schema.Struct<{
153
+ readonly outcome: Schema.Literal<"undeliverable">;
154
+ readonly reason: Schema.Literal<"recipient_left">;
151
155
  }>]>>;
152
156
  readonly key: Schema.String;
153
157
  readonly to: Schema.Struct<{
@@ -165,14 +169,13 @@ export declare const BirdDogAgentJobPayloadSchema: Schema.Struct<{
165
169
  readonly meta: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
166
170
  }>, Schema.Struct<{
167
171
  readonly from: Schema.Struct<{
168
- readonly kind: Schema.Literal<"agent">;
169
- readonly agentId: Schema.String;
170
- readonly sessionId: Schema.optionalKey<Schema.String>;
172
+ readonly kind: Schema.Literal<"system">;
173
+ readonly systemId: Schema.Literal<"hub">;
171
174
  }>;
172
- /** An unstarted recipient can only author an undeliverable reply. */
175
+ /** Only the Hub may author this offline disposition. */
173
176
  readonly reply: Schema.Struct<{
174
177
  readonly outcome: Schema.Literal<"undeliverable">;
175
- readonly reason: Schema.Literals<readonly ["recipient_offline", "recipient_left"]>;
178
+ readonly reason: Schema.Literal<"recipient_offline">;
176
179
  }>;
177
180
  readonly key: Schema.String;
178
181
  readonly to: Schema.Struct<{
@@ -211,12 +214,12 @@ export declare const BirdDogAgentJobInputSchema: Schema.Struct<{
211
214
  readonly commandId: Schema.String;
212
215
  readonly outcome: Schema.Literals<readonly ["completed", "failed", "interrupted", "cancelled", "outcome_unknown"]>;
213
216
  readonly diagnostic: Schema.optionalKey<Schema.String>;
214
- }>, Schema.Struct<{
215
- readonly outcome: Schema.Literal<"undeliverable">;
216
- readonly reason: Schema.Literals<readonly ["recipient_offline", "recipient_left"]>;
217
217
  }>, Schema.Struct<{
218
218
  readonly outcome: Schema.Literal<"accepted">;
219
219
  readonly commandId: Schema.String;
220
+ }>, Schema.Struct<{
221
+ readonly outcome: Schema.Literal<"undeliverable">;
222
+ readonly reason: Schema.Literal<"recipient_left">;
220
223
  }>]>>;
221
224
  readonly key: Schema.String;
222
225
  readonly to: Schema.Struct<{
@@ -234,14 +237,13 @@ export declare const BirdDogAgentJobInputSchema: Schema.Struct<{
234
237
  readonly meta: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
235
238
  }>, Schema.Struct<{
236
239
  readonly from: Schema.Struct<{
237
- readonly kind: Schema.Literal<"agent">;
238
- readonly agentId: Schema.String;
239
- readonly sessionId: Schema.optionalKey<Schema.String>;
240
+ readonly kind: Schema.Literal<"system">;
241
+ readonly systemId: Schema.Literal<"hub">;
240
242
  }>;
241
- /** An unstarted recipient can only author an undeliverable reply. */
243
+ /** Only the Hub may author this offline disposition. */
242
244
  readonly reply: Schema.Struct<{
243
245
  readonly outcome: Schema.Literal<"undeliverable">;
244
- readonly reason: Schema.Literals<readonly ["recipient_offline", "recipient_left"]>;
246
+ readonly reason: Schema.Literal<"recipient_offline">;
245
247
  }>;
246
248
  readonly key: Schema.String;
247
249
  readonly to: Schema.Struct<{
package/dist/effect.js CHANGED
@@ -20,6 +20,11 @@ export const BirdDogAgentRecipientReferenceSchema = Schema.Struct({
20
20
  agentId: Identifier,
21
21
  sessionId: Schema.optionalKey(Identifier),
22
22
  });
23
+ /** The Hub's stable system identity for a terminal offline disposition. */
24
+ export const BirdDogSystemIdentitySchema = Schema.Struct({
25
+ kind: Schema.Literal("system"),
26
+ systemId: Schema.Literal("hub"),
27
+ });
23
28
  /** The most characters a reply's failure diagnostic may carry. */
24
29
  export const BIRD_DOG_DIAGNOSTIC_MAX_LENGTH = 200;
25
30
  /**
@@ -57,6 +62,14 @@ export const BirdDogReplySchema = Schema.Union([
57
62
  UndeliverableBirdDogReplySchema,
58
63
  AcceptedBirdDogReplySchema,
59
64
  ]);
65
+ const BirdDogAgentReplySchema = Schema.Union([
66
+ SettledBirdDogReplySchema,
67
+ AcceptedBirdDogReplySchema,
68
+ Schema.Struct({
69
+ outcome: Schema.Literal("undeliverable"),
70
+ reason: Schema.Literal("recipient_left"),
71
+ }),
72
+ ]);
60
73
  const REDACTED = "[redacted]";
61
74
  // An authorization scheme's credential, e.g. `Bearer <token>`.
62
75
  const schemeCredential = /\b(bearer|basic)\s+[^\s"',;]+/giu;
@@ -98,13 +111,16 @@ export const BirdDogMailSchema = Schema.Union([
98
111
  ...BirdDogMailFields,
99
112
  from: BirdDogAgentReferenceSchema,
100
113
  /** Settlement or acceptance facts, present only on a reply. */
101
- reply: Schema.optionalKey(BirdDogReplySchema),
114
+ reply: Schema.optionalKey(BirdDogAgentReplySchema),
102
115
  }),
103
116
  Schema.Struct({
104
117
  ...BirdDogMailFields,
105
- from: BirdDogAgentRecipientReferenceSchema,
106
- /** An unstarted recipient can only author an undeliverable reply. */
107
- reply: UndeliverableBirdDogReplySchema,
118
+ from: BirdDogSystemIdentitySchema,
119
+ /** Only the Hub may author this offline disposition. */
120
+ reply: Schema.Struct({
121
+ outcome: Schema.Literal("undeliverable"),
122
+ reason: Schema.Literal("recipient_offline"),
123
+ }),
108
124
  }),
109
125
  ]);
110
126
  /** Parser for accepted Session work. */
@@ -177,7 +193,7 @@ export function settlementReplies(settlement, createdAt) {
177
193
  settlement.diagnostic === undefined
178
194
  ? undefined
179
195
  : boundedDiagnostic(settlement.diagnostic);
180
- const reply = Schema.decodeUnknownSync(BirdDogReplySchema)(diagnostic === undefined
196
+ const reply = Schema.decodeUnknownSync(SettledBirdDogReplySchema)(diagnostic === undefined
181
197
  ? { commandId: work.commandFactId, outcome }
182
198
  : { commandId: work.commandFactId, outcome, diagnostic });
183
199
  return mail.replyTo.map((destination, index) => ({
package/dist/index.d.ts CHANGED
@@ -12,6 +12,11 @@ export type BirdDogAgentRecipientReference = Readonly<{
12
12
  agentId: string;
13
13
  sessionId?: string;
14
14
  }>;
15
+ /** The Hub's stable system identity for a terminal offline disposition. */
16
+ export type BirdDogSystemIdentity = Readonly<{
17
+ kind: "system";
18
+ systemId: "hub";
19
+ }>;
15
20
  /**
16
21
  * What a reply reports about the settled work beside its content. The
17
22
  * recipient's host trusts these facts only after it authenticates the reply
@@ -32,7 +37,17 @@ export type BirdDogReply = Readonly<{
32
37
  outcome: "undeliverable";
33
38
  reason: "recipient_offline" | "recipient_left";
34
39
  }>;
35
- /** Addressed mail; an unstarted Agent may author only an undeliverable reply. */
40
+ /** Facts an Agent may author; the Hub owns recipient-offline disposition. */
41
+ export type BirdDogAgentReply = Exclude<BirdDogReply, {
42
+ outcome: "undeliverable";
43
+ }> | Readonly<{
44
+ outcome: "undeliverable";
45
+ reason: "recipient_left";
46
+ }>;
47
+ /**
48
+ * Addressed correspondence. Agents author ordinary replies and recipient-left
49
+ * notices; only the Hub system authors recipient-offline dispositions.
50
+ */
36
51
  export type BirdDogMail = Readonly<{
37
52
  key: string;
38
53
  to: BirdDogAgentRecipientReference;
@@ -43,7 +58,7 @@ export type BirdDogMail = Readonly<{
43
58
  meta?: BirdDogMeta;
44
59
  from: BirdDogAgentReference;
45
60
  /** Settlement or acceptance facts, present only on a reply. */
46
- reply?: BirdDogReply;
61
+ reply?: BirdDogAgentReply;
47
62
  }> | Readonly<{
48
63
  key: string;
49
64
  to: BirdDogAgentRecipientReference;
@@ -52,12 +67,15 @@ export type BirdDogMail = Readonly<{
52
67
  createdAt: number;
53
68
  /** The sender's opaque host metadata; BirdDog never reads it. */
54
69
  meta?: BirdDogMeta;
55
- /** No Session exists when a never-started recipient is undeliverable. */
56
- from: BirdDogAgentRecipientReference;
57
- reply: Extract<BirdDogReply, {
70
+ /** The Hub owns offline disposition authorship, not the recipient. */
71
+ from: BirdDogSystemIdentity;
72
+ reply: Readonly<{
58
73
  outcome: "undeliverable";
74
+ reason: "recipient_offline";
59
75
  }>;
60
76
  }>;
77
+ /** Construct the one stable system reply correlated to the exact sent letter. */
78
+ export declare function undeliverableReply(original: BirdDogMail, createdAt: number): BirdDogMail;
61
79
  /** Opaque JSON a host attached to the work; BirdDog only carries it. */
62
80
  export type BirdDogMeta = typeof Schema.Json.Type;
63
81
  /** The accepted Session work BirdDog points at from an opaque Watchdog job. */
package/dist/index.js CHANGED
@@ -1,5 +1,19 @@
1
1
  import { agentJobFromInput, decodeAgentJob } from "./effect.js";
2
2
  import { createPromiseBirdDog } from "./internal/promise-mail-room.js";
3
+ /** Construct the one stable system reply correlated to the exact sent letter. */
4
+ export function undeliverableReply(original, createdAt) {
5
+ if (original.reply !== undefined || original.from.kind !== "agent")
6
+ throw new Error("A reply cannot receive another undeliverable disposition");
7
+ return {
8
+ key: `${original.key}:reply:0`,
9
+ from: { kind: "system", systemId: "hub" },
10
+ to: original.from,
11
+ replyTo: [],
12
+ content: "undeliverable",
13
+ createdAt,
14
+ reply: { outcome: "undeliverable", reason: "recipient_offline" },
15
+ };
16
+ }
3
17
  /** Agent-aware mail translation over Watchdog's payload-blind job grammar. */
4
18
  export const BirdDog = Object.freeze({
5
19
  agentJob: agentJobFromInput,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/bird-dog",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Durable addressed agent mail over generic Watchdog work",
6
6
  "type": "module",