@kindgi/sdk 0.0.0-bootstrap.0 → 0.1.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/LICENSE +201 -0
- package/README.md +187 -1
- package/dist/build.d.ts +10 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +11 -0
- package/dist/build.js.map +1 -0
- package/dist/client.d.ts +33 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +55 -0
- package/dist/client.js.map +1 -0
- package/dist/define.d.ts +25 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +37 -0
- package/dist/define.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-config.d.ts +53 -0
- package/dist/runtime-config.d.ts.map +1 -0
- package/dist/runtime-config.js +114 -0
- package/dist/runtime-config.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/webhooks.d.ts +15 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +16 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +88 -4
- package/skills/kindgi-authoring-agents/SKILL.md +252 -0
- package/skills/kindgi-authoring-flows/SKILL.md +302 -0
- package/skills/kindgi-authoring-guardrails/SKILL.md +297 -0
- package/skills/kindgi-authoring-mcp-servers/SKILL.md +289 -0
- package/skills/kindgi-authoring-providers/SKILL.md +705 -0
- package/skills/kindgi-authoring-tools/SKILL.md +298 -0
- package/skills/kindgi-framework-feedback/SKILL.md +211 -0
- package/skills/kindgi-getting-started/SKILL.md +189 -0
- package/skills/kindgi-python-authoring-agents/SKILL.md +205 -0
- package/skills/kindgi-python-authoring-flows/SKILL.md +325 -0
- package/skills/kindgi-python-authoring-guardrails/SKILL.md +176 -0
- package/skills/kindgi-python-authoring-tools/SKILL.md +305 -0
- package/skills/kindgi-python-getting-started/SKILL.md +242 -0
- package/src/build.ts +18 -0
- package/src/client.ts +177 -0
- package/src/define.ts +75 -0
- package/src/index.ts +20 -0
- package/src/runtime-config.ts +180 -0
- package/src/types.ts +86 -0
- package/src/webhooks.ts +34 -0
package/src/client.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@kindgi/sdk/client` — client callsite surface.
|
|
6
|
+
*
|
|
7
|
+
* Re-exports `createClient` plus every resource-client type, the error
|
|
8
|
+
* surface, transport primitives, and streaming helpers from the
|
|
9
|
+
* `@kindgi/client` package (`sdks/typescript/` in this repository).
|
|
10
|
+
* Names preserved verbatim.
|
|
11
|
+
*
|
|
12
|
+
* This sub-path intentionally does NOT re-export the branded ID types
|
|
13
|
+
* (`AgentId`, `RunId`, etc.) that `@kindgi/client` also happens to
|
|
14
|
+
* surface — those live in `@kindgi/sdk/types` to keep the flat barrel
|
|
15
|
+
* (`import { ... } from '@kindgi/sdk'`) collision-free.
|
|
16
|
+
*
|
|
17
|
+
* Callsite examples target
|
|
18
|
+
* `import { createClient } from '@kindgi/sdk/client'`.
|
|
19
|
+
*
|
|
20
|
+
* @module @kindgi/sdk/client
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// ---- Client factory + top-level shape ----
|
|
24
|
+
import { createClient as createKindgiClient } from '@kindgi/client';
|
|
25
|
+
import type { ClientOptions, KindgiClient } from '@kindgi/client';
|
|
26
|
+
|
|
27
|
+
import { resolveClientOptions } from './runtime-config.js';
|
|
28
|
+
|
|
29
|
+
export type { KindgiClient } from '@kindgi/client';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A client for the app's Kindgi runtime. Every option is optional:
|
|
33
|
+
*
|
|
34
|
+
* - `apiUrl` and `auth` come from `KINDGI_API_URL` and `KINDGI_API_TOKEN`;
|
|
35
|
+
* - outside production, when those aren't set, from the running
|
|
36
|
+
* `kindgi dev` (the nearest `.kindgirc.json`), with a one-time warning to
|
|
37
|
+
* put them in the app's env file;
|
|
38
|
+
* - a token that doesn't match the running `kindgi dev`'s for the same
|
|
39
|
+
* `apiUrl` (after `kindgi dev --reset`) is warned about once.
|
|
40
|
+
*
|
|
41
|
+
* Production (`NODE_ENV` or `KINDGI_ENV` = `production`) never reads
|
|
42
|
+
* `.kindgirc.json`: there, the env or explicit options must say. In a
|
|
43
|
+
* browser, pass `apiUrl` and `auth`. `@kindgi/client`'s `createClient` is
|
|
44
|
+
* the explicit form underneath.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { createClient } from '@kindgi/sdk/client';
|
|
49
|
+
*
|
|
50
|
+
* const kindgi = createClient();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function createClient(options: Partial<ClientOptions> = {}): KindgiClient {
|
|
54
|
+
return createKindgiClient(resolveClientOptions(options));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ---- Resource client types + per-resource input shapes ----
|
|
58
|
+
export type {
|
|
59
|
+
AdapterConfigureInput,
|
|
60
|
+
AdapterFilter,
|
|
61
|
+
AdapterTestInput,
|
|
62
|
+
AdaptersClient,
|
|
63
|
+
AddMembershipInput,
|
|
64
|
+
AgentsClient,
|
|
65
|
+
ApplyProposalInput,
|
|
66
|
+
ApprovalFilter,
|
|
67
|
+
ApprovalsClient,
|
|
68
|
+
ArtifactFilter,
|
|
69
|
+
ArtifactsClient,
|
|
70
|
+
AuditClient,
|
|
71
|
+
AuditExportInput,
|
|
72
|
+
BatchDecideInput,
|
|
73
|
+
BudgetsClient,
|
|
74
|
+
CapabilitiesClient,
|
|
75
|
+
CapabilityFilter,
|
|
76
|
+
ClientOptions,
|
|
77
|
+
CompleteTokenInput,
|
|
78
|
+
ConversationFilter,
|
|
79
|
+
ConversationsClient,
|
|
80
|
+
CostClient,
|
|
81
|
+
DecideInput,
|
|
82
|
+
DraftProposalsInput,
|
|
83
|
+
EventsClient,
|
|
84
|
+
FactsClient,
|
|
85
|
+
FlowFilter,
|
|
86
|
+
FlowsClient,
|
|
87
|
+
FlowValidateResult,
|
|
88
|
+
GuardrailFilter,
|
|
89
|
+
GuardrailsClient,
|
|
90
|
+
LogsClient,
|
|
91
|
+
McpClient,
|
|
92
|
+
McpEndpointFilter,
|
|
93
|
+
McpEndpointsClient,
|
|
94
|
+
TeamMembershipsClient,
|
|
95
|
+
MemoryClient,
|
|
96
|
+
MessageFilter,
|
|
97
|
+
ObservationFilter,
|
|
98
|
+
ObservationsClient,
|
|
99
|
+
OrgsClient,
|
|
100
|
+
PackFilter,
|
|
101
|
+
PacksClient,
|
|
102
|
+
PageFilter,
|
|
103
|
+
PatternsInput,
|
|
104
|
+
PoliciesClient,
|
|
105
|
+
PolicyListFilter,
|
|
106
|
+
PolicyVersionsFilter,
|
|
107
|
+
ProposalDryRunInput,
|
|
108
|
+
ProposalListInput,
|
|
109
|
+
ProposalsClient,
|
|
110
|
+
ProvenanceClient,
|
|
111
|
+
ProvenanceExportInput,
|
|
112
|
+
ProviderFilter,
|
|
113
|
+
ProvidersClient,
|
|
114
|
+
ReflectReviewInput,
|
|
115
|
+
RegistryClient,
|
|
116
|
+
RegistryFilter,
|
|
117
|
+
ResumeRunInput,
|
|
118
|
+
ReviewerFilter,
|
|
119
|
+
ReviewersClient,
|
|
120
|
+
RollbackProposalInput,
|
|
121
|
+
Run,
|
|
122
|
+
RunsClient,
|
|
123
|
+
SchedulesClient,
|
|
124
|
+
SessionsClient,
|
|
125
|
+
StartRunInput,
|
|
126
|
+
SubmitForReviewInput,
|
|
127
|
+
SubscriptionsClient,
|
|
128
|
+
SupervisorClient,
|
|
129
|
+
ListTeamsFilter,
|
|
130
|
+
TeamsClient,
|
|
131
|
+
TenantClient,
|
|
132
|
+
TenantConfigClient,
|
|
133
|
+
TokenFilter,
|
|
134
|
+
TokensClient,
|
|
135
|
+
ReinstateToolVersionResult,
|
|
136
|
+
ToolFilter,
|
|
137
|
+
ToolVersionFilter,
|
|
138
|
+
ToolsClient,
|
|
139
|
+
Transport,
|
|
140
|
+
TransportRequest,
|
|
141
|
+
UsageClient,
|
|
142
|
+
UsageSummaryInput,
|
|
143
|
+
UserFilter,
|
|
144
|
+
UsersClient,
|
|
145
|
+
WebhooksClient,
|
|
146
|
+
WithdrawProposalInput,
|
|
147
|
+
} from '@kindgi/client';
|
|
148
|
+
|
|
149
|
+
// ---- Error surface ----
|
|
150
|
+
export { KindgiApiError, fromWire, notImplementedInPreview, notYetWired } from '@kindgi/client';
|
|
151
|
+
export type {
|
|
152
|
+
AuthError,
|
|
153
|
+
ConflictError,
|
|
154
|
+
GuardrailViolation,
|
|
155
|
+
GuardrailViolationError,
|
|
156
|
+
InvalidRequestError,
|
|
157
|
+
NetworkError,
|
|
158
|
+
NotFoundError,
|
|
159
|
+
NotImplementedInPreviewError,
|
|
160
|
+
NotYetWiredError,
|
|
161
|
+
RateLimitedError,
|
|
162
|
+
ServerError,
|
|
163
|
+
KindgiError,
|
|
164
|
+
} from '@kindgi/client';
|
|
165
|
+
|
|
166
|
+
// ---- Streaming helpers (SSE parser + resume) ----
|
|
167
|
+
export { readSse, unwrapSseData } from '@kindgi/client';
|
|
168
|
+
export type { SseEvent, SseReadOptions } from '@kindgi/client';
|
|
169
|
+
|
|
170
|
+
// ---- Following a run (browser-safe: a page follows a run with a public token) ----
|
|
171
|
+
export { followRun, subscribeToRun } from '@kindgi/client';
|
|
172
|
+
export type {
|
|
173
|
+
FollowRunOptions,
|
|
174
|
+
RunProgress,
|
|
175
|
+
RunProgressEvent,
|
|
176
|
+
SubscribeToRunOptions,
|
|
177
|
+
} from '@kindgi/client';
|
package/src/define.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@kindgi/sdk/define` — pack authoring surface.
|
|
6
|
+
*
|
|
7
|
+
* Re-exports the authoring primitives from the individual packages
|
|
8
|
+
* (`@kindgi/tools`, `@kindgi/guardrails`, `@kindgi/agents`,
|
|
9
|
+
* `@kindgi/flow`, `@kindgi/schema`) verbatim — no renaming, no
|
|
10
|
+
* behavior. Consumers reading those packages' docs find matching
|
|
11
|
+
* symbols here.
|
|
12
|
+
*
|
|
13
|
+
* The SDK facade is the recommended public developer surface. The
|
|
14
|
+
* individual packages remain importable directly.
|
|
15
|
+
*
|
|
16
|
+
* @module @kindgi/sdk/define
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// ---- Tools ----
|
|
20
|
+
export {
|
|
21
|
+
defineTool,
|
|
22
|
+
defineToolAsync,
|
|
23
|
+
invokeTool,
|
|
24
|
+
registerToolSpecSynthesizer,
|
|
25
|
+
} from '@kindgi/tools';
|
|
26
|
+
export type {
|
|
27
|
+
DefinedTool,
|
|
28
|
+
DefineToolSpec,
|
|
29
|
+
HttpAuthSpec,
|
|
30
|
+
HttpHeaderSpec,
|
|
31
|
+
HttpMethod,
|
|
32
|
+
HttpRequestBodySpec,
|
|
33
|
+
HttpToolSpec,
|
|
34
|
+
InferInput,
|
|
35
|
+
InferOutput,
|
|
36
|
+
Tool,
|
|
37
|
+
ToolContext,
|
|
38
|
+
ToolManifest,
|
|
39
|
+
ToolSecretRef,
|
|
40
|
+
ToolSpec,
|
|
41
|
+
ToolSpecSynthesizer,
|
|
42
|
+
} from '@kindgi/tools';
|
|
43
|
+
|
|
44
|
+
// ---- Guardrails (checks) ----
|
|
45
|
+
export { defineCheck } from '@kindgi/guardrails';
|
|
46
|
+
export type { DefineCheckSpec, DefinedCheck, InferCheckConfig } from '@kindgi/guardrails';
|
|
47
|
+
|
|
48
|
+
// ---- Agents ----
|
|
49
|
+
export { defineAgent } from '@kindgi/agents';
|
|
50
|
+
export type { Agent, DefineAgentSpec } from '@kindgi/agents';
|
|
51
|
+
|
|
52
|
+
// ---- Flow ----
|
|
53
|
+
//
|
|
54
|
+
// `defineFlow` is the author-facing primitive that mirrors `defineTool`
|
|
55
|
+
// / `defineCheck` / `defineAgent` — a thin wrapper over `loadFlow` that
|
|
56
|
+
// runs the same validation gauntlet and returns `Result<Flow,
|
|
57
|
+
// FlowError>`. Pack authors reach for `defineFlow` in TypeScript;
|
|
58
|
+
// `loadFlow` remains the wire-form entry point for JSON coming off disk
|
|
59
|
+
// / network.
|
|
60
|
+
export { defineFlow } from '@kindgi/flow';
|
|
61
|
+
export type {
|
|
62
|
+
EdgePolicy,
|
|
63
|
+
FanoutNode,
|
|
64
|
+
Flow,
|
|
65
|
+
FlowSpec,
|
|
66
|
+
LoopNode,
|
|
67
|
+
SubflowNode,
|
|
68
|
+
} from '@kindgi/flow';
|
|
69
|
+
|
|
70
|
+
// ---- Zod-optional helpers ----
|
|
71
|
+
//
|
|
72
|
+
// Direct access for callers that prefer to convert / inspect schemas
|
|
73
|
+
// themselves rather than let `defineTool` / `defineCheck` do it implicitly.
|
|
74
|
+
export { isZodSchema, toJSONSchema } from '@kindgi/schema';
|
|
75
|
+
export type { AnySchema, ZodLikeSchema } from '@kindgi/schema';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@kindgi/sdk` — public developer facade.
|
|
6
|
+
*
|
|
7
|
+
* Flat barrel that re-exports the three sub-paths for callers who prefer
|
|
8
|
+
* a single import: `import { defineTool, createClient, type RunId } from
|
|
9
|
+
* '@kindgi/sdk'`.
|
|
10
|
+
*
|
|
11
|
+
* Sub-paths are the primary developer-facing shape (`@kindgi/sdk/define`,
|
|
12
|
+
* `@kindgi/sdk/client`, `@kindgi/sdk/types`); this barrel is a
|
|
13
|
+
* convenience alias.
|
|
14
|
+
*
|
|
15
|
+
* @module @kindgi/sdk
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export * from './define.js';
|
|
19
|
+
export * from './client.js';
|
|
20
|
+
export * from './types.js';
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where an app's client finds its Kindgi runtime when `createClient` is
|
|
6
|
+
* called without `apiUrl` / `auth`:
|
|
7
|
+
*
|
|
8
|
+
* 1. `KINDGI_API_URL` and `KINDGI_API_TOKEN` from the environment;
|
|
9
|
+
* 2. outside production, the running `kindgi dev`, from the nearest
|
|
10
|
+
* `.kindgirc.json` at or above the working directory (it records the
|
|
11
|
+
* runtime's `apiUrl` and the dev `token`), with a one-time warning to
|
|
12
|
+
* put them in the app's env file;
|
|
13
|
+
* 3. otherwise, an error that says what to set.
|
|
14
|
+
*
|
|
15
|
+
* Production (`NODE_ENV` or `KINDGI_ENV` set to `production`) never reads
|
|
16
|
+
* `.kindgirc.json`. Whatever the source, a token that differs from the
|
|
17
|
+
* running `kindgi dev`'s for the same `apiUrl` (the stale token after
|
|
18
|
+
* `kindgi dev --reset`) is warned about once.
|
|
19
|
+
*
|
|
20
|
+
* Node only: the file is read through `process.getBuiltinModule`, never a
|
|
21
|
+
* static `node:` import, so the module stays safe to bundle for browsers,
|
|
22
|
+
* where only explicit options apply.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { AuthConfig, ClientOptions } from '@kindgi/client';
|
|
26
|
+
|
|
27
|
+
/** The file `kindgi dev` writes in the pack directory. */
|
|
28
|
+
export const DEV_RUNTIME_FILE = '.kindgirc.json';
|
|
29
|
+
|
|
30
|
+
/** What a client needs from a running `kindgi dev`. */
|
|
31
|
+
export interface DevRuntime {
|
|
32
|
+
readonly apiUrl: string;
|
|
33
|
+
readonly token: string;
|
|
34
|
+
/** The `.kindgirc.json` it came from. */
|
|
35
|
+
readonly path: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Where the lookup runs: the process's own environment by default (tests pass their own). */
|
|
39
|
+
export interface RuntimeConfigContext {
|
|
40
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
41
|
+
/** The directory the `.kindgirc.json` search starts from. */
|
|
42
|
+
readonly cwd: string | undefined;
|
|
43
|
+
readonly warn: (message: string) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const ENV_FILE_HINT = 'your env file (.env / .env.local)';
|
|
47
|
+
|
|
48
|
+
const warned = new Set<string>();
|
|
49
|
+
|
|
50
|
+
function warnOnce(context: RuntimeConfigContext, key: string, message: string): void {
|
|
51
|
+
if (warned.has(key)) return;
|
|
52
|
+
warned.add(key);
|
|
53
|
+
context.warn(`[kindgi] ${message}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function defaultContext(): RuntimeConfigContext {
|
|
57
|
+
const proc = typeof process === 'undefined' ? undefined : process;
|
|
58
|
+
return {
|
|
59
|
+
env: proc?.env ?? {},
|
|
60
|
+
cwd: typeof proc?.cwd === 'function' ? proc.cwd() : undefined,
|
|
61
|
+
warn: (message) => console.warn(message),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function isProduction(env: RuntimeConfigContext['env']): boolean {
|
|
66
|
+
return env.NODE_ENV === 'production' || env.KINDGI_ENV === 'production';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The client options with every missing field resolved (see the module
|
|
71
|
+
* comment). Throws when no `apiUrl` or no token can be found.
|
|
72
|
+
*/
|
|
73
|
+
export function resolveClientOptions(
|
|
74
|
+
options: Partial<ClientOptions>,
|
|
75
|
+
context: RuntimeConfigContext = defaultContext(),
|
|
76
|
+
): ClientOptions {
|
|
77
|
+
const { env } = context;
|
|
78
|
+
const dev = isProduction(env) ? undefined : findDevRuntime(context.cwd);
|
|
79
|
+
|
|
80
|
+
let apiUrl = options.apiUrl ?? nonEmpty(env.KINDGI_API_URL);
|
|
81
|
+
let auth: AuthConfig | undefined =
|
|
82
|
+
options.auth ??
|
|
83
|
+
(nonEmpty(env.KINDGI_API_TOKEN) !== undefined
|
|
84
|
+
? { kind: 'apiToken', token: env.KINDGI_API_TOKEN as string }
|
|
85
|
+
: undefined);
|
|
86
|
+
|
|
87
|
+
if ((apiUrl === undefined || auth === undefined) && dev !== undefined) {
|
|
88
|
+
const used: string[] = [];
|
|
89
|
+
if (apiUrl === undefined) {
|
|
90
|
+
apiUrl = dev.apiUrl;
|
|
91
|
+
used.push('KINDGI_API_URL');
|
|
92
|
+
}
|
|
93
|
+
if (auth === undefined) {
|
|
94
|
+
auth = { kind: 'apiToken', token: dev.token };
|
|
95
|
+
used.push('KINDGI_API_TOKEN');
|
|
96
|
+
}
|
|
97
|
+
warnOnce(
|
|
98
|
+
context,
|
|
99
|
+
`fallback:${dev.path}`,
|
|
100
|
+
`Using the running kindgi dev from ${dev.path} for ${used.join(' and ')}. Set them in ${ENV_FILE_HINT}, and in production, where there's no ${DEV_RUNTIME_FILE}.`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (apiUrl === undefined || auth === undefined) {
|
|
105
|
+
const missing = [
|
|
106
|
+
...(apiUrl === undefined ? ['KINDGI_API_URL'] : []),
|
|
107
|
+
...(auth === undefined ? ['KINDGI_API_TOKEN'] : []),
|
|
108
|
+
];
|
|
109
|
+
throw new Error(
|
|
110
|
+
`createClient(): ${missing.join(' and ')} ${missing.length === 1 ? "isn't" : "aren't"} set. Set ${missing.length === 1 ? 'it' : 'them'} in ${ENV_FILE_HINT}, or pass { apiUrl, auth }.${
|
|
111
|
+
isProduction(env)
|
|
112
|
+
? ''
|
|
113
|
+
: ` In development, run \`kindgi dev\` in the app: it writes them to ${DEV_RUNTIME_FILE}, which the client reads.`
|
|
114
|
+
}`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (dev !== undefined && auth.kind === 'apiToken' && auth.token !== dev.token) {
|
|
119
|
+
if (sameUrl(apiUrl, dev.apiUrl)) {
|
|
120
|
+
warnOnce(
|
|
121
|
+
context,
|
|
122
|
+
`stale:${dev.path}:${dev.token}`,
|
|
123
|
+
`The API token doesn't match the running kindgi dev's (${dev.path}). After \`kindgi dev --reset\` the token changes: copy the new one into ${ENV_FILE_HINT}.`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { ...options, apiUrl, auth };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The running `kindgi dev`'s `apiUrl` and `token`, from the nearest
|
|
133
|
+
* `.kindgirc.json` at or above `from`; `undefined` when there's none, it
|
|
134
|
+
* can't be read, or the runtime can't read files (a browser).
|
|
135
|
+
*/
|
|
136
|
+
export function findDevRuntime(from: string | undefined): DevRuntime | undefined {
|
|
137
|
+
if (from === undefined) return undefined;
|
|
138
|
+
const fs = builtin<typeof import('node:fs')>('node:fs');
|
|
139
|
+
const path = builtin<typeof import('node:path')>('node:path');
|
|
140
|
+
if (fs === undefined || path === undefined) return undefined;
|
|
141
|
+
for (let dir = from; ; dir = path.dirname(dir)) {
|
|
142
|
+
const candidate = path.join(dir, DEV_RUNTIME_FILE);
|
|
143
|
+
if (fs.existsSync(candidate)) return readDevRuntime(fs, candidate);
|
|
144
|
+
if (path.dirname(dir) === dir) return undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function readDevRuntime(fs: typeof import('node:fs'), file: string): DevRuntime | undefined {
|
|
149
|
+
try {
|
|
150
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<string, unknown>;
|
|
151
|
+
const apiUrl = parsed.apiUrl;
|
|
152
|
+
const token = parsed.token;
|
|
153
|
+
if (typeof apiUrl !== 'string' || apiUrl === '' || typeof token !== 'string' || token === '') {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
return { apiUrl, token, path: file };
|
|
157
|
+
} catch {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function builtin<T>(id: string): T | undefined {
|
|
163
|
+
const proc = typeof process === 'undefined' ? undefined : process;
|
|
164
|
+
const get = (proc as { getBuiltinModule?: (id: string) => unknown } | undefined)
|
|
165
|
+
?.getBuiltinModule;
|
|
166
|
+
return typeof get === 'function' ? (get.call(proc, id) as T | undefined) : undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function nonEmpty(value: string | undefined): string | undefined {
|
|
170
|
+
return value === undefined || value === '' ? undefined : value;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function sameUrl(a: string, b: string): boolean {
|
|
174
|
+
return a.replace(/\/+$/, '') === b.replace(/\/+$/, '');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Tests only: forget which warnings were printed. */
|
|
178
|
+
export function resetWarningsForTests(): void {
|
|
179
|
+
warned.clear();
|
|
180
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@kindgi/sdk/types` — branded IDs, framework-wide result envelope,
|
|
6
|
+
* pagination, refs, temporal + version primitives.
|
|
7
|
+
*
|
|
8
|
+
* Re-exports types from `@kindgi/types` under their own names. These
|
|
9
|
+
* are the workspace-wide identifiers callers pass across the SDK
|
|
10
|
+
* boundary.
|
|
11
|
+
*
|
|
12
|
+
* The /types sub-path is where branded identifiers live in the public
|
|
13
|
+
* facade.
|
|
14
|
+
*
|
|
15
|
+
* @module @kindgi/sdk/types
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export type {
|
|
19
|
+
BlobRef,
|
|
20
|
+
Brand,
|
|
21
|
+
ContentHash,
|
|
22
|
+
Cursor,
|
|
23
|
+
DatasetRef,
|
|
24
|
+
DurationMs,
|
|
25
|
+
ErrOf,
|
|
26
|
+
Filter,
|
|
27
|
+
IsoDuration,
|
|
28
|
+
OkOf,
|
|
29
|
+
Page,
|
|
30
|
+
Result,
|
|
31
|
+
SchemaMajor,
|
|
32
|
+
Semver,
|
|
33
|
+
SignatureValue,
|
|
34
|
+
Timestamp,
|
|
35
|
+
VersionedRef,
|
|
36
|
+
} from '@kindgi/types';
|
|
37
|
+
|
|
38
|
+
// ---- Branded IDs ----
|
|
39
|
+
//
|
|
40
|
+
// Re-exported individually rather than via `export type *` so the flat
|
|
41
|
+
// barrel (`import { RunId } from '@kindgi/sdk'`) can see them —
|
|
42
|
+
// `verbatimModuleSyntax` requires named type re-exports for `export *`
|
|
43
|
+
// forwarding to work through the barrel.
|
|
44
|
+
export type {
|
|
45
|
+
AgentId,
|
|
46
|
+
ApiTokenId,
|
|
47
|
+
ApprovalId,
|
|
48
|
+
ArtifactId,
|
|
49
|
+
AuditBundleId,
|
|
50
|
+
ComplianceEvidenceId,
|
|
51
|
+
ConversationId,
|
|
52
|
+
DatasetId,
|
|
53
|
+
EdgeId,
|
|
54
|
+
EventId,
|
|
55
|
+
FactId,
|
|
56
|
+
FixProposalId,
|
|
57
|
+
FlowId,
|
|
58
|
+
InstallationId,
|
|
59
|
+
GuardrailId,
|
|
60
|
+
KeyId,
|
|
61
|
+
LogEntryId,
|
|
62
|
+
NodeId,
|
|
63
|
+
ObservationId,
|
|
64
|
+
OrgId,
|
|
65
|
+
PackId,
|
|
66
|
+
PolicyId,
|
|
67
|
+
ProjectId,
|
|
68
|
+
ProvenanceId,
|
|
69
|
+
ProviderId,
|
|
70
|
+
ReviewerId,
|
|
71
|
+
RunId,
|
|
72
|
+
ScheduleId,
|
|
73
|
+
SessionId,
|
|
74
|
+
SigningKeyId,
|
|
75
|
+
SubscriptionId,
|
|
76
|
+
SupervisorId,
|
|
77
|
+
TeamId,
|
|
78
|
+
TenantId,
|
|
79
|
+
ThreadId,
|
|
80
|
+
ToolId,
|
|
81
|
+
TriggerId,
|
|
82
|
+
UserId,
|
|
83
|
+
WaitTokenId,
|
|
84
|
+
WebhookDeliveryId,
|
|
85
|
+
WebhookId,
|
|
86
|
+
} from '@kindgi/types';
|
package/src/webhooks.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@kindgi/sdk/webhooks` — receiving Kindgi's webhooks. Server only: it
|
|
6
|
+
* uses `node:crypto`, so it stays out of `/client` (browser-safe) and the
|
|
7
|
+
* flat barrel.
|
|
8
|
+
*
|
|
9
|
+
* Re-exports the Standard Webhooks helpers from `@kindgi/crypto`:
|
|
10
|
+
* `verifyWebhook` for a receiver, `generateWebhookSecret` for the secret an
|
|
11
|
+
* app registers by name, and `signWebhook` / `webhookHeaders` to test a
|
|
12
|
+
* receiver.
|
|
13
|
+
*
|
|
14
|
+
* @module @kindgi/sdk/webhooks
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
DEFAULT_WEBHOOK_TOLERANCE_SECONDS,
|
|
19
|
+
generateWebhookSecret,
|
|
20
|
+
isStrongWebhookSecret,
|
|
21
|
+
signWebhook,
|
|
22
|
+
verifyWebhook,
|
|
23
|
+
WEBHOOK_HEADERS,
|
|
24
|
+
WEBHOOK_SECRET_MIN_BYTES,
|
|
25
|
+
WEBHOOK_SECRET_PREFIX,
|
|
26
|
+
webhookHeaders,
|
|
27
|
+
} from '@kindgi/crypto';
|
|
28
|
+
export type {
|
|
29
|
+
SignWebhookInput,
|
|
30
|
+
VerifyWebhookFailure,
|
|
31
|
+
VerifyWebhookInput,
|
|
32
|
+
VerifyWebhookResult,
|
|
33
|
+
WebhookRequestHeaders,
|
|
34
|
+
} from '@kindgi/crypto';
|