@abubakarsiddiik/server 0.0.0-stage → 0.2.0

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/LICENSE +202 -0
  2. package/README.md +187 -2
  3. package/dist/browsers.d.ts +19 -0
  4. package/dist/browsers.d.ts.map +1 -0
  5. package/dist/browsers.js +36 -0
  6. package/dist/browsers.js.map +1 -0
  7. package/dist/canary.d.ts +38 -0
  8. package/dist/canary.d.ts.map +1 -0
  9. package/dist/canary.js +87 -0
  10. package/dist/canary.js.map +1 -0
  11. package/dist/credentials.d.ts +44 -0
  12. package/dist/credentials.d.ts.map +1 -0
  13. package/dist/credentials.js +96 -0
  14. package/dist/credentials.js.map +1 -0
  15. package/dist/executor.d.ts +54 -0
  16. package/dist/executor.d.ts.map +1 -0
  17. package/dist/executor.js +108 -0
  18. package/dist/executor.js.map +1 -0
  19. package/dist/health.d.ts +28 -0
  20. package/dist/health.d.ts.map +1 -0
  21. package/dist/health.js +25 -0
  22. package/dist/health.js.map +1 -0
  23. package/dist/host.d.ts +16 -0
  24. package/dist/host.d.ts.map +1 -0
  25. package/dist/host.js +27 -0
  26. package/dist/host.js.map +1 -0
  27. package/dist/index.d.ts +14 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +14 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/log.d.ts +28 -0
  32. package/dist/log.d.ts.map +1 -0
  33. package/dist/log.js +56 -0
  34. package/dist/log.js.map +1 -0
  35. package/dist/maps.d.ts +24 -0
  36. package/dist/maps.d.ts.map +1 -0
  37. package/dist/maps.js +95 -0
  38. package/dist/maps.js.map +1 -0
  39. package/dist/mcp-stdio.d.ts +2 -0
  40. package/dist/mcp-stdio.d.ts.map +1 -0
  41. package/dist/mcp-stdio.js +13 -0
  42. package/dist/mcp-stdio.js.map +1 -0
  43. package/dist/mcp.d.ts +54 -0
  44. package/dist/mcp.d.ts.map +1 -0
  45. package/dist/mcp.js +708 -0
  46. package/dist/mcp.js.map +1 -0
  47. package/dist/server.d.ts +48 -0
  48. package/dist/server.d.ts.map +1 -0
  49. package/dist/server.js +214 -0
  50. package/dist/server.js.map +1 -0
  51. package/dist/start.d.ts +2 -0
  52. package/dist/start.d.ts.map +1 -0
  53. package/dist/start.js +40 -0
  54. package/dist/start.js.map +1 -0
  55. package/dist/stdio.d.ts +38 -0
  56. package/dist/stdio.d.ts.map +1 -0
  57. package/dist/stdio.js +36 -0
  58. package/dist/stdio.js.map +1 -0
  59. package/dist/store.d.ts +43 -0
  60. package/dist/store.d.ts.map +1 -0
  61. package/dist/store.js +258 -0
  62. package/dist/store.js.map +1 -0
  63. package/dist/write-ledger.d.ts +17 -0
  64. package/dist/write-ledger.d.ts.map +1 -0
  65. package/dist/write-ledger.js +42 -0
  66. package/dist/write-ledger.js.map +1 -0
  67. package/package.json +48 -3
@@ -0,0 +1,96 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ const execFileAsync = promisify(execFile);
4
+ /**
5
+ * Environment-backed credentials.
6
+ *
7
+ * The variable is derived from the site and key: `PORTOLAN_STORE_API_KEY`.
8
+ * A value for one site is never visible under another site's name.
9
+ */
10
+ export class EnvCredentialStore {
11
+ env;
12
+ constructor(env = process.env) {
13
+ this.env = env;
14
+ }
15
+ async get(site, key) {
16
+ const name = envName(site, key);
17
+ const value = this.env[name];
18
+ return value !== undefined && value.length > 0 ? value : undefined;
19
+ }
20
+ }
21
+ const defaultRun = async (command, args) => {
22
+ const { stdout } = await execFileAsync(command, args, { encoding: "utf8" });
23
+ return { stdout };
24
+ };
25
+ /**
26
+ * OS-keychain-backed credentials.
27
+ *
28
+ * macOS uses `security find-generic-password`; Linux uses `secret-tool lookup`.
29
+ * The service and account are namespaced with the site, so a keychain entry
30
+ * cannot be read under another site. A missing entry is `undefined`, not an
31
+ * error.
32
+ */
33
+ export class KeychainCredentialStore {
34
+ platform;
35
+ run;
36
+ constructor(options = {}) {
37
+ this.platform = options.platform ?? process.platform;
38
+ this.run = options.run ?? defaultRun;
39
+ }
40
+ async get(site, key) {
41
+ try {
42
+ if (this.platform === "darwin") {
43
+ const { stdout } = await this.run("security", [
44
+ "find-generic-password",
45
+ "-s",
46
+ `portolan:${site}:${key}`,
47
+ "-w",
48
+ ]);
49
+ return nonEmpty(stdout);
50
+ }
51
+ if (this.platform === "linux") {
52
+ const { stdout } = await this.run("secret-tool", [
53
+ "lookup",
54
+ "service",
55
+ "portolan",
56
+ "site",
57
+ site,
58
+ "key",
59
+ key,
60
+ ]);
61
+ return nonEmpty(stdout);
62
+ }
63
+ }
64
+ catch {
65
+ return undefined;
66
+ }
67
+ return undefined;
68
+ }
69
+ }
70
+ /** Env first, then the OS keychain. */
71
+ export class ChainCredentialStore {
72
+ stores;
73
+ constructor(stores) {
74
+ this.stores = stores;
75
+ }
76
+ async get(site, key) {
77
+ for (const store of this.stores) {
78
+ const value = await store.get(site, key);
79
+ if (value !== undefined)
80
+ return value;
81
+ }
82
+ return undefined;
83
+ }
84
+ }
85
+ export function createCredentialStore(env = process.env) {
86
+ return new ChainCredentialStore([new EnvCredentialStore(env), new KeychainCredentialStore()]);
87
+ }
88
+ function envName(site, key) {
89
+ const suffix = `${site}_${key}`.toUpperCase().replace(/[^A-Z0-9]+/g, "_");
90
+ return `PORTOLAN_${suffix}`;
91
+ }
92
+ function nonEmpty(value) {
93
+ const trimmed = value.trim();
94
+ return trimmed.length > 0 ? trimmed : undefined;
95
+ }
96
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAO1C;;;;;GAKG;AACH,MAAM,OAAO,k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AM,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa;IAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { OpDef, ResultEnvelope, SessionRecord, SiteMap } from "@abubakarsiddiik/protocol";
2
+ import type { Substrate } from "@abubakarsiddiik/substrate";
3
+ export type OpAudit = {
4
+ tier?: "webmcp" | "url" | "http" | "ui";
5
+ beforeState?: string;
6
+ afterState?: string;
7
+ requests?: Array<{
8
+ method: string;
9
+ url: string;
10
+ status?: number;
11
+ }>;
12
+ };
13
+ export type OpExecutorInput = {
14
+ session: SessionRecord;
15
+ map: SiteMap;
16
+ op: OpDef;
17
+ params: Record<string, unknown>;
18
+ confirm?: boolean;
19
+ idempotencyKey?: string;
20
+ /** The live substrate. Absent when the server has no browser factory. */
21
+ substrate?: Substrate;
22
+ /** Override the map's first origin, e.g. a fixture on an ephemeral port. */
23
+ baseUrl?: string;
24
+ /** Optional: report how the op ran, for the audit log. */
25
+ audit?: (info: OpAudit) => void;
26
+ };
27
+ /**
28
+ * The op runtime behind the MCP surface.
29
+ *
30
+ * Kept as an injected function so the transport, session pinning, and
31
+ * validation can be tested without a browser.
32
+ */
33
+ export type OpExecutor = (input: OpExecutorInput) => Promise<ResultEnvelope>;
34
+ export type RuntimeExecutorOptions = {
35
+ /** Default origin when the map has none. */
36
+ baseUrl?: string;
37
+ };
38
+ /**
39
+ * Execute an op through the cheapest verified tier.
40
+ *
41
+ * The tiers are tried in the map's declared order. A read may start from any
42
+ * state; a write must start in one of the op's `from` states, checked before
43
+ * dispatch. `runWrite` in the MCP layer owns confirmation and idempotency, so
44
+ * this function only runs the op.
45
+ */
46
+ export declare function runtimeExecutor(options?: RuntimeExecutorOptions): OpExecutor;
47
+ /**
48
+ * The executor used before a browser factory is configured.
49
+ *
50
+ * It reports exactly where the call stopped. Returning a fake success would
51
+ * be worse than failing: a caller would believe an order was placed.
52
+ */
53
+ export declare const notReadyExecutor: OpExecutor;
54
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,KAAK,EACL,cAAc,EACd,aAAa,EACb,OAAO,EACR,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpE,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,aAAa,CAAC;IACvB,GAAG,EAAE,OAAO,CAAC;IACb,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,sBAAsB,GAAG;IACnC,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,UAAU,CAyFhF;AAiBD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,UACY,CAAC"}
@@ -0,0 +1,108 @@
1
+ import { recognizeState, runHttpOp, runUiOp, runUrlOp } from "@abubakarsiddiik/runtime";
2
+ /**
3
+ * Execute an op through the cheapest verified tier.
4
+ *
5
+ * The tiers are tried in the map's declared order. A read may start from any
6
+ * state; a write must start in one of the op's `from` states, checked before
7
+ * dispatch. `runWrite` in the MCP layer owns confirmation and idempotency, so
8
+ * this function only runs the op.
9
+ */
10
+ export function runtimeExecutor(options = {}) {
11
+ return async ({ map, op, params, substrate, baseUrl, audit }) => {
12
+ if (substrate === undefined) {
13
+ return broken(op, "the server has no browser substrate");
14
+ }
15
+ const base = baseUrl ?? options.baseUrl ?? map.origins[0];
16
+ if (base === undefined) {
17
+ return broken(op, `site "${map.site}" has no origin`);
18
+ }
19
+ const before = stateOf(map, await substrate.view());
20
+ if (op.effect !== "read" && (before === undefined || !op.from.includes(before))) {
21
+ return {
22
+ ok: false,
23
+ error: {
24
+ code: "precondition_failed",
25
+ message: `op "${op.name}" needs ${op.from.join(" or ")}, found ${before ?? "unknown"}`,
26
+ ...(before !== undefined ? { details: { current_state: before } } : {}),
27
+ },
28
+ };
29
+ }
30
+ const tiers = [...new Set(op.impls.map((impl) => impl.tier))].filter((tier) => tier !== "webmcp");
31
+ if (tiers.length === 0) {
32
+ return broken(op, "no supported impl (webmcp is not implemented yet)");
33
+ }
34
+ let last;
35
+ for (const tier of tiers) {
36
+ if (tier === "url") {
37
+ const result = await runUrlOp({ map, op, params, substrate, baseUrl: base });
38
+ if (result.ok) {
39
+ audit?.({
40
+ tier: "url",
41
+ ...(before !== undefined ? { beforeState: before } : {}),
42
+ afterState: result.state,
43
+ requests: [{ method: "GET", url: result.url }],
44
+ });
45
+ return { ok: true, result: result.result };
46
+ }
47
+ last = result;
48
+ continue;
49
+ }
50
+ if (tier === "http") {
51
+ const result = await runHttpOp({ map, op, params, substrate, baseUrl: base });
52
+ if (result.ok) {
53
+ audit?.({
54
+ tier: "http",
55
+ ...(before !== undefined ? { beforeState: before } : {}),
56
+ requests: [{ method: "HTTP", url: result.url, status: result.status }],
57
+ });
58
+ return { ok: true, result: result.result };
59
+ }
60
+ last = result;
61
+ continue;
62
+ }
63
+ if (tier === "ui") {
64
+ const result = await runUiOp({ map, op, params, substrate });
65
+ if (result.ok) {
66
+ audit?.({
67
+ tier: "ui",
68
+ ...(before !== undefined ? { beforeState: before } : {}),
69
+ afterState: result.state,
70
+ });
71
+ return { ok: true, result: result.result };
72
+ }
73
+ last = result;
74
+ }
75
+ }
76
+ return last === undefined
77
+ ? broken(op, "no impl ran")
78
+ : {
79
+ ok: false,
80
+ error: {
81
+ code: last.code,
82
+ message: last.message,
83
+ ...(last.details !== undefined ? { details: last.details } : {}),
84
+ },
85
+ };
86
+ };
87
+ }
88
+ function broken(op, message) {
89
+ return {
90
+ ok: false,
91
+ error: {
92
+ code: "op_broken",
93
+ message: `op "${op.name}" reached the runtime, but ${message}`,
94
+ details: { stage: "executor", op: op.name },
95
+ },
96
+ };
97
+ }
98
+ function stateOf(map, view) {
99
+ return recognizeState(map, view.snapshot)?.state.id;
100
+ }
101
+ /**
102
+ * The executor used before a browser factory is configured.
103
+ *
104
+ * It reports exactly where the call stopped. Returning a fake success would
105
+ * be worse than failing: a caller would believe an order was placed.
106
+ */
107
+ export const notReadyExecutor = async ({ op }) => broken(op, "execution is not configured");
108
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAOA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C3B,CAAC,CAAC;gBACE,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE;oBACL,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACjE;aACF,CAAC;IACR,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,EAAS,EAAE,OAAe;IACxC,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE;YACL,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,OAAO,EAAE,CAAC,IAAI,8BAA8B,OAAO,EAAE;YAC9D,OAAO,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE;SAC5C;KACF,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,GAAY,EAAE,IAA4C;IACzE,OAAO,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAe,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAC3D,MAAM,CAAC,EAAE,EAAE,6BAA6B,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Effect, SiteMap } from "@abubakarsiddiik/protocol";
2
+ export type OpHealthStatus = "healthy" | "degraded" | "broken";
3
+ export type OpHealthRecord = {
4
+ site: string;
5
+ op: string;
6
+ map_version?: number;
7
+ status: OpHealthStatus;
8
+ checked_at: string;
9
+ message?: string;
10
+ ms?: number;
11
+ };
12
+ export type OpHealth = {
13
+ name: string;
14
+ effect: Effect;
15
+ status: OpHealthStatus | "unknown";
16
+ checked_at?: string;
17
+ message?: string;
18
+ ms?: number;
19
+ };
20
+ export type SiteHealth = {
21
+ site: string;
22
+ version: number;
23
+ checked_at?: string;
24
+ ops: OpHealth[];
25
+ };
26
+ /** Merge the latest stored status with every op in the map. */
27
+ export declare function mergeHealth(map: SiteMap, records: OpHealthRecord[]): SiteHealth;
28
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,QAAQ,EAAE,CAAC;CACjB,CAAC;AAEF,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,UAAU,CAwB/E"}
package/dist/health.js ADDED
@@ -0,0 +1,25 @@
1
+ /** Merge the latest stored status with every op in the map. */
2
+ export function mergeHealth(map, records) {
3
+ const byOp = new Map(records.map((record) => [record.op, record]));
4
+ const checked = records
5
+ .map((record) => record.checked_at)
6
+ .sort()
7
+ .at(-1);
8
+ return {
9
+ site: map.site,
10
+ version: map.version,
11
+ ...(checked !== undefined ? { checked_at: checked } : {}),
12
+ ops: map.ops.map((op) => {
13
+ const record = byOp.get(op.name);
14
+ return {
15
+ name: op.name,
16
+ effect: op.effect,
17
+ status: record?.status ?? "unknown",
18
+ ...(record?.checked_at !== undefined ? { checked_at: record.checked_at } : {}),
19
+ ...(record?.message !== undefined ? { message: record.message } : {}),
20
+ ...(record?.ms !== undefined ? { ms: record.ms } : {}),
21
+ };
22
+ }),
23
+ };
24
+ }
25
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AA8BA,+DAA+D;AAC/D,MAAM,UAAU,WAAW,CAAC,GAAY,EAAE,OAAyB;IACjE,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,OAAO;SACpB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC;SAClC,IAAI,EAAE;SACN,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAEV,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;YACtB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YAEjC,OAAO;gBACL,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,MAAM,EAAE,EAAE,CAAC,MAAM;gBACjB,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,SAAS;gBACnC,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC9E,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrE,GAAG,CAAC,MAAM,EAAE,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACvD,CAAC;QACJ,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
package/dist/host.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export type BindPolicy = {
2
+ /** When set, the server requires a bearer token. */
3
+ authToken?: string;
4
+ /** Explicit opt-in to a public bind without auth. */
5
+ allowRemote?: boolean;
6
+ };
7
+ /**
8
+ * Refuse to bind a public interface without authentication.
9
+ *
10
+ * The default host is loopback, so the common case is unaffected. A container
11
+ * or a host that sets `0.0.0.0` must either set a token or opt in explicitly;
12
+ * otherwise a session with the user's cookies is reachable from the network.
13
+ */
14
+ export declare function assertBindAllowed(host: string, policy?: BindPolicy): void;
15
+ export declare function isLoopbackHost(host: string): boolean;
16
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,UAAe,GAAG,IAAI,CAQ7E;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWpD"}
package/dist/host.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Refuse to bind a public interface without authentication.
3
+ *
4
+ * The default host is loopback, so the common case is unaffected. A container
5
+ * or a host that sets `0.0.0.0` must either set a token or opt in explicitly;
6
+ * otherwise a session with the user's cookies is reachable from the network.
7
+ */
8
+ export function assertBindAllowed(host, policy = {}) {
9
+ if (isLoopbackHost(host))
10
+ return;
11
+ if (policy.authToken !== undefined && policy.authToken.length > 0)
12
+ return;
13
+ if (policy.allowRemote === true)
14
+ return;
15
+ throw new Error(`refusing to bind ${host} without authentication; set PORTOLAN_AUTH_TOKEN or PORTOLAN_ALLOW_REMOTE=1`);
16
+ }
17
+ export function isLoopbackHost(host) {
18
+ const normalized = host
19
+ .trim()
20
+ .toLowerCase()
21
+ .replace(/^\[|\]$/g, "");
22
+ return (normalized === "localhost" ||
23
+ normalized === "::1" ||
24
+ normalized === "0:0:0:0:0:0:0:1" ||
25
+ normalized.startsWith("127."));
26
+ }
27
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,SAAqB,EAAE;IACrE,IAAI,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO;IACjC,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO;IAC1E,IAAI,MAAM,CAAC,WAAW,KAAK,IAAI;QAAE,OAAO;IAExC,MAAM,IAAI,KAAK,CACb,oBAAoB,IAAI,6EAA6E,CACtG,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,UAAU,GAAG,IAAI;SACpB,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3B,OAAO,CACL,UAAU,KAAK,WAAW;QAC1B,UAAU,KAAK,KAAK;QACpB,UAAU,KAAK,iBAAiB;QAChC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAC9B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export * from "./browsers.js";
2
+ export * from "./canary.js";
3
+ export * from "./credentials.js";
4
+ export * from "./executor.js";
5
+ export * from "./health.js";
6
+ export * from "./host.js";
7
+ export * from "./log.js";
8
+ export * from "./maps.js";
9
+ export * from "./mcp.js";
10
+ export * from "./server.js";
11
+ export * from "./stdio.js";
12
+ export * from "./store.js";
13
+ export * from "./write-ledger.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export * from "./browsers.js";
2
+ export * from "./canary.js";
3
+ export * from "./credentials.js";
4
+ export * from "./executor.js";
5
+ export * from "./health.js";
6
+ export * from "./host.js";
7
+ export * from "./log.js";
8
+ export * from "./maps.js";
9
+ export * from "./mcp.js";
10
+ export * from "./server.js";
11
+ export * from "./stdio.js";
12
+ export * from "./store.js";
13
+ export * from "./write-ledger.js";
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC"}
package/dist/log.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ export type LogLevel = "debug" | "info" | "warn" | "error";
2
+ export type LogFields = Record<string, unknown>;
3
+ /**
4
+ * A structured logger: one JSON object per line.
5
+ *
6
+ * The runtime writes logs a machine reads, not prose a human greps. Every
7
+ * field is redacted by key before it is written, so a credential passed in a
8
+ * field name cannot reach stdout.
9
+ */
10
+ export type Logger = {
11
+ debug(event: string, fields?: LogFields): void;
12
+ info(event: string, fields?: LogFields): void;
13
+ warn(event: string, fields?: LogFields): void;
14
+ error(event: string, fields?: LogFields): void;
15
+ /** A logger with fields merged into every line. */
16
+ child(fields: LogFields): Logger;
17
+ };
18
+ export type LoggerOptions = {
19
+ /** Default `info`. */
20
+ level?: LogLevel;
21
+ /** Defaults to stdout. */
22
+ write?: (line: string) => void;
23
+ /** Fields on every line, e.g. `{ service: "portolan-server" }`. */
24
+ base?: LogFields;
25
+ now?: () => Date;
26
+ };
27
+ export declare function createLogger(options?: LoggerOptions): Logger;
28
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/C,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9C,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9C,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/C,mDAAmD;IACnD,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,sBAAsB;IACtB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,0BAA0B;IAC1B,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,mEAAmE;IACnE,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB,CAAC;AASF,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CA8BhE"}
package/dist/log.js ADDED
@@ -0,0 +1,56 @@
1
+ import { isSensitiveKey, REDACTED, redactText } from "@abubakarsiddiik/runtime";
2
+ const LEVELS = {
3
+ debug: 10,
4
+ info: 20,
5
+ warn: 30,
6
+ error: 40,
7
+ };
8
+ export function createLogger(options = {}) {
9
+ const threshold = LEVELS[options.level ?? "info"];
10
+ const write = options.write ?? ((line) => process.stdout.write(`${line}\n`));
11
+ const now = options.now ?? (() => new Date());
12
+ const make = (base) => {
13
+ const emit = (level, event, fields) => {
14
+ if (LEVELS[level] < threshold)
15
+ return;
16
+ const record = {
17
+ ts: now().toISOString(),
18
+ level,
19
+ event,
20
+ ...redactFields(base),
21
+ ...redactFields(fields ?? {}),
22
+ };
23
+ write(JSON.stringify(record));
24
+ };
25
+ return {
26
+ debug: (event, fields) => emit("debug", event, fields),
27
+ info: (event, fields) => emit("info", event, fields),
28
+ warn: (event, fields) => emit("warn", event, fields),
29
+ error: (event, fields) => emit("error", event, fields),
30
+ child: (fields) => make({ ...base, ...fields }),
31
+ };
32
+ };
33
+ return make(options.base ?? {});
34
+ }
35
+ function redactFields(fields) {
36
+ const result = {};
37
+ for (const [key, value] of Object.entries(fields)) {
38
+ if (isSensitiveKey(key)) {
39
+ result[key] = REDACTED;
40
+ continue;
41
+ }
42
+ result[key] = redactValue(value);
43
+ }
44
+ return result;
45
+ }
46
+ function redactValue(value) {
47
+ if (Array.isArray(value))
48
+ return value.map((item) => redactValue(item));
49
+ if (value !== null && typeof value === "object") {
50
+ return redactFields(value);
51
+ }
52
+ if (typeof value === "string")
53
+ return redactText(value);
54
+ return value;
55
+ }
56
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAgChF,MAAM,MAAM,GAA6B;IACvC,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,EAAE;CACV,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,UAAyB,EAAE;IACtD,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CA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,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC;SAChD,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,YAAY,CAAC,MAAiB;IACrC,MAAM,MAAM,GAAc,EAAE,CAAC;IAE7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;YACvB,SAAS;QACX,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAExE,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,YAAY,CAAC,KAAkB,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;IAExD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/maps.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { type Effect, type JsonSchema, type SiteMap } from "@abubakarsiddiik/protocol";
2
+ export type OpSummary = {
3
+ name: string;
4
+ summary: string;
5
+ effect: Effect;
6
+ params: JsonSchema;
7
+ returns: JsonSchema;
8
+ };
9
+ export type SiteSummary = {
10
+ site: string;
11
+ version: number;
12
+ ops: OpSummary[];
13
+ };
14
+ export declare class MapStore {
15
+ private readonly directory;
16
+ constructor(directory: string);
17
+ list(): SiteSummary[];
18
+ get(site: string): SiteMap | undefined;
19
+ getVersion(site: string, version: number): SiteMap | undefined;
20
+ latestVersion(site: string): number | undefined;
21
+ }
22
+ /** The compact text `open_site` returns. */
23
+ export declare function renderMap(map: SiteMap): string;
24
+ //# sourceMappingURL=maps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maps.d.ts","sourceRoot":"","sources":["../src/maps.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EAGf,KAAK,OAAO,EACb,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,SAAS,EAAE,CAAC;CAClB,CAAC;AAgBF,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IAE9C,IAAI,IAAI,WAAW,EAAE;IA+BrB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAKtC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAW9D,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAkBhD;AAED,4CAA4C;AAC5C,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAQ9C"}