@clinebot/shared 0.0.8

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/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @clinebot/shared
2
+
3
+ Package-level docs are centralized:
4
+
5
+ - Overview: [`packages/README.md`](../README.md)
6
+ - Architecture and interactions: [`ARCHITECTURE.md`](/Users/beatrix/dev/clinee/sdk-wip/ARCHITECTURE.md)
7
+
8
+ `@clinebot/shared` owns shared cross-package primitives (session common types/utilities).
9
+
10
+ Node-only filesystem path resolvers live under the storage subpath export:
11
+
12
+ - `@clinebot/shared/storage`
13
+ - examples: `resolveClineDataDir`, `resolveSessionDataDir`, `resolveTeamDataDir`
14
+
15
+ It also exports cross-client logging contracts, including `BasicLogger`, so
16
+ runtime, SDK, and host applications can share a single logger type.
17
+
18
+ Session config primitives are also centralized here so hosts/runtimes can
19
+ compose one base shape instead of redefining similar fields repeatedly:
20
+
21
+ - `AgentMode`
22
+ - `SessionPromptConfig`
23
+ - `SessionWorkspaceConfig`
24
+ - `SessionExecutionConfig` (includes canonical `ToolPolicy` map shape)
25
+
26
+ It now also exports hook session context primitives used across agents/core/CLI:
27
+
28
+ - `HookSessionContext`
29
+ - `resolveHookSessionContext(...)`
30
+ - `resolveRootSessionId(...)`
31
+ - `resolveHookLogPath(...)`
32
+
33
+ It also exports cross-client RPC runtime payload DTOs used by multiple hosts
34
+ (`@clinebot/cli`, `@clinebot/code`) so request/response contracts are not duplicated
35
+ outside transport wiring:
36
+
37
+ - chat runtime payloads (`RpcChatStartSessionRequest`, `RpcChatRunTurnRequest`, `RpcChatTurnResult`)
38
+ - provider runtime payloads (`RpcProviderActionRequest`, `RpcProviderCatalogResponse`, `RpcProviderOAuthLoginResponse`)
39
+ - Cline account runtime payloads (`RpcClineAccountActionRequest`, `RpcClineAccountUser`, `RpcClineAccountBalance`)
40
+ - provider action requests include provider catalog/model operations plus provider add/save operations for settings hosts
41
+ - provider action payloads now expose granular request/type contracts for reuse:
42
+ `RpcAddProviderActionRequest`, `RpcSaveProviderSettingsActionRequest`,
43
+ `RpcProviderCapability`, and `RpcOAuthProviderId`
44
+
45
+ Chat runtime payload notes:
46
+ - `RpcChatStartSessionRequest` supports `initialMessages`, optional `toolPolicies`, optional `rules` for default system prompt assembly, and optional `logger` runtime config (`RpcChatRuntimeLoggerConfig`) so hosts can pass serialized logger settings to remote runtimes.
47
+ - `RpcChatRuntimeLoggerConfig.bindings` lets hosts attach stable context fields (for example `clientId`, `clientType`, `clientApp`) to all runtime log records.
48
+ - `RpcChatRunTurnRequest` supports `promptPreformatted` for callers that already built CLI-style user input envelopes.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Canonical list of OAuth provider IDs managed by the platform.
3
+ * Derive sets, types, and guards from this single source of truth.
4
+ */
5
+ export declare const OAUTH_PROVIDER_IDS: readonly ["cline", "oca", "openai-codex"];
6
+ export type OAuthProviderId = (typeof OAUTH_PROVIDER_IDS)[number];
7
+ /**
8
+ * Check whether a provider ID is a managed OAuth provider.
9
+ */
10
+ export declare function isOAuthProviderId(providerId: string): providerId is OAuthProviderId;
11
+ /**
12
+ * Error‑message sub-strings that indicate an auth / credential failure.
13
+ * Used to decide whether a failed API call should trigger an OAuth refresh.
14
+ */
15
+ export declare const AUTH_ERROR_PATTERNS: readonly ["401", "403", "unauthorized", "forbidden", "invalid token", "expired token", "authentication"];
16
+ /**
17
+ * Returns `true` when `error` looks like an authentication failure
18
+ * *and* the provider is a managed OAuth provider.
19
+ */
20
+ export declare function isLikelyAuthError(error: unknown, providerId: string): boolean;
@@ -0,0 +1,35 @@
1
+ import { z } from "zod";
2
+ export declare const ConnectorHookEventNameSchema: z.ZodEnum<{
3
+ "connector.started": "connector.started";
4
+ "connector.stopping": "connector.stopping";
5
+ "message.received": "message.received";
6
+ "message.completed": "message.completed";
7
+ "message.failed": "message.failed";
8
+ "session.started": "session.started";
9
+ "session.reused": "session.reused";
10
+ "thread.reset": "thread.reset";
11
+ "schedule.delivery.started": "schedule.delivery.started";
12
+ "schedule.delivery.sent": "schedule.delivery.sent";
13
+ "schedule.delivery.failed": "schedule.delivery.failed";
14
+ }>;
15
+ export type ConnectorHookEventName = z.infer<typeof ConnectorHookEventNameSchema>;
16
+ export declare const ConnectorHookEventSchema: z.ZodObject<{
17
+ adapter: z.ZodString;
18
+ botUserName: z.ZodOptional<z.ZodString>;
19
+ event: z.ZodEnum<{
20
+ "connector.started": "connector.started";
21
+ "connector.stopping": "connector.stopping";
22
+ "message.received": "message.received";
23
+ "message.completed": "message.completed";
24
+ "message.failed": "message.failed";
25
+ "session.started": "session.started";
26
+ "session.reused": "session.reused";
27
+ "thread.reset": "thread.reset";
28
+ "schedule.delivery.started": "schedule.delivery.started";
29
+ "schedule.delivery.sent": "schedule.delivery.sent";
30
+ "schedule.delivery.failed": "schedule.delivery.failed";
31
+ }>;
32
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
33
+ ts: z.ZodString;
34
+ }, z.core.$strip>;
35
+ export type ConnectorHookEvent = z.infer<typeof ConnectorHookEventSchema>;
@@ -0,0 +1,2 @@
1
+ export type { SessionSchemaOptions, SqliteDb, SqliteStatement, } from "./sqlite-db";
2
+ export { asBool, asOptionalString, asString, ensureSessionSchema, loadSqliteDb, nowIso, toBoolInt, } from "./sqlite-db";
@@ -0,0 +1,92 @@
1
+ var D=Object.defineProperty;var E=(S)=>S;function F(S,g){this[S]=E.bind(null,g)}var W=(S,g)=>{for(var w in g)D(S,w,{get:g[w],enumerable:!0,configurable:!0,set:F.bind(g,w)})};import{createRequire as G}from"node:module";function J(){return new Date().toISOString()}function K(S){return S?1:0}function L(S){return typeof S==="string"?S:""}function Q(S){if(typeof S!=="string")return;let g=S.trim();return g.length>0?g:void 0}function T(S){return S===1||S===!0}function U(S){let g=G(import.meta.url);if(typeof globalThis.Bun<"u"){let{Database:j}=g("bun:sqlite"),x=new j(S,{create:!0});return{prepare:(I)=>{let k=x.query(I);return{run:(...O)=>k.run(...O),get:(...O)=>k.get(...O),all:(...O)=>k.all(...O)}},exec:(I)=>x.exec(I)}}try{let j=["node",":sqlite"].join(""),{DatabaseSync:x}=g(j),I=new x(S);return{prepare:(k)=>{let O=I.prepare(k);return{run:(...z)=>O.run(...z),get:(...z)=>O.get(...z)??null,all:(...z)=>O.all(...z)}},exec:(k)=>I.exec(k)}}catch{}let B=["better","-sqlite3"].join("");return new(g(B))(S)}function V(S,g={}){if(S.exec("PRAGMA journal_mode = WAL;"),S.exec("PRAGMA busy_timeout = 5000;"),S.exec(`
2
+ CREATE TABLE IF NOT EXISTS sessions (
3
+ session_id TEXT PRIMARY KEY,
4
+ source TEXT NOT NULL,
5
+ pid INTEGER NOT NULL,
6
+ started_at TEXT NOT NULL,
7
+ ended_at TEXT,
8
+ exit_code INTEGER,
9
+ status TEXT NOT NULL,
10
+ status_lock INTEGER NOT NULL DEFAULT 0,
11
+ interactive INTEGER NOT NULL,
12
+ provider TEXT NOT NULL,
13
+ model TEXT NOT NULL,
14
+ cwd TEXT NOT NULL,
15
+ workspace_root TEXT NOT NULL,
16
+ team_name TEXT,
17
+ enable_tools INTEGER NOT NULL,
18
+ enable_spawn INTEGER NOT NULL,
19
+ enable_teams INTEGER NOT NULL,
20
+ parent_session_id TEXT,
21
+ parent_agent_id TEXT,
22
+ agent_id TEXT,
23
+ conversation_id TEXT,
24
+ is_subagent INTEGER NOT NULL DEFAULT 0,
25
+ prompt TEXT,
26
+ metadata_json TEXT,
27
+ transcript_path TEXT NOT NULL,
28
+ hook_path TEXT NOT NULL,
29
+ messages_path TEXT,
30
+ updated_at TEXT NOT NULL
31
+ );
32
+ `),S.exec(`
33
+ CREATE TABLE IF NOT EXISTS subagent_spawn_queue (
34
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
35
+ root_session_id TEXT NOT NULL,
36
+ parent_agent_id TEXT NOT NULL,
37
+ task TEXT,
38
+ system_prompt TEXT,
39
+ created_at TEXT NOT NULL,
40
+ consumed_at TEXT
41
+ );
42
+ `),S.exec(`
43
+ CREATE TABLE IF NOT EXISTS schedules (
44
+ schedule_id TEXT PRIMARY KEY,
45
+ name TEXT NOT NULL,
46
+ cron_pattern TEXT NOT NULL,
47
+ prompt TEXT NOT NULL,
48
+ provider TEXT NOT NULL,
49
+ model TEXT NOT NULL,
50
+ mode TEXT NOT NULL DEFAULT 'act',
51
+ workspace_root TEXT,
52
+ cwd TEXT,
53
+ system_prompt TEXT,
54
+ max_iterations INTEGER,
55
+ timeout_seconds INTEGER,
56
+ max_parallel INTEGER NOT NULL DEFAULT 1,
57
+ enabled INTEGER NOT NULL DEFAULT 1,
58
+ created_at TEXT NOT NULL,
59
+ updated_at TEXT NOT NULL,
60
+ last_run_at TEXT,
61
+ next_run_at TEXT,
62
+ claim_token TEXT,
63
+ claim_started_at TEXT,
64
+ claim_until_at TEXT,
65
+ created_by TEXT,
66
+ tags TEXT,
67
+ metadata_json TEXT
68
+ );
69
+ `),S.exec(`
70
+ CREATE TABLE IF NOT EXISTS schedule_executions (
71
+ execution_id TEXT PRIMARY KEY,
72
+ schedule_id TEXT NOT NULL,
73
+ session_id TEXT,
74
+ triggered_at TEXT NOT NULL,
75
+ started_at TEXT,
76
+ ended_at TEXT,
77
+ status TEXT NOT NULL,
78
+ exit_code INTEGER,
79
+ error_message TEXT,
80
+ iterations INTEGER,
81
+ tokens_used INTEGER,
82
+ cost_usd REAL,
83
+ FOREIGN KEY (schedule_id) REFERENCES schedules(schedule_id) ON DELETE CASCADE,
84
+ FOREIGN KEY (session_id) REFERENCES sessions(session_id) ON DELETE SET NULL
85
+ );
86
+ `),S.exec(`
87
+ CREATE INDEX IF NOT EXISTS idx_schedule_executions_schedule
88
+ ON schedule_executions(schedule_id, triggered_at DESC);
89
+ `),S.exec(`
90
+ CREATE INDEX IF NOT EXISTS idx_schedules_next_run
91
+ ON schedules(enabled, next_run_at);
92
+ `),!g.includeLegacyMigrations)return;let w=S.prepare("PRAGMA table_info(sessions);").all(),B=(x)=>w.some((I)=>I.name===x);if(!B("workspace_root"))S.exec("ALTER TABLE sessions ADD COLUMN workspace_root TEXT;"),S.exec("UPDATE sessions SET workspace_root = cwd WHERE workspace_root IS NULL OR workspace_root = '';");if(!B("parent_session_id"))S.exec("ALTER TABLE sessions ADD COLUMN parent_session_id TEXT;");if(!B("parent_agent_id"))S.exec("ALTER TABLE sessions ADD COLUMN parent_agent_id TEXT;");if(!B("agent_id"))S.exec("ALTER TABLE sessions ADD COLUMN agent_id TEXT;");if(!B("conversation_id"))S.exec("ALTER TABLE sessions ADD COLUMN conversation_id TEXT;");if(!B("is_subagent"))S.exec("ALTER TABLE sessions ADD COLUMN is_subagent INTEGER NOT NULL DEFAULT 0;");if(!B("messages_path"))S.exec("ALTER TABLE sessions ADD COLUMN messages_path TEXT;");if(!B("metadata_json"))S.exec("ALTER TABLE sessions ADD COLUMN metadata_json TEXT;");let A=S.prepare("PRAGMA table_info(schedules);").all(),j=(x)=>A.some((I)=>I.name===x);if(!j("claim_token"))S.exec("ALTER TABLE schedules ADD COLUMN claim_token TEXT;");if(!j("claim_started_at"))S.exec("ALTER TABLE schedules ADD COLUMN claim_started_at TEXT;");if(!j("claim_until_at"))S.exec("ALTER TABLE schedules ADD COLUMN claim_until_at TEXT;")}export{K as toBoolInt,J as nowIso,U as loadSqliteDb,V as ensureSessionSchema,L as asString,Q as asOptionalString,T as asBool};
@@ -0,0 +1,21 @@
1
+ export type SqliteStatement = {
2
+ run: (...params: unknown[]) => {
3
+ changes?: number;
4
+ };
5
+ get: (...params: unknown[]) => Record<string, unknown> | null;
6
+ all: (...params: unknown[]) => Record<string, unknown>[];
7
+ };
8
+ export type SqliteDb = {
9
+ prepare: (sql: string) => SqliteStatement;
10
+ exec: (sql: string) => void;
11
+ };
12
+ export declare function nowIso(): string;
13
+ export declare function toBoolInt(value: boolean): number;
14
+ export declare function asString(value: unknown): string;
15
+ export declare function asOptionalString(value: unknown): string | undefined;
16
+ export declare function asBool(value: unknown): boolean;
17
+ export declare function loadSqliteDb(filePath: string): SqliteDb;
18
+ export interface SessionSchemaOptions {
19
+ includeLegacyMigrations?: boolean;
20
+ }
21
+ export declare function ensureSessionSchema(db: SqliteDb, options?: SessionSchemaOptions): void;
@@ -0,0 +1,26 @@
1
+ export type { OAuthProviderId } from "./auth/constants";
2
+ export { AUTH_ERROR_PATTERNS, isLikelyAuthError, isOAuthProviderId, OAUTH_PROVIDER_IDS, } from "./auth/constants";
3
+ export type { ConnectorHookEvent, ConnectorHookEventName, } from "./connectors/events";
4
+ export { ConnectorHookEventNameSchema, ConnectorHookEventSchema, } from "./connectors/events";
5
+ export { MODELS_DEV_PROVIDER_KEY_ENTRIES, MODELS_DEV_PROVIDER_KEY_MAP, resolveProviderModelCatalogKeys, } from "./llms/model-id";
6
+ export type { Tool, ToolApprovalRequest, ToolApprovalResult, ToolCallRecord, ToolContext, ToolPolicy, } from "./llms/tools";
7
+ export { ToolCallRecordSchema, ToolContextSchema } from "./llms/tools";
8
+ export type { BasicLogger } from "./logging/logger";
9
+ export { parseJsonStream, safeJsonStringify } from "./parse/json";
10
+ export { formatHumanReadableDate } from "./parse/time";
11
+ export { validateWithZod, zodToJsonSchema } from "./parse/zod";
12
+ export { formatFileContentBlock, formatUserInputBlock, normalizeUserInput, xmlTagsRemoval, } from "./prompt/format";
13
+ export type { RpcAddProviderActionRequest, RpcAgentMode, RpcChatAttachmentFile, RpcChatAttachments, RpcChatMessage, RpcChatRunTurnRequest, RpcChatRuntimeConfigBase, RpcChatRuntimeLoggerConfig, RpcChatStartSessionArtifacts, RpcChatStartSessionRequest, RpcChatStartSessionResponse, RpcChatToolCallResult, RpcChatTurnResult, RpcClineAccountActionRequest, RpcClineAccountBalance, RpcClineAccountOrganization, RpcClineAccountOrganizationBalance, RpcClineAccountOrganizationUsageTransaction, RpcClineAccountPaymentTransaction, RpcClineAccountUsageTransaction, RpcClineAccountUser, RpcGetProviderModelsActionRequest, RpcListProvidersActionRequest, RpcOAuthProviderId, RpcProviderActionRequest, RpcProviderCapability, RpcProviderCatalogResponse, RpcProviderListItem, RpcProviderModel, RpcProviderModelsResponse, RpcProviderOAuthLoginResponse, RpcProviderSettingsActionRequest, RpcSaveProviderSettingsActionRequest, RpcSessionStorageOptions, } from "./rpc/runtime";
14
+ export type { TeamProgressCounts, TeamProgressLifecycleEvent, TeamProgressMemberRole, TeamProgressMemberStatus, TeamProgressOutcomeFragmentStatus, TeamProgressOutcomeStatus, TeamProgressProjectionEvent, TeamProgressRunStatus, TeamProgressSummary, TeamProgressTaskStatus, } from "./rpc/team-progress";
15
+ export { RPC_TEAM_LIFECYCLE_EVENT_TYPE, RPC_TEAM_PROGRESS_EVENT_TYPE, } from "./rpc/team-progress";
16
+ export type { ITelemetryService, OpenTelemetryClientConfig, TelemetryArray, TelemetryMetadata, TelemetryObject, TelemetryPrimitive, TelemetryProperties, TelemetryValue, } from "./services/telemetry";
17
+ export type { ClineTelemetryServiceConfig } from "./services/telemetry-config";
18
+ export { createClineTelemetryServiceConfig, createClineTelemetryServiceMetadata, } from "./services/telemetry-config";
19
+ export type { HookSessionContext, HookSessionContextLookup, HookSessionContextProvider, } from "./session/hook-context";
20
+ export { resolveHookLogPath, resolveHookSessionContext, resolveRootSessionId, } from "./session/hook-context";
21
+ export type { SessionLineage, SessionRuntimeRecordShape, SharedSessionStatus, } from "./session/records";
22
+ export { SESSION_STATUS_VALUES } from "./session/records";
23
+ export type { AgentMode, SessionExecutionConfig, SessionPromptConfig, SessionWorkspaceConfig, } from "./session/runtime-config";
24
+ export type { RuntimeEnv } from "./session/runtime-env";
25
+ export type { VcrRecording } from "./vcr";
26
+ export { initVcr } from "./vcr";