@tarkahq/sdk 0.0.0-stage → 0.3.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 (130) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +69 -0
  3. package/README.md +700 -2
  4. package/api-source.json +38 -0
  5. package/dist/cjs/client.d.ts +114 -0
  6. package/dist/cjs/client.js +174 -0
  7. package/dist/cjs/errors.d.ts +27 -0
  8. package/dist/cjs/errors.js +78 -0
  9. package/dist/cjs/generated/google/api/annotations.d.ts +1 -0
  10. package/dist/cjs/generated/google/api/annotations.js +10 -0
  11. package/dist/cjs/generated/google/api/http.d.ts +395 -0
  12. package/dist/cjs/generated/google/api/http.js +421 -0
  13. package/dist/cjs/generated/google/protobuf/descriptor.d.ts +873 -0
  14. package/dist/cjs/generated/google/protobuf/descriptor.js +3992 -0
  15. package/dist/cjs/generated/google/protobuf/empty.d.ts +35 -0
  16. package/dist/cjs/generated/google/protobuf/empty.js +58 -0
  17. package/dist/cjs/generated/google/protobuf/struct.d.ts +127 -0
  18. package/dist/cjs/generated/google/protobuf/struct.js +529 -0
  19. package/dist/cjs/generated/google/protobuf/timestamp.d.ts +128 -0
  20. package/dist/cjs/generated/google/protobuf/timestamp.js +95 -0
  21. package/dist/cjs/generated/protoc-gen-openapiv2/options/annotations.d.ts +1 -0
  22. package/dist/cjs/generated/protoc-gen-openapiv2/options/annotations.js +10 -0
  23. package/dist/cjs/generated/protoc-gen-openapiv2/options/openapiv2.d.ts +983 -0
  24. package/dist/cjs/generated/protoc-gen-openapiv2/options/openapiv2.js +4874 -0
  25. package/dist/cjs/generated/tarka/access/v1/access.d.ts +322 -0
  26. package/dist/cjs/generated/tarka/access/v1/access.js +2979 -0
  27. package/dist/cjs/generated/tarka/channels/v1/channels.d.ts +370 -0
  28. package/dist/cjs/generated/tarka/channels/v1/channels.js +3603 -0
  29. package/dist/cjs/generated/tarka/gateway/v1/gateway.d.ts +804 -0
  30. package/dist/cjs/generated/tarka/gateway/v1/gateway.js +8081 -0
  31. package/dist/cjs/generated/tarka/iam/v1/iam.d.ts +1291 -0
  32. package/dist/cjs/generated/tarka/iam/v1/iam.js +13207 -0
  33. package/dist/cjs/generated/tarka/inference/v1/inference.d.ts +699 -0
  34. package/dist/cjs/generated/tarka/inference/v1/inference.js +7058 -0
  35. package/dist/cjs/generated/tarka/provisioning/v1/agent_secrets.d.ts +70 -0
  36. package/dist/cjs/generated/tarka/provisioning/v1/agent_secrets.js +603 -0
  37. package/dist/cjs/generated/tarka/provisioning/v1/billing_quote.d.ts +171 -0
  38. package/dist/cjs/generated/tarka/provisioning/v1/billing_quote.js +1588 -0
  39. package/dist/cjs/generated/tarka/provisioning/v1/job.d.ts +168 -0
  40. package/dist/cjs/generated/tarka/provisioning/v1/job.js +1505 -0
  41. package/dist/cjs/generated/tarka/provisioning/v1/provisioning.d.ts +2644 -0
  42. package/dist/cjs/generated/tarka/provisioning/v1/provisioning.js +19501 -0
  43. package/dist/cjs/generated/tarka/provisioning/v1/registry_credentials.d.ts +89 -0
  44. package/dist/cjs/generated/tarka/provisioning/v1/registry_credentials.js +856 -0
  45. package/dist/cjs/generated/tarka/provisioning/v1/sandbox.d.ts +431 -0
  46. package/dist/cjs/generated/tarka/provisioning/v1/sandbox.js +3203 -0
  47. package/dist/cjs/generated/tarka/provisioning/v1/source_builds.d.ts +291 -0
  48. package/dist/cjs/generated/tarka/provisioning/v1/source_builds.js +3920 -0
  49. package/dist/cjs/grpc.d.ts +12 -0
  50. package/dist/cjs/grpc.js +55 -0
  51. package/dist/cjs/index.d.ts +6 -0
  52. package/dist/cjs/index.js +21 -0
  53. package/dist/cjs/package.json +1 -0
  54. package/dist/cjs/resources/inference.d.ts +293 -0
  55. package/dist/cjs/resources/inference.js +451 -0
  56. package/dist/cjs/resources/provisioning.d.ts +389 -0
  57. package/dist/cjs/resources/provisioning.js +552 -0
  58. package/dist/cjs/resources/sandboxes.d.ts +360 -0
  59. package/dist/cjs/resources/sandboxes.js +732 -0
  60. package/dist/cjs/rpc-types.d.ts +36 -0
  61. package/dist/cjs/rpc-types.js +29 -0
  62. package/dist/cjs/runtime.d.ts +99 -0
  63. package/dist/cjs/runtime.js +473 -0
  64. package/dist/cjs/transport.d.ts +60 -0
  65. package/dist/cjs/transport.js +114 -0
  66. package/dist/cjs/types.d.ts +309 -0
  67. package/dist/cjs/types.js +2 -0
  68. package/dist/esm/client.d.ts +114 -0
  69. package/dist/esm/client.js +169 -0
  70. package/dist/esm/errors.d.ts +27 -0
  71. package/dist/esm/errors.js +71 -0
  72. package/dist/esm/generated/google/api/annotations.d.ts +1 -0
  73. package/dist/esm/generated/google/api/annotations.js +7 -0
  74. package/dist/esm/generated/google/api/http.d.ts +395 -0
  75. package/dist/esm/generated/google/api/http.js +418 -0
  76. package/dist/esm/generated/google/protobuf/descriptor.d.ts +873 -0
  77. package/dist/esm/generated/google/protobuf/descriptor.js +3977 -0
  78. package/dist/esm/generated/google/protobuf/empty.d.ts +35 -0
  79. package/dist/esm/generated/google/protobuf/empty.js +55 -0
  80. package/dist/esm/generated/google/protobuf/struct.d.ts +127 -0
  81. package/dist/esm/generated/google/protobuf/struct.js +524 -0
  82. package/dist/esm/generated/google/protobuf/timestamp.d.ts +128 -0
  83. package/dist/esm/generated/google/protobuf/timestamp.js +92 -0
  84. package/dist/esm/generated/protoc-gen-openapiv2/options/annotations.d.ts +1 -0
  85. package/dist/esm/generated/protoc-gen-openapiv2/options/annotations.js +7 -0
  86. package/dist/esm/generated/protoc-gen-openapiv2/options/openapiv2.d.ts +983 -0
  87. package/dist/esm/generated/protoc-gen-openapiv2/options/openapiv2.js +4859 -0
  88. package/dist/esm/generated/tarka/access/v1/access.d.ts +322 -0
  89. package/dist/esm/generated/tarka/access/v1/access.js +2976 -0
  90. package/dist/esm/generated/tarka/channels/v1/channels.d.ts +370 -0
  91. package/dist/esm/generated/tarka/channels/v1/channels.js +3600 -0
  92. package/dist/esm/generated/tarka/gateway/v1/gateway.d.ts +804 -0
  93. package/dist/esm/generated/tarka/gateway/v1/gateway.js +8077 -0
  94. package/dist/esm/generated/tarka/iam/v1/iam.d.ts +1291 -0
  95. package/dist/esm/generated/tarka/iam/v1/iam.js +13203 -0
  96. package/dist/esm/generated/tarka/inference/v1/inference.d.ts +699 -0
  97. package/dist/esm/generated/tarka/inference/v1/inference.js +7055 -0
  98. package/dist/esm/generated/tarka/provisioning/v1/agent_secrets.d.ts +70 -0
  99. package/dist/esm/generated/tarka/provisioning/v1/agent_secrets.js +600 -0
  100. package/dist/esm/generated/tarka/provisioning/v1/billing_quote.d.ts +171 -0
  101. package/dist/esm/generated/tarka/provisioning/v1/billing_quote.js +1585 -0
  102. package/dist/esm/generated/tarka/provisioning/v1/job.d.ts +168 -0
  103. package/dist/esm/generated/tarka/provisioning/v1/job.js +1500 -0
  104. package/dist/esm/generated/tarka/provisioning/v1/provisioning.d.ts +2644 -0
  105. package/dist/esm/generated/tarka/provisioning/v1/provisioning.js +19496 -0
  106. package/dist/esm/generated/tarka/provisioning/v1/registry_credentials.d.ts +89 -0
  107. package/dist/esm/generated/tarka/provisioning/v1/registry_credentials.js +853 -0
  108. package/dist/esm/generated/tarka/provisioning/v1/sandbox.d.ts +431 -0
  109. package/dist/esm/generated/tarka/provisioning/v1/sandbox.js +3192 -0
  110. package/dist/esm/generated/tarka/provisioning/v1/source_builds.d.ts +291 -0
  111. package/dist/esm/generated/tarka/provisioning/v1/source_builds.js +3917 -0
  112. package/dist/esm/grpc.d.ts +12 -0
  113. package/dist/esm/grpc.js +11 -0
  114. package/dist/esm/index.d.ts +6 -0
  115. package/dist/esm/index.js +4 -0
  116. package/dist/esm/resources/inference.d.ts +293 -0
  117. package/dist/esm/resources/inference.js +437 -0
  118. package/dist/esm/resources/provisioning.d.ts +389 -0
  119. package/dist/esm/resources/provisioning.js +531 -0
  120. package/dist/esm/resources/sandboxes.d.ts +360 -0
  121. package/dist/esm/resources/sandboxes.js +718 -0
  122. package/dist/esm/rpc-types.d.ts +36 -0
  123. package/dist/esm/rpc-types.js +26 -0
  124. package/dist/esm/runtime.d.ts +99 -0
  125. package/dist/esm/runtime.js +466 -0
  126. package/dist/esm/transport.d.ts +60 -0
  127. package/dist/esm/transport.js +110 -0
  128. package/dist/esm/types.d.ts +309 -0
  129. package/dist/esm/types.js +1 -0
  130. package/package.json +155 -4
@@ -0,0 +1,38 @@
1
+ {
2
+ "repository": "https://github.com/TarkaHQ/api",
3
+ "revision": "1bbe9c6ab8c1cdd73e4309b1ad062a44eb2964e9",
4
+ "generators": {
5
+ "grpc-tools": "1.13.1",
6
+ "ts-proto": "2.12.4"
7
+ },
8
+ "options": [
9
+ "outputServices=generic-definitions",
10
+ "outputClientImpl=false",
11
+ "env=node",
12
+ "forceLong=bigint",
13
+ "oneof=unions-value",
14
+ "useExactTypes=false",
15
+ "esModuleInterop=true",
16
+ "importSuffix=.js"
17
+ ],
18
+ "sources": {
19
+ "tarka/access/v1/access.proto": "aa8960b47aaaa3bfedf95d7e1060fa8b4c03601c15d67d1b365fa93c1d67d278",
20
+ "tarka/channels/v1/channels.proto": "9d5301f73af5f736389b6dfc66ce2bb8c87cc3f40f4ba22b87e94fbfe3385e47",
21
+ "tarka/gateway/v1/gateway.proto": "3490a2dc178d356e0748b933316650d2335579c48412de38048be0356f8dc6fe",
22
+ "tarka/iam/v1/iam.proto": "885f3fc0e7e7fd60f69e47891dfb734ae932ed33f2431b7f95e147185112daab",
23
+ "tarka/inference/v1/inference.proto": "7690975cde9687537511cb26bc32c83470ddde427c59c71670f52c68b4ee72f1",
24
+ "tarka/provisioning/v1/agent_secrets.proto": "b6c4774cd21609a6179b15851592ca9d71a8857e3a9c8a616694ff6c697c2540",
25
+ "tarka/provisioning/v1/billing_quote.proto": "ba69a5c0e922833fa4efcc0772e522483485fcb0e6d75ab4b0cd9e5d59db0e4c",
26
+ "tarka/provisioning/v1/job.proto": "e3bb52fdc2521a8e39255c02a8a62982dcf33803b20caa82fbf9da2b726d5175",
27
+ "tarka/provisioning/v1/provisioning.proto": "f227bb9426ede9345e71342f85700725278fbdcb7e12b6a40162ce164c3a9f0d",
28
+ "tarka/provisioning/v1/registry_credentials.proto": "30d9abf3e013ad42dfd9871a4ceef8ce996cff010227fa23bfc9f156f62b0e6e",
29
+ "tarka/provisioning/v1/sandbox.proto": "a840ceedaa3c494ef3987ef93ff6875b78a8f0f64dfda09af0ed39f66a9c44d7",
30
+ "tarka/provisioning/v1/source_builds.proto": "900d424f76533eabbede0d43c10bbcc9ffc8aaef85653f2b72e2c9d898a1fac6"
31
+ },
32
+ "imports": {
33
+ "google/api/annotations.proto": "e79ea741cb605a65e78ca322174764a4af9fde1962c1631e12b84c4934ba9a6c",
34
+ "google/api/http.proto": "ead99129aa15dd5f6233942030c72eec33bc0d7b1c7c260dc143293ef66c5b78",
35
+ "protoc-gen-openapiv2/options/annotations.proto": "1f8e23ce506c358349d5ce0e54c336e3b2f3bf17c5d9e7d965e24a6e3429c2c9",
36
+ "protoc-gen-openapiv2/options/openapiv2.proto": "8e9c28731f17e4608a1f7457cdd6f9a2718add4f5f9a0390dd5514a88e2023ef"
37
+ }
38
+ }
@@ -0,0 +1,114 @@
1
+ import type { ServiceClient } from "./transport.js";
2
+ import { ChannelsServiceDefinition } from "./generated/tarka/channels/v1/channels.js";
3
+ import { AccessServiceDefinition } from "./generated/tarka/access/v1/access.js";
4
+ import { GatewayServiceDefinition } from "./generated/tarka/gateway/v1/gateway.js";
5
+ import { IAMServiceDefinition } from "./generated/tarka/iam/v1/iam.js";
6
+ import { Channel, type ChannelCredentials, type ChannelOptions } from "@grpc/grpc-js";
7
+ import { InferenceServiceDefinition } from "./generated/tarka/inference/v1/inference.js";
8
+ import { Audio, Catalog, Chat, Models, Ocr, Responses } from "./resources/inference.js";
9
+ import { Users, Organizations, OrganizationScope, Git } from "./resources/provisioning.js";
10
+ import { type GrpcClient, type ProvisioningRpc } from "./rpc-types.js";
11
+ /** Default native gRPC endpoint used by authenticated SDK-owned connections. */
12
+ export declare const DEFAULT_GRPC_ENDPOINT = "grpc.tarka.rest:443";
13
+ /** Advanced gRPC endpoint and TLS configuration for an SDK-owned connection. */
14
+ export interface ChannelConfig {
15
+ /** Native gRPC target, such as `grpc.tarka.rest:443`, or a resolver URI. Defaults to the Tarka endpoint; do not use an HTTP URL. */
16
+ target?: string;
17
+ /** TLS credentials, for example `credentials.createSsl(customRootCA)` imported from `@tarkahq/sdk/grpc`. */
18
+ channelCredentials?: ChannelCredentials;
19
+ /** Native grpc-js channel settings. Ordinary SDK use does not require them. */
20
+ channelOptions?: ChannelOptions;
21
+ }
22
+ /**
23
+ * Choose an access token with optional endpoint/TLS settings, or inject a caller-owned channel.
24
+ *
25
+ * An injected channel cannot be combined with a token or channel configuration. `timeoutMs` sets the default RPC timeout; sandbox wait helpers use their own total budget.
26
+ */
27
+ export type TarkaClientOptions = ((ChannelConfig & {
28
+ /** Raw bearer token, without a Bearer prefix. The SDK configures TLS authentication. */
29
+ accessToken: string;
30
+ channel?: never;
31
+ }) | {
32
+ /** Caller-owned connection; the caller supplies authentication and closes it. */
33
+ channel: Channel;
34
+ accessToken?: never;
35
+ target?: never;
36
+ channelCredentials?: never;
37
+ channelOptions?: never;
38
+ }) & {
39
+ /** Default RPC timeout in milliseconds; per-call timeoutMs overrides it. Wait/run helpers default to their own 60-second total budget. */
40
+ timeoutMs?: number;
41
+ };
42
+ /**
43
+ * Create a TLS channel with bearer authentication. The caller owns its lifecycle.
44
+ *
45
+ * @param accessToken - Raw token without a `Bearer` prefix, whitespace, or control characters.
46
+ * @param options - Optional native gRPC target, TLS credentials, and channel settings.
47
+ * @returns A channel that must be closed by its owner.
48
+ * @throws TypeError for an invalid token or HTTP target. Insecure credentials cannot be combined with bearer authentication.
49
+ */
50
+ export declare function createChannel(accessToken: string, options?: ChannelConfig): Channel;
51
+ /**
52
+ * Tarka resource client for inference, organizations, compute, storage, Git, and sandboxes.
53
+ *
54
+ * Reuse one client across requests. Resource methods expose typed entities and TarkaError failures; advanced transport access is isolated under `grpc`.
55
+ * @example
56
+ * const client = new TarkaClient({ accessToken, timeoutMs: 30_000 });
57
+ * try {
58
+ * const text = await client.chat.text({ model, prompt: "Hello" });
59
+ * } finally {
60
+ * client.close();
61
+ * }
62
+ */
63
+ export declare class TarkaClient {
64
+ #private;
65
+ /** Advanced native RPC clients and their shared channel. These retain generated envelopes, native call options, and numeric gRPC errors. */
66
+ readonly iam: ServiceClient<typeof IAMServiceDefinition>;
67
+ readonly gateway: ServiceClient<typeof GatewayServiceDefinition>;
68
+ readonly access: ServiceClient<typeof AccessServiceDefinition>;
69
+ readonly channels: ServiceClient<typeof ChannelsServiceDefinition>;
70
+ readonly control: ProvisioningRpc;
71
+ readonly inferenceApi: ServiceClient<typeof InferenceServiceDefinition>;
72
+ readonly grpc: GrpcClient;
73
+ /** Discover inference-visible models as plain records. */
74
+ readonly models: Models;
75
+ /** Typed completions, text helpers, and OpenAI-compatible JSON chat. */
76
+ readonly chat: Chat;
77
+ /** OpenAI-compatible Responses API with direct JSON bodies and events. */
78
+ readonly responses: Responses;
79
+ /** Image text recognition with full-result and text-only helpers. */
80
+ readonly ocr: Ocr;
81
+ /** Audio transcription, translation, speech generation, and voice cloning. */
82
+ readonly audio: Audio;
83
+ /** Control plane model catalog with modality filtering and provisioning details. */
84
+ readonly catalog: Catalog;
85
+ /** Retrieve or initialize the authenticated account. */
86
+ readonly user: Users;
87
+ /** List, retrieve, and create organizations. Use `org(id)` for organization-scoped resources. */
88
+ readonly organizations: Organizations;
89
+ /** Ensure hosted Git access for the authenticated account. */
90
+ readonly git: Git;
91
+ /**
92
+ * Create a resource client with a shared connection.
93
+ *
94
+ * @param options - Raw access token and optional RPC timeout, or a caller-owned channel. Defaults to TLS at grpc.tarka.rest:443.
95
+ * @throws TypeError for invalid or mutually exclusive connection options.
96
+ */
97
+ constructor(options: TarkaClientOptions);
98
+ /**
99
+ * Bind resource operations to one organization without making a network request.
100
+ *
101
+ * @param id - Organization identifier, for example `user.defaultOrgId`.
102
+ * @returns A scope whose nested operations automatically include this organization ID.
103
+ * @example
104
+ * const org = client.org(orgId);
105
+ * const keys = await org.apiKeys.list();
106
+ */
107
+ org(id: string): OrganizationScope;
108
+ /**
109
+ * Close the SDK-owned connection. Safe to call more than once.
110
+ *
111
+ * A caller-provided channel remains open and must be closed by its owner. Close after active work has finished, typically on application shutdown.
112
+ */
113
+ close(): void;
114
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TarkaClient = exports.DEFAULT_GRPC_ENDPOINT = void 0;
4
+ exports.createChannel = createChannel;
5
+ const channels_js_1 = require("./generated/tarka/channels/v1/channels.js");
6
+ const access_js_1 = require("./generated/tarka/access/v1/access.js");
7
+ const gateway_js_1 = require("./generated/tarka/gateway/v1/gateway.js");
8
+ const iam_js_1 = require("./generated/tarka/iam/v1/iam.js");
9
+ const grpc_js_1 = require("@grpc/grpc-js");
10
+ const inference_js_1 = require("./generated/tarka/inference/v1/inference.js");
11
+ const provisioning_js_1 = require("./generated/tarka/provisioning/v1/provisioning.js");
12
+ const sandbox_js_1 = require("./generated/tarka/provisioning/v1/sandbox.js");
13
+ const transport_js_1 = require("./transport.js");
14
+ const inference_js_2 = require("./resources/inference.js");
15
+ const provisioning_js_2 = require("./resources/provisioning.js");
16
+ const rpc_types_js_1 = require("./rpc-types.js");
17
+ /** Default native gRPC endpoint used by authenticated SDK-owned connections. */
18
+ exports.DEFAULT_GRPC_ENDPOINT = "grpc.tarka.rest:443";
19
+ /**
20
+ * Create a TLS channel with bearer authentication. The caller owns its lifecycle.
21
+ *
22
+ * @param accessToken - Raw token without a `Bearer` prefix, whitespace, or control characters.
23
+ * @param options - Optional native gRPC target, TLS credentials, and channel settings.
24
+ * @returns A channel that must be closed by its owner.
25
+ * @throws TypeError for an invalid token or HTTP target. Insecure credentials cannot be combined with bearer authentication.
26
+ */
27
+ function createChannel(accessToken, options = {}) {
28
+ if (typeof accessToken !== "string" || !/^[\x21-\x7e]+$/.test(accessToken)) {
29
+ throw new TypeError("accessToken must be a non-empty token without whitespace or control characters");
30
+ }
31
+ const target = options.target ?? exports.DEFAULT_GRPC_ENDPOINT;
32
+ if (!target.trim() || /^https?:\/\//i.test(target)) {
33
+ throw new TypeError("target must be a native gRPC target such as grpc.tarka.rest:443");
34
+ }
35
+ const auth = grpc_js_1.credentials.createFromMetadataGenerator((_params, callback) => {
36
+ const metadata = new grpc_js_1.Metadata();
37
+ metadata.set("authorization", `Bearer ${accessToken}`);
38
+ callback(null, metadata);
39
+ });
40
+ // grpc-js rejects combining call credentials with an insecure channel.
41
+ const secure = grpc_js_1.credentials.combineChannelCredentials(options.channelCredentials ?? grpc_js_1.credentials.createSsl(), auth);
42
+ return new grpc_js_1.Channel(target, secure, options.channelOptions ?? {});
43
+ }
44
+ /**
45
+ * Tarka resource client for inference, organizations, compute, storage, Git, and sandboxes.
46
+ *
47
+ * Reuse one client across requests. Resource methods expose typed entities and TarkaError failures; advanced transport access is isolated under `grpc`.
48
+ * @example
49
+ * const client = new TarkaClient({ accessToken, timeoutMs: 30_000 });
50
+ * try {
51
+ * const text = await client.chat.text({ model, prompt: "Hello" });
52
+ * } finally {
53
+ * client.close();
54
+ * }
55
+ */
56
+ class TarkaClient {
57
+ /** Advanced native RPC clients and their shared channel. These retain generated envelopes, native call options, and numeric gRPC errors. */
58
+ iam;
59
+ gateway;
60
+ access;
61
+ channels;
62
+ control;
63
+ inferenceApi;
64
+ grpc;
65
+ /** Discover inference-visible models as plain records. */
66
+ models;
67
+ /** Typed completions, text helpers, and OpenAI-compatible JSON chat. */
68
+ chat;
69
+ /** OpenAI-compatible Responses API with direct JSON bodies and events. */
70
+ responses;
71
+ /** Image text recognition with full-result and text-only helpers. */
72
+ ocr;
73
+ /** Audio transcription, translation, speech generation, and voice cloning. */
74
+ audio;
75
+ /** Control plane model catalog with modality filtering and provisioning details. */
76
+ catalog;
77
+ /** Retrieve or initialize the authenticated account. */
78
+ user;
79
+ /** List, retrieve, and create organizations. Use `org(id)` for organization-scoped resources. */
80
+ organizations;
81
+ /** Ensure hosted Git access for the authenticated account. */
82
+ git;
83
+ #provisioning;
84
+ #sandboxes;
85
+ #ownsChannel;
86
+ #closed = false;
87
+ /**
88
+ * Create a resource client with a shared connection.
89
+ *
90
+ * @param options - Raw access token and optional RPC timeout, or a caller-owned channel. Defaults to TLS at grpc.tarka.rest:443.
91
+ * @throws TypeError for invalid or mutually exclusive connection options.
92
+ */
93
+ constructor(options) {
94
+ if (!options || typeof options !== "object") {
95
+ throw new TypeError("TarkaClient requires an accessToken or a caller-provided channel");
96
+ }
97
+ (0, transport_js_1.validateTimeout)(options.timeoutMs);
98
+ let channel;
99
+ if (options.channel != null) {
100
+ if (options.accessToken !== undefined ||
101
+ options.target !== undefined ||
102
+ options.channelCredentials !== undefined ||
103
+ options.channelOptions !== undefined) {
104
+ throw new TypeError("A caller-provided channel cannot be combined with accessToken or channel configuration");
105
+ }
106
+ this.#ownsChannel = false;
107
+ channel = options.channel;
108
+ }
109
+ else {
110
+ this.#ownsChannel = true;
111
+ channel = createChannel(options.accessToken, options);
112
+ }
113
+ const defaults = { timeoutMs: options.timeoutMs };
114
+ const inference = (0, transport_js_1.createServiceClient)(inference_js_1.InferenceServiceDefinition, channel, defaults);
115
+ const provisioning = (0, transport_js_1.createServiceClient)(provisioning_js_1.ProvisioningServiceDefinition, channel, defaults);
116
+ const sandboxRpc = (0, transport_js_1.createServiceClient)(sandbox_js_1.SandboxServiceDefinition, channel, defaults);
117
+ const iam = (0, transport_js_1.createServiceClient)(iam_js_1.IAMServiceDefinition, channel, defaults);
118
+ this.iam = (0, rpc_types_js_1.sdkService)(iam_js_1.IAMServiceDefinition, iam);
119
+ const gateway = (0, transport_js_1.createServiceClient)(gateway_js_1.GatewayServiceDefinition, channel, defaults);
120
+ this.gateway = (0, rpc_types_js_1.sdkService)(gateway_js_1.GatewayServiceDefinition, gateway);
121
+ const access = (0, transport_js_1.createServiceClient)(access_js_1.AccessServiceDefinition, channel, defaults);
122
+ this.access = (0, rpc_types_js_1.sdkService)(access_js_1.AccessServiceDefinition, access);
123
+ const channels = (0, transport_js_1.createServiceClient)(channels_js_1.ChannelsServiceDefinition, channel, defaults);
124
+ this.channels = (0, rpc_types_js_1.sdkService)(channels_js_1.ChannelsServiceDefinition, channels);
125
+ this.grpc = Object.freeze({
126
+ channel,
127
+ inference,
128
+ provisioning,
129
+ iam,
130
+ gateway,
131
+ access,
132
+ channels,
133
+ sandboxes: sandboxRpc,
134
+ });
135
+ const inferenceSdk = (0, rpc_types_js_1.sdkService)(inference_js_1.InferenceServiceDefinition, inference);
136
+ this.inferenceApi = inferenceSdk;
137
+ this.#provisioning = (0, rpc_types_js_1.sdkService)(provisioning_js_1.ProvisioningServiceDefinition, provisioning);
138
+ this.control = this.#provisioning;
139
+ this.#sandboxes = (0, rpc_types_js_1.sdkService)(sandbox_js_1.SandboxServiceDefinition, sandboxRpc);
140
+ this.models = new inference_js_2.Models(inferenceSdk);
141
+ this.chat = new inference_js_2.Chat(inferenceSdk);
142
+ this.responses = new inference_js_2.Responses(inferenceSdk);
143
+ this.ocr = new inference_js_2.Ocr(inferenceSdk);
144
+ this.audio = new inference_js_2.Audio(inferenceSdk);
145
+ this.catalog = new inference_js_2.Catalog(this.#provisioning);
146
+ this.user = new provisioning_js_2.Users(this.#provisioning);
147
+ this.organizations = new provisioning_js_2.Organizations(this.#provisioning);
148
+ this.git = new provisioning_js_2.Git(this.#provisioning);
149
+ }
150
+ /**
151
+ * Bind resource operations to one organization without making a network request.
152
+ *
153
+ * @param id - Organization identifier, for example `user.defaultOrgId`.
154
+ * @returns A scope whose nested operations automatically include this organization ID.
155
+ * @example
156
+ * const org = client.org(orgId);
157
+ * const keys = await org.apiKeys.list();
158
+ */
159
+ org(id) {
160
+ return new provisioning_js_2.OrganizationScope(this.#provisioning, this.#sandboxes, id);
161
+ }
162
+ /**
163
+ * Close the SDK-owned connection. Safe to call more than once.
164
+ *
165
+ * A caller-provided channel remains open and must be closed by its owner. Close after active work has finished, typically on application shutdown.
166
+ */
167
+ close() {
168
+ if (this.#ownsChannel && !this.#closed) {
169
+ this.grpc.channel.close();
170
+ this.#closed = true;
171
+ }
172
+ }
173
+ }
174
+ exports.TarkaClient = TarkaClient;
@@ -0,0 +1,27 @@
1
+ import type { Metadata } from "./types.js";
2
+ /** Stable string error codes used by resource methods. Native numeric gRPC codes are exposed only by `client.grpc`. */
3
+ export type ErrorCode = "cancelled" | "unknown" | "invalid_argument" | "deadline_exceeded" | "not_found" | "already_exists" | "permission_denied" | "resource_exhausted" | "failed_precondition" | "aborted" | "out_of_range" | "unimplemented" | "internal" | "unavailable" | "data_loss" | "unauthenticated";
4
+ /**
5
+ * A resource API failure with a readable message, stable string code, and plain metadata.
6
+ *
7
+ * The underlying error is available through `cause`. Local argument validation throws TypeError; sandbox operation errors additionally expose explicit recovery.
8
+ * @example
9
+ * if (error instanceof TarkaError && error.code === "deadline_exceeded") {
10
+ * console.error("Client wait expired");
11
+ * }
12
+ */
13
+ export declare class TarkaError extends Error {
14
+ /** Stable string code, such as deadline_exceeded or permission_denied. */
15
+ readonly code: ErrorCode;
16
+ constructor(message: string,
17
+ /** Stable string code, such as deadline_exceeded or permission_denied. */
18
+ code: ErrorCode, options?: {
19
+ cause?: unknown;
20
+ metadata?: Metadata;
21
+ });
22
+ /** Trailing server metadata as a plain object, or an empty object when no trailers are available. */
23
+ readonly metadata: Metadata;
24
+ }
25
+ export declare function normalizeError(error: unknown): TarkaError;
26
+ export declare function required<T>(value: T | undefined, field: string): T;
27
+ export declare function requireText(value: unknown, name: string): asserts value is string;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TarkaError = void 0;
4
+ exports.normalizeError = normalizeError;
5
+ exports.required = required;
6
+ exports.requireText = requireText;
7
+ const grpc_js_1 = require("@grpc/grpc-js");
8
+ const codes = [
9
+ "unknown",
10
+ "cancelled",
11
+ "unknown",
12
+ "invalid_argument",
13
+ "deadline_exceeded",
14
+ "not_found",
15
+ "already_exists",
16
+ "permission_denied",
17
+ "resource_exhausted",
18
+ "failed_precondition",
19
+ "aborted",
20
+ "out_of_range",
21
+ "unimplemented",
22
+ "internal",
23
+ "unavailable",
24
+ "data_loss",
25
+ "unauthenticated",
26
+ ];
27
+ /**
28
+ * A resource API failure with a readable message, stable string code, and plain metadata.
29
+ *
30
+ * The underlying error is available through `cause`. Local argument validation throws TypeError; sandbox operation errors additionally expose explicit recovery.
31
+ * @example
32
+ * if (error instanceof TarkaError && error.code === "deadline_exceeded") {
33
+ * console.error("Client wait expired");
34
+ * }
35
+ */
36
+ class TarkaError extends Error {
37
+ code;
38
+ constructor(message,
39
+ /** Stable string code, such as deadline_exceeded or permission_denied. */
40
+ code, options = {}) {
41
+ super(message, { cause: options.cause });
42
+ this.code = code;
43
+ this.name = "TarkaError";
44
+ this.metadata = options.metadata ?? {};
45
+ }
46
+ /** Trailing server metadata as a plain object, or an empty object when no trailers are available. */
47
+ metadata;
48
+ }
49
+ exports.TarkaError = TarkaError;
50
+ function normalizeError(error) {
51
+ if (error instanceof TarkaError)
52
+ return error;
53
+ if (typeof error === "object" &&
54
+ error !== null &&
55
+ "code" in error &&
56
+ typeof error.code === "number") {
57
+ const details = "details" in error && typeof error.details === "string"
58
+ ? error.details
59
+ : "Tarka request failed";
60
+ const metadata = "metadata" in error && error.metadata instanceof grpc_js_1.Metadata
61
+ ? error.metadata.getMap()
62
+ : {};
63
+ return new TarkaError(details, codes[error.code] ?? "unknown", {
64
+ cause: error,
65
+ metadata,
66
+ });
67
+ }
68
+ return new TarkaError(error instanceof Error ? error.message : "Tarka request failed", "unknown", { cause: error });
69
+ }
70
+ function required(value, field) {
71
+ if (value === undefined)
72
+ throw new TarkaError(`The server response is missing ${field}`, "data_loss");
73
+ return value;
74
+ }
75
+ function requireText(value, name) {
76
+ if (typeof value !== "string" || !value.trim())
77
+ throw new TypeError(`${name} must not be empty`);
78
+ }
@@ -0,0 +1 @@
1
+ export declare const protobufPackage = "google.api";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
+ // versions:
4
+ // protoc-gen-ts_proto v2.12.4
5
+ // protoc v3.19.1
6
+ // source: google/api/annotations.proto
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.protobufPackage = void 0;
9
+ /* eslint-disable */
10
+ exports.protobufPackage = "google.api";